Merge branch 'pr/866' into devel

This commit is contained in:
David Glasser
2013-03-22 15:09:46 -07:00
3 changed files with 19 additions and 1 deletions

View File

@@ -28,7 +28,10 @@ Handlebars.json_ast_to_func = function (ast) {
// what is passed in via named arguments.
Handlebars._default_helpers = {
'with': function (data, options) {
return options.fn(data);
if (!data || (data instanceof Array && !data.length))
return options.inverse(this);
else
return options.fn(data);
},
'each': function (data, options) {
var parentData = this;

View File

@@ -355,3 +355,11 @@
<template name="test_template_issue801">
{{#each values}}{{this}}{{/each}}
</template>
<!-- Test for issue #770 - falsy value for with -->
<template name="test_template_issue770">
{{# with value1}}{{this}}{{else}}xxx{{/with}}
{{# with value2}}{{this}}{{else}}xxx{{/with}}
{{# with value1}}{{this}}{{/with}}
{{# with value2}}{{this}}{{/with}}
</template>

View File

@@ -1092,3 +1092,10 @@ Tinytest.add('templating - each falsy Issue #801', function (test) {
var frag = Meteor.render(Template.test_template_issue801);
test.equal(canonicalizeHtml(DomUtils.fragmentToHtml(frag)), "12null");
});
Tinytest.add('templating - with falsy Issue #770', function (test) {
Template.test_template_issue770.value1 = function () { return "abc"; };
Template.test_template_issue770.value2 = function () { return false; };
var frag = Meteor.render(Template.test_template_issue770);
test.equal(canonicalizeHtml(DomUtils.fragmentToHtml(frag)), "abcxxxabc");
});