gram/packages/renderer
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab a19a2f054b
Some checks failed
CI / Build & Test (pull_request) Has been cancelled
chore: release v1.6.1
2026-12-02 14:38:23 +01:00
..
scripts feat(renderer): modernize HTML recipe view layout and intermediate traceability (#126) 2026-11-11 16:02:27 +01:00
src Merge remote-tracking branch 'origin/main' into chore/merge-main-into-dev-1.6-2026-11-30 2026-11-30 20:41:09 +01:00
tests Merge remote-tracking branch 'origin/main' into chore/merge-main-into-dev-1.6-2026-11-30 2026-11-30 20:41:09 +01:00
CHANGELOG.md chore: release v1.6.1 2026-12-02 14:38:23 +01:00
CONTRIBUTING.md feat(renderer): modernize HTML recipe view layout and intermediate traceability (#126) 2026-11-11 16:02:27 +01:00
gantt.css feat: replace the Gantt chart with the work plan (#88) 2026-11-05 09:49:00 +01:00
package.json chore: release v1.6.1 2026-12-02 14:38:23 +01:00
README.md docs: rewrite root and package READMEs for v1.6 2026-11-29 22:35:50 +01:00
tsconfig.json feat(renderer): extract HTML/Markdown rendering into a new @gram/renderer package 2026-06-08 21:42:30 +02:00

@gram-lang/renderer

npm License: GPL v3

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.