Skip to content

Instantly share code, notes, and snippets.

@orlandov
Created February 1, 2010 20:29
Show Gist options
  • Select an option

  • Save orlandov/291988 to your computer and use it in GitHub Desktop.

Select an option

Save orlandov/291988 to your computer and use it in GitHub Desktop.
--- 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