Skip to content

Commit

Permalink
streamable templates FTW
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Machi committed Sep 29, 2010
1 parent 370053f commit c0cb9cb
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions lib/template.js
Expand Up @@ -19,19 +19,13 @@ var Template = exports.Template = function(source, options, noWrapper){
} }


// header for compiled template function // header for compiled template function
// TODO change this so we can be provided a write function and stream the template gen options.header = 'return { forEach: function(_write) { with($data){';
options.header = [ 'var $text = [];',
'var _write = function(text) {',
'$text.push((typeof text == "number")?text:(text||""));',
'};',
'with($data){ '
].join('');


// footer for compiled template function // footer for compiled template function
options.footer = '} return $text.join("");'; options.footer = '}}}';
var parsed;
return when(source, function(source){ return when(source, function(source){
parsed = parse(source, state, options); var parsed = parse(source, state, options);
return when(parsed, function(parsed){ return when(parsed, function(parsed){
if (!noWrapper){ if (!noWrapper){
var wrapped = [options.header,parsed, options.footer].join(''); var wrapped = [options.header,parsed, options.footer].join('');
Expand Down

0 comments on commit c0cb9cb

Please sign in to comment.