| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .. | ||
| scripts | ||
| src | ||
| tests | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| gantt.css | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
@gram-lang/renderer
Part of the Gram monorepo · Documentation
The display layer for the Gram recipe DSL. Turns a compiled or analyzed recipe into views (the recipe and its run sheet) in semantic HTML, Markdown, plain text, and print layout, including compound quantities, unit ratios, temperature notes, and target states (={...}). Views share a single registry of settings (VIEW_SETTINGS, RECIPE_SETTINGS) read by the CLI, editor, and playground. The engine computes; the views only show.
Installation
npm install @gram-lang/renderer
# or
bun add @gram-lang/renderer
Usage
import { getAST } from '@gram-lang/parser';
import { compile } from '@gram-lang/kitchen';
import { analyze } from '@gram-lang/analyzer';
import {
toHTML,
toMarkdown,
toText,
toPrintHTML,
prepareViews,
render,
views
} from '@gram-lang/renderer';
const { result: recipe } = analyze(compile(getAST(source)), ingredientDatabase);
// 1. The recipe in each of its formats
const html = toHTML(recipe, { lang: 'en' }); // semantic HTML, styled by gram.css
const markdown = toMarkdown(recipe);
const text = toText(recipe, { lang: 'en' }); // plain text, for a terminal or file
const printHtml = toPrintHTML(recipe); // self-contained print layout
// 2. Customized HTML (inversion of control)
const custom = toHTML(recipe, {
icons: { clock: '<span class="icon-clock">🕒</span>' },
classes: { recipeTitle: 'custom-title' }
});
// 3. Views: one pipeline entry point, computed once on demand
const input = prepareViews(
recipe,
{ miseEnPlace: 'perSection', rests: 'shortest', comments: 'show' },
{
lang: 'en',
serveAt: '2026-10-17T20:00',
kitchen: { timeZone: 'Europe/Paris', availability: { daily: [{ start: '08:00', end: '22:00' }] } }
}
);
for (const view of views) {
console.log(view.id, view.formats); // 'recipe' [...], 'runSheet' [...]
}
const runSheetHtml = render('runSheet', input, 'html');
const runSheetText = render('runSheet', input, 'text');
Settings are described once in VIEW_SETTINGS and RECIPE_SETTINGS and parsed with parseViewSettings() and parseRecipeSettings(). inspectors and outputs expose pipeline inspectors (composed AST, compiled JSON, JSON tree) alongside the views.
See CONTRIBUTING.md to add a view or a setting.
Structure
src/index.ts: public API entry point.src/prepare-views.ts:prepareViews(), computing the timeline, run sheet, and serving-time search once on demand.src/contract.ts:ViewDefinition, inspector contracts, and formats.src/views/registry.ts,src/outputs.ts: view registry (views,render()) and full output list (views and inspectors).src/views/recipe/: recipe view (HTML, Markdown, plain text, print,screen.css,print.css).src/views/run-sheet/: run sheet view (runSheetTo*,describeRunSheet).src/inspectors/: AST S-expression and interactive JSON tree (renderSExpr,renderJsonTree).src/settings.ts: view and recipe setting descriptors shared across surfaces.src/shared/: shared formatting, nutrition, icons, tooltips,tokens.css,base.css, and base print styles.src/describe-error.ts:describeError(), shared error summaries.src/types.ts: TypeScript interfaces (RendererOptions,RendererIcons,RendererClasses).src/gantt/: deprecated Gantt chart (removed in 2.0.0); use the run sheet instead.gram.css(@gram-lang/renderer/gram.css): combined screen stylesheet, each view scoped via CSS@scope.gantt.css: stylesheet of the deprecated Gantt chart.
License
Licensed under the GPL-3.0 license.