Skip to content

Commit

Permalink
fixed problem with trailing text not being added to template
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Jun 19, 2012
1 parent 656acd2 commit 419248b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions view/ejs/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,19 @@ steal('can/view', 'can/util/string','can/observe/compute').then(function( $ ) {

source = source.replace(newLine, "\n");
source.replace(tokenReg, function(whole, part, offset){
// if the next token starts after the last token ends
// push what's in between
if(offset > last){
tokens.push( source.substring(last, offset) );
}
tokens.push(part)
}
// push the token
tokens.push(part);
// update the position of the last part of the last token
last = offset+part.length;
})
if(last === 0){
tokens.push(source)
// if there's something at the end, add it
if(last < source.length){
tokens.push(source.substr(last))
}

var content = '',
Expand Down
7 changes: 6 additions & 1 deletion view/ejs/ejs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,11 @@ test("nested live bindings", function(){
})*/


test("trailing text", function(){
can.view.ejs("count","There are <%= this.attr('length') %> todos")
var div = document.createElement('div');
div.appendChild( can.view("count", new can.Observe.List([{},{}])) );
ok(/There are 2 todos/.test(div.innerHTML), "got all text")
})

})()

0 comments on commit 419248b

Please sign in to comment.