Hogan.js is a compiler for the
Mustache templating language. For information
on Mustache, see the manpage and
the spec.
Basics
Hogan compiles templates to HoganTemplate objects, which have a render method.
var data = { screenName: "dhg",};var template = Hogan.compile("Follow @{{screenName}}.");var output = template.render(data);// prints "Follow @dhg."console.log(output);
Features
Hogan is fast--try it on your workload.
Hogan has separate scanning, parsing and code generation phases. This way it's
possible to add new features without touching the scanner at all, and many
different code generation techniques can be tried without changing the parser.
Hogan exposes scan and parse methods. These can be useful for
pre-processing templates on the server.
var text = "{{^check}}{{#i18n}}No{{/i18n}}{{/check}}";text += "{{#check}}{{#i18n}}Yes{{/i18n}}{{/check}}";var tree = Hogan.parse(Hogan.scan(text));// outputs "# check"console.log(tree[0].tag + " " + tree[0].name);// outputs "Yes"console.log(tree[1].nodes[0].nodes[0]);
It's also possible to use HoganTemplate objects without the Hogan compiler
present. That means you can pre-compile your templates on the server, and
avoid shipping the compiler. However, the optional lambda features from the
Mustache spec require the compiler and the original template source to be present.