Handle empty responses from partials

Fixes #675
This commit is contained in:
kpdecker
2013-12-23 15:33:33 -06:00
parent 23d41e5617
commit 93fb25c702
2 changed files with 8 additions and 2 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ export function template(templateSpec, env) {
// TODO : Check this for all inputs and the options handling (partial flag, etc). This feels
// like there should be a common exec path
var result = invokePartial.apply(this, arguments);
if (result) { return result; }
if (result != null) { return result; }
var options = { helpers: helpers, partials: partials, data: data };
partials[name] = env.compile(partial, { data: data !== undefined }, env);
@@ -42,7 +42,7 @@ export function template(templateSpec, env) {
} else {
invokePartialWrapper = function(partial, name /* , context, helpers, partials, data */) {
var result = invokePartial.apply(this, arguments);
if (result) { return result; }
if (result != null) { return result; }
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
};
}
+6
View File
@@ -123,4 +123,10 @@ describe('partials', function() {
var hash = {name:"Jeepers", another_dude:"Creepers"};
shouldCompileToWithPartials(string, [hash, {}, {'+404/asdf?.bar':dude}], true, "Dudes: Jeepers", "Partials can use literal paths");
});
it('should handle empty partial', function() {
var string = "Dudes: {{#dudes}}{{> dude}}{{/dudes}}";
var partial = "";
var hash = {dudes: [{name: "Yehuda", url: "http://yehuda"}, {name: "Alan", url: "http://alan"}]};
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}], true, "Dudes: "); });
});