ert
Express routing templates provides a simple micro-templating syntax for building strings from a template and a request
object.
Installation
$ npm install ert
Usage
var ert = ;var express = ;var app = ; app; app;
Syntax
Code Blocks
e.g.
Code in squre brackets ([
and ]
) is evalutated as a JavaScript expression. It has req
available as an object. It also supports shortcuts, so you could write the above as:
Shortucts
There are characters that are shortucts, the defaults of these are:
exportsshortcutMap = ':': 'req.params' '$': 'req.query' '@': 'req.body';
These can be used directly like:
which is equivallent to:
API
ert(req, src) or ert.translate(req, src)
Transforms the string with req
and returns the resulting string. It caches the compiled function so should be pretty good for performance.
ert.compile(src)
Compiles src
and returns a JavaScript expression as a string. This can be used to generate client side code with something like:
{ return 'function name(req){return ' + ert + '}';}
ert.compileFn(src)
Compiles src
and returns a function which expects a single argument, request
.
License
MIT