diff --git a/lib/template.js b/lib/template.js index 748cd2b..34d9a3b 100644 --- a/lib/template.js +++ b/lib/template.js @@ -19,19 +19,13 @@ var Template = exports.Template = function(source, options, noWrapper){ } // header for compiled template function - // TODO change this so we can be provided a write function and stream the template gen - options.header = [ 'var $text = [];', - 'var _write = function(text) {', - '$text.push((typeof text == "number")?text:(text||""));', - '};', - 'with($data){ ' - ].join(''); + options.header = 'return { forEach: function(_write) { with($data){'; // footer for compiled template function - options.footer = '} return $text.join("");'; - var parsed; + options.footer = '}}}'; + return when(source, function(source){ - parsed = parse(source, state, options); + var parsed = parse(source, state, options); return when(parsed, function(parsed){ if (!noWrapper){ var wrapped = [options.header,parsed, options.footer].join('');