5 KiB
Contributing to the renderer
The renderer turns a compiled recipe into views. The engine computes, the views only show: a view reads what prepareViews() worked out (the schedule, the run sheet, the serving times) and never computes a schedule of its own.
How it is laid out
src/prepare-views.ts: the one entry point. It takes the recipe, the view settings and the serving context, and works out the costly parts once, only when a view reads them.src/contract.ts: what a view (ViewDefinition) and an inspector (InspectorDefinition) are, and the formats (FORMATS, withFORMAT_DEFINITIONSsaying how a screen shows each one).src/views/<id>/: one folder per view (its id in kebab case:runSheetlives inrun-sheet/), with its formats, itsview.ts, its screen stylesheetscreen.cssand its print stylesheetprint.css.src/views/registry.tslists them inviews.src/inspectors/: the looks at the pipeline (AST, JSON, JSON tree), listed ininspectors.src/shared/: what several views use (formatting of a step, nutrition, icons, the base print stylesheet, and on screen only the tokens, the frame and the floating tooltip).src/settings.ts: the descriptors of the view and recipe settings, the one source of truth every surface reads.
A view never imports another view. What two views share goes in shared/. tests/views-imports.test.ts checks it.
Adding a view
- Create
src/views/<id>/. It imports only its own files,shared/, the contract, the settings, the types,prepareViewsand the pipeline packages. - Write its
view.ts, aViewDefinition: itsformats(only those it can really express, and alwayshtml: the editor's panel and the playground show a view in html;gram exportwritesmarkdown,printandtext, andgram printneedsprint, so a view withhtmlalone is on screen only), the settings ithonors, what itneedsfrom the input (schedule,runSheet,serveTimes), andrender(). Returnnullwhen the recipe has nothing for it. - Write its
screen.css, the stylesheet of itshtmlformat: every rule inside one@scope (.gram-<folder>), and its html written in a root element of that class (<section class="gram-run-sheet">). It reuses no class of another view's stylesheet, only the tokens ofshared/tokens.css. The build adds it togram.cssfrom the registry;tests/views-styles.test.tschecks the scope and the root. - Add it to
viewsinsrc/views/registry.ts, and tooutputsinsrc/outputs.ts(written out, not spread, so a bundler can drop the views a page does not use). Give it a name in every language, underrenderer.outputsof@gram-lang/i18n: the surfaces list the outputs by that name. - Run
tests/views-contract.test.ts. It renders the view in each format for every fixture, checks the escaping, and checks that the view reacts to each setting it honors and to no other. If it honors a setting none of the fixtures shows, extend a fixture. - If the view brings a new setting: add its descriptor to
VIEW_SETTINGSinsrc/settings.ts, a probe toPROBESin the contract test, agram.*key in the VS Code extension'spackage.json(the parity test fails until it exists), and the docs in English and French. - If the view brings a new format: add it to
FormatandFORMATS, describe it inFORMAT_DEFINITIONS(page,codewith its highlighting language, ornone; the build fails until you do), and name it underrenderer.formatsof@gram-lang/i18nin every language. The playground and the editor read how to show it from there. - Document the view in English and French (what it shows, its formats, the settings it follows), and add a changeset: a new view is a new feature of every surface.
Nothing else should need an edit, not even a test of a surface: the surfaces list their outputs from the registry, so a new view appears in the CLI, VS Code and the playground. Removing a view is the reverse.
Every surface lists its outputs from the registry: the language server and the VS Code extension, the playground (as tabs, with the formats of each view), and the CLI (--view of gram export and gram print, each --format checked against the view's formats). The terminal views of gram view and gram cook are not renderer strings and stay apart.
Checks
bun run --cwd packages/renderer build
bun run --cwd packages/renderer test
The print styles live in real stylesheets (src/shared/print.css, then each view's print.css), bundled as text: edit those, not the .ts wrappers.
The screen styles are each view's screen.css, after the shared src/shared/tokens.css, base.css and tooltip.css. The build (scripts/build-css.mjs) joins them in the registry's order into dist/gram.css, the file the package ships as @gram-lang/renderer/gram.css and the VS Code extension copies: never edit the generated file. They stay out of the JavaScript bundle, since every surface loads them as a file. .gram-preview is the class a surface puts around a view, any view: it carries the type, never the style of a view.