diff options
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 4 | ||||
-rw-r--r-- | spec/blocks.js | 11 | ||||
-rw-r--r-- | spec/regressions.js | 22 |
3 files changed, 34 insertions, 3 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 3e83a62..f823daa 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -222,7 +222,9 @@ Compiler.prototype = { }, content: function(content) { - this.opcode('appendContent', content.string); + if (!content.omit) { + this.opcode('appendContent', content.string); + } }, mustache: function(mustache) { diff --git a/spec/blocks.js b/spec/blocks.js index 718d316..c57a67e 100644 --- a/spec/blocks.js +++ b/spec/blocks.js @@ -83,4 +83,15 @@ describe('blocks', function() { "No people"); }); }); + + describe('standalone sections', function() { + it('block standalone else sections', function() { + shouldCompileTo('{{#people}}\n{{name}}\n{{^}}\n{{none}}\n{{/people}}\n', {none: 'No people'}, + 'No people\n'); + shouldCompileTo('{{#none}}\n{{.}}\n{{^}}\n{{none}}\n{{/none}}\n', {none: 'No people'}, + 'No people\n'); + shouldCompileTo('\n{{#people}}\n{{name}}\n{{^}}\n{{none}}\n{{/people}}\n', {none: 'No people'}, + 'No people\n'); + }); + }); }); diff --git a/spec/regressions.js b/spec/regressions.js index 6a7990c..dd4eedd 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -24,7 +24,19 @@ describe('Regressions', function() { }); it("bug reported by @fat where lambdas weren't being properly resolved", function() { - var string = "<strong>This is a slightly more complicated {{thing}}.</strong>.\n{{! Just ignore this business. }}\nCheck this out:\n{{#hasThings}}\n<ul>\n{{#things}}\n<li class={{className}}>{{word}}</li>\n{{/things}}</ul>.\n{{/hasThings}}\n{{^hasThings}}\n\n<small>Nothing to check out...</small>\n{{/hasThings}}"; + var string = '<strong>This is a slightly more complicated {{thing}}.</strong>.\n' + + '{{! Just ignore this business. }}\n' + + 'Check this out:\n' + + '{{#hasThings}}\n' + + '<ul>\n' + + '{{#things}}\n' + + '<li class={{className}}>{{word}}</li>\n' + + '{{/things}}</ul>.\n' + + '{{/hasThings}}\n' + + '{{^hasThings}}\n' + + '\n' + + '<small>Nothing to check out...</small>\n' + + '{{/hasThings}}'; var data = { thing: function() { return "blah"; @@ -39,7 +51,13 @@ describe('Regressions', function() { } }; - var output = "<strong>This is a slightly more complicated blah.</strong>.\n\nCheck this out:\n\n<ul>\n\n<li class=one>@fat</li>\n\n<li class=two>@dhg</li>\n\n<li class=three>@sayrer</li>\n</ul>.\n\n"; + var output = '<strong>This is a slightly more complicated blah.</strong>.\n' + + 'Check this out:\n' + + '<ul>\n' + + '<li class=one>@fat</li>\n' + + '<li class=two>@dhg</li>\n' + + '<li class=three>@sayrer</li>\n' + + '</ul>.\n'; shouldCompileTo(string, data, output); }); |