Switched empty block handling for expression blocks to use helperMissing.not.
This commit is contained in:
+15
-5
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user