Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement false for blocks like mustache(.js) and handlebars.java #822

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function registerDefaultHelpers(instance) {

if(context === true) {
return fn(this);
} else if(context === false || context == null) {
} else if(!context) {
return inverse(this);
} else if (isArray(context)) {
if(context.length > 0) {
Expand Down
18 changes: 18 additions & 0 deletions spec/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ describe('blocks', function() {
shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is false.");
});

it("inverted section with empty string", function() {
var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}";
var hash = {goodbyes: ""};
shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is empty string.");
});

it("inverted section with value NaN", function() {
var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}";
var hash = {goodbyes: NaN};
shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is NaN.");
});

it("inverted section with value 0", function() {
var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}";
var hash = {goodbyes: 0};
shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is 0.");
});

it("inverted section with empty set", function() {
var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}";
var hash = {goodbyes: []};
Expand Down
4 changes: 0 additions & 4 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ describe('Regressions', function() {
}, Error, 'You must pass a string or Handlebars AST to Handlebars.precompile. You passed null');
});

it('GH-731: zero context rendering', function() {
shouldCompileTo('{{#foo}} This is {{bar}} ~ {{/foo}}', {foo: 0, bar: 'OK'}, ' This is ~ ');
});

if (Handlebars.AST) {
it("can pass through an already-compiled AST via compile/precompile", function() {
equal(Handlebars.compile(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")]))(), 'Hello');
Expand Down