public
Last active

Using Rhino to compile Mustache templates with Hogan

  • Download Gist
compile.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13
// load 'hogan' library
load('js/lib/hogan/web/builds/2.0.0/hogan-2.0.0.js');
 
// initialize templates object
print('var templates = {');
 
// read mustache template content from file path
template = readFile('templates/index.mustache');
// print compiled function from Hogan
print('"index" : new Hogan.Template(' + Hogan.compile(template, {asString : true}) + ')');
 
// close object
print('};');

To run :

java -jar rhino.jar compile.js templates.js

'compile.js' refers to this gist.
'templates.js' is the file to output to.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.