Permalink
Browse files

streamable templates FTW

  • Loading branch information...
1 parent 370053f commit c0cb9cb8351fe0bb508ce5d0f791c67a9b350bd5 @dmachi committed Sep 29, 2010
Showing with 4 additions and 10 deletions.
  1. +4 −10 lib/template.js
View
@@ -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('');

0 comments on commit c0cb9cb

Please sign in to comment.