summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Decker <kpdecker@gmail.com>2014-07-29 09:25:45 -0500
committerKevin Decker <kpdecker@gmail.com>2014-07-29 09:25:45 -0500
commitf374939cfd12e0f50c38682643b898b9b980968d (patch)
treeccb59a52de039404571d752f80ecee27bc2dfa20
parent271106d43fae96fc1287898568d000b871f19084 (diff)
parent2bdfd2a31d029355cc1aca6349d2b318720c1e81 (diff)
downloadhandlebars.js-f374939cfd12e0f50c38682643b898b9b980968d.zip
handlebars.js-f374939cfd12e0f50c38682643b898b9b980968d.tar.gz
handlebars.js-f374939cfd12e0f50c38682643b898b9b980968d.tar.bz2
Merge pull request #823 from fractal-surfing/with-inverse
Support inverse sections on the with helper
-rw-r--r--lib/handlebars/base.js2
-rw-r--r--spec/builtins.js4
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 9b910c7..022417b 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -185,6 +185,8 @@ function registerDefaultHelpers(instance) {
}
return fn(context, options);
+ } else {
+ return options.inverse(this);
}
});
diff --git a/spec/builtins.js b/spec/builtins.js
index a28f400..77f3701 100644
--- a/spec/builtins.js
+++ b/spec/builtins.js
@@ -44,6 +44,10 @@ describe('builtin helpers', function() {
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
shouldCompileTo(string, {person: function() { return {first: "Alan", last: "Johnson"};}}, "Alan Johnson");
});
+ it("with with else", function() {
+ var string = "{{#with person}}Person is present{{else}}Person is not present{{/with}}";
+ shouldCompileTo(string, {}, "Person is not present");
+ });
});
describe('#each', function() {