Turn mustache templates into JSX output functions.
npm testRuns all tests in
test/*/input.mustache. Output filetest/*/output.jsxis generated in directories that don't have it.
npm run test:updateUpdates every
*.jsxtest output file.
npm run serveRuns a watch build and dev server with REPL on
localhost:5000.
npm run distBuilds into
dist/
Other than JSX pragmas (createElement, Fragment), runnable templates expect a set of helper functions in scope:
view(key: string | null, ...scope: Object[]): anyResolves a value from the view like mustache would:
keymay be null if referencing the full scope (like{{.}})...scopeis a sequence of object scopes, in order of lookup priority. The root object is used as fallback whenkeyis not found in the scope (if there's no scope, it will use the root object).
section(
value: any,
callback: (item: any, index: number) => Renderable
): Renderable[]A section, like {{#section}}. Returns a list of Renderables.
- If
valueis an array,callback()loops over it. - If
valueis a single value, the callback is applied on it. - If
valueis falsy, or an empty array, the callback is not applied.
inverted(value: any): booleanInversion of value: true if falsy or an empty array, like inverted mustache sections as {{^falsy}}:
inverted([]) && "the list is empty";html(str: string | null): RenderableTakes an unescaped value (like {{& myHtml}}) and renders it onto the DOM.