Created
November 4, 2011 11:17
-
-
Save changtimwu/1339126 to your computer and use it in GitHub Desktop.
use jade lib to generate a template render function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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