Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created November 4, 2011 11:17
Show Gist options
  • Select an option

  • Save changtimwu/1339126 to your computer and use it in GitHub Desktop.

Select an option

Save changtimwu/1339126 to your computer and use it in GitHub Desktop.
use jade lib to generate a template render function
#!/usr/bin/node
var jade = require('jade');
var fs = require('fs');
var path = require('path');
var compile = function (str) {
options ={ client: true, compileDebug: false};
var fn = jade.compile(str, options);
return fn.toString();
}
function icompile( jadestr, mfn) {
preline = ["(function() {",
" this.JST || (this.JST = {});",
" this.JST['"+ mfn +"'] = "
].join("\n");
endline = "}).call();"
return preline + compile( jadestr) + endline;
}
filefn = process.argv[2];
jadestr = fs.readFileSync( filefn, 'utf-8');
rjs = compile( jadestr);//, process.argv[3]);
console.log(rjs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment