Skip to content

Commit 419248b

Browse files
committed
fixed problem with trailing text not being added to template
1 parent 656acd2 commit 419248b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

view/ejs/ejs.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,19 @@ steal('can/view', 'can/util/string','can/observe/compute').then(function( $ ) {
413413

414414
source = source.replace(newLine, "\n");
415415
source.replace(tokenReg, function(whole, part, offset){
416+
// if the next token starts after the last token ends
417+
// push what's in between
416418
if(offset > last){
417419
tokens.push( source.substring(last, offset) );
418-
}
419-
tokens.push(part)
420+
}
421+
// push the token
422+
tokens.push(part);
423+
// update the position of the last part of the last token
420424
last = offset+part.length;
421425
})
422-
if(last === 0){
423-
tokens.push(source)
426+
// if there's something at the end, add it
427+
if(last < source.length){
428+
tokens.push(source.substr(last))
424429
}
425430

426431
var content = '',

view/ejs/ejs_test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ test("nested live bindings", function(){
816816
817817
})*/
818818

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

821826
})()

0 commit comments

Comments
 (0)