Skip to content

Commit

Permalink
Merge pull request #379 from bitovi/issue-379
Browse files Browse the repository at this point in the history
Fixed . not being passed as an object when used as a Mustache helper argument
  • Loading branch information
andykant committed May 27, 2013
2 parents 0219813 + 9f5ebb9 commit 0ce4eca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion view/mustache/mustache.js
Expand Up @@ -528,7 +528,7 @@ function( can ){
i && result.push(',');

// Check for special helper arguments (string/number/boolean/hashes).
if (i && (m = arg.match(/^(('.*?'|".*?"|[0-9.]+|true|false)|((.+?)=(('.*?'|".*?"|[0-9.]+|true|false)|(.+))))$/))) {
if (i && (m = arg.match(/^(('.*?'|".*?"|[0-9]+\.?[0-9]*|true|false)|((.+?)=(('.*?'|".*?"|[0-9]+\.?[0-9]*|true|false)|(.+))))$/))) {
// Found a native type like string/number/boolean.
if (m[2]) {
result.push(m[0]);
Expand Down
21 changes: 21 additions & 0 deletions view/mustache/mustache_test.js
Expand Up @@ -1892,4 +1892,25 @@ test("Computes should be resolved prior to accessing attributes", function() {
equal( div.innerHTML, "0" );
})

test("Helpers can be passed . or this for the active context", function() {
can.Mustache.registerHelper('rsvp', function(attendee, event) {
return attendee.name + ' is attending ' + event.name;
});
var template = can.view.mustache("{{#attendee}}{{#events}}<div>{{rsvp attendee .}}</div>{{/events}}{{/#attendee}}"),
data = {
attendee: { name: 'Justin' },
events: [
{ name: 'Reception' },
{ name: 'Wedding' }
]
};

var div = document.createElement('div');
div.appendChild(template(data));
var children = div.getElementsByTagName('div');

equal( children[0].innerHTML, 'Justin is attending Reception' );
equal( children[1].innerHTML, 'Justin is attending Wedding' );
})

})();

0 comments on commit 0ce4eca

Please sign in to comment.