summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-08-12 14:07:13 -0500
committerkpdecker <kpdecker@gmail.com>2014-08-12 14:41:58 -0500
commit2a47d66ee9fdf467588f68de48a521ed2a1f59e1 (patch)
treed01f492d2106c44caa3ea440cc65562bb05fdfe5
parent50c657f138d01c90d2dee19c7c15ca81bb0ee165 (diff)
downloadhandlebars.js-2a47d66ee9fdf467588f68de48a521ed2a1f59e1.zip
handlebars.js-2a47d66ee9fdf467588f68de48a521ed2a1f59e1.tar.gz
handlebars.js-2a47d66ee9fdf467588f68de48a521ed2a1f59e1.tar.bz2
Drop omitted content tags from generated output
-rw-r--r--lib/handlebars/compiler/compiler.js4
-rw-r--r--spec/blocks.js11
-rw-r--r--spec/regressions.js22
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);
});