Fly template - a template engine that flies
Fly templates are similar to ES6 strings. You can interpolate variables and
expressions using the ${}
syntax. Template properties are exposed on this,
and can be accessed with ${this.property}
.
It compiles the template into a function that's very quick to execute.
How to use
Constructing templates
A template is very similar to ES6 template strings. Use ${} to enclose expressions and have them interpolated on render.
var template = 'Hello ${this.place}! It is currently ${new Date().toTimeString()}.';
Compilation
Then we need to compile the template.
var render = template;
Rendering
Now we can render the template with some associated data.
;
Produces something like: Hello world!, it is currently 16:20:29 GMT+1100 (AEDT)
.
Full example
var flyTemplate = template = 'Hello ${this.place}, it is currently ${new Date().toTimeString()}.' render = ; console;
Produces something like: Hello world!, it is currently 16:20:29 GMT+1100 (AEDT)
.
Methods
.parse(template)
Parses the template and produces a JSON structure that can be passed/transmitted
around that can be converted to a function using .convert()
. Ideal to save clients from having to
parse the template.
.convert()
Converts the JSON structure exported by .parse()
into the render function.
Contributing
Fork the project, create a feature branch, and send a pull-request.