#jet-engine
More complete documentation to follow.
jet-engine is a template engine with syntax very similar to dustjs-linked in. It was written because we were trying to produce the smallest bundle possible for a recent project. I liked dustjs syntax, compared to other template engines, and thought this would be a fun side project. I'm very pleased with the result. Each function is written in a separate source file, and it is easy to add additional features. In the few cases in which I wanted templates to behave differently than dustjs, I implemented my preferred approach. We also had no requirement for asynchronous template handing, so I left that out.
Usage
If you know dustjs template syntax, you know jet-engine syntax. Here are some some examples.
import { render } from 'jet-engine';
const out = render('Hello, {name}!', { name: 'World' }); // Hello, World!
Nearly all of the familiar keywords are implemented:
{value}
{#section}
{?test}
{!test} // my preferred negation test
{* comment *} // my preferred comment
{@eq ...} // and many other helpers
{>subroutine} // I prefer this terminology
{<definition} // ditto
{+block}
{~gt} // and several other other special characters
Subroutines
Register a subroutine like this
import { render, register } from 'jet-engine';
register('greet', 'Hello, {name}!')
const out = render('{>greet}', { name: 'Jim' });
const out = render('{>greet name='Jim'}'); // or provide data as an attribute
Context
The data context is exactly as you would expect form a sophisticated engine.
An initial context is set when the render() function is first invoked. Addition conexts are pushed and popped from context stack by the following commands:
{#names} // value of "names" is pushed onto the context stack
{>subroutine name="Jim"} // { name: "Jim" } is pushed onto the context stack
{@eq key="size" value=17} // { key: "size", value: 17 } is pushed onto the stack (explained in Helpers section below)
Data references are resolved from the top of the context stack downward, with the following exceptions:
{.} refers to the entire context currently on the top of the stack
{.value} references "value" only if it exists on the top of the stack. Searching will not continue downwards in the stack.
If a reference cannot be found on the context stack, an empty string ''
is returned.
provide examples
Document each keyword funciton