Compiles Mustache templates in HTML to javascript

Compiles Mustache templates in HTML to javascript.

Compiled templates don't use eval nor Function so they can be used from restricted environments such as Chrome extension apps.

Stable and being used in commercial development.

npm install mustachec
mustachec main.html

compiles each Mustache template within main.html like below (expressed as Jade template)

      a.cancel.close ×
      .modal-title {{title}}

    center {{message}}
    button.cancel.btn Cancel
    button.ok.btn.btn-primary {{confirm}}

into javascript and save them as main-templates.js file like below in the same directory:

window.compiledTemplates = {}
window.compiledTemplates["dialog-template"] = ...;
window.compiledTemplates["confirm-dialog-subtemplate"] = ...;
var context = { title: "foobar" };
var renderedHtml = window.compiledTemplates["dialog-template"].render(context)

Generated code currently expects Hogan.js 2.0 to be loaded.

Use -s or --selector option to override jQuery selector used to identify Mustache template elements in HTML input. Default selector is script[type='text/x-mustache-template'] like this:

mustachec -s ".template" main.html

Use -a or --assign option to specify where to store the compiled templates. Default location is window.compiledTemplates.

mustachec -a "var compiledTemplates" main.html

Use -o or --out option to specify output directory.

mustachec -o ../build main.html