Switched empty block handling for expression blocks to use helperMissing.not.

This commit is contained in:
Alan Johnson
2010-09-25 16:42:59 -04:00
parent c1bcd72eb1
commit 88d0ea90fc
2 changed files with 20 additions and 5 deletions
+15 -5
View File
@@ -178,14 +178,21 @@ var Handlebars = {
var out = "";
if (Handlebars.isFunction(lookup)) {
out = out + lookup.call(context, arg, fn);
if (notFn != null && Handlebars.isFunction(lookup.not)) {
out = out + lookup.not.call(context, arg, notFn);
}
}
else if (typeof lookup != 'undefined') {
out = out + Handlebars.helperMissing.call(arg, lookup, fn);
else {
if (!Handlebars.isEmpty(lookup)) {
out = out + Handlebars.helperMissing.call(arg, lookup, fn);
}
if (notFn != null) {
out = out + Handlebars.helperMissing.not.call(arg, lookup, notFn);
}
}
if (notFn != null && Handlebars.isFunction(lookup.not)) {
out = out + lookup.not.call(context, arg, notFn);
}
return out;
},
@@ -256,6 +263,9 @@ Handlebars.helperMissing = function(object, fn) {
return fn(object);
}
};
Handlebars.helperMissing.not = function(context, fn) {
return fn(context);
}
Handlebars.Compiler.prototype = {
getChar: function(n) {
+5
View File
@@ -267,6 +267,11 @@ test("nested block helpers", function() {
});
test("block inverted sections", function() {
shouldCompileTo("{{#people}}{{name}}{{^}}{{../none}}{{/people}}", {none: "No people"},
"No people");
});
test("block helper inverted sections", function() {
var string = "{{#list people}}{{name}}{{^}}<em>Nobody's here</em>{{/list}}"
var list = function(context, fn) {
if (context.length > 0) {