Created
February 1, 2010 20:29
-
-
Save orlandov/291988 to your computer and use it in GitHub Desktop.
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
| --- a/lib/Template.js | |
| +++ b/lib/Template.js | |
| @@ -48,6 +48,11 @@ | |
| **/ | |
| if (!this.exports) this.exports = {}; | |
| +var uneval; | |
| +if (typeof uneval === "undefined") { | |
| + uneval = JSON.stringify | |
| +} | |
| + | |
| /** section: Module | |
| * class exports.Template | |
| * | |
| @@ -313,6 +318,34 @@ Template.prototype = { | |
| return ret.replace(/^\s*([\s\S]*?)\s*$/, '$1'); | |
| + }, | |
| + | |
| + toJSFun: function Template$prototype$toJSFun(input) { | |
| + // Reset. | |
| + this.parserOutput = []; | |
| + | |
| + var parser = new Template.Parser(this); | |
| + var ctx = new Template.Context(this); | |
| + | |
| + parser.parse(input); | |
| + this.parserTokens = [].concat(parser._tokenBuffer); | |
| + if (this.DBG_OUTPUT_TOKENS) | |
| + require('system').stderr.print('# Tokens: ' + this.parserTokens.toSource()); | |
| + var chunks = parser.chunks(); | |
| + | |
| + this.parserOutput = [].concat(chunks); | |
| + | |
| + if (this.DBG_OUTPUT_CHUNKS) | |
| + require('system').stderr.print('# Chunks: ' + chunks.toSource()); | |
| + | |
| + var ti = new Template.Interpreter(chunks, this); | |
| + | |
| + this.interpreterOutput = ti.output; | |
| + | |
| + if (this.DBG_OUTPUT_FUNC) | |
| + require('system').stderr.print(ti.output); | |
| + | |
| + return ti.output; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment