summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-07-30 11:06:54 -0500
committerkpdecker <kpdecker@gmail.com>2013-10-14 22:50:50 -0500
commit6b0b3fa2ca4e8d274a71f8b8337e628e3466a7c5 (patch)
tree6b89726c3cbd9edeb6fe47153f0af8292629d8ba /lib/handlebars/compiler/javascript-compiler.js
parent1de6cee1b247f5dd133e1ff3141b893fb427ff94 (diff)
downloadhandlebars.js-6b0b3fa2ca4e8d274a71f8b8337e628e3466a7c5.zip
handlebars.js-6b0b3fa2ca4e8d274a71f8b8337e628e3466a7c5.tar.gz
handlebars.js-6b0b3fa2ca4e8d274a71f8b8337e628e3466a7c5.tar.bz2
Defer content output
Allows for stripping of the content after the fact.
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index d90f0b1..f0bd58b 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -77,6 +77,9 @@ JavaScriptCompiler.prototype = {
}
}
+ // Flush any trailing content that might be pending.
+ this.pushSource('');
+
return this.createFunctionContext(asObject);
},
@@ -233,7 +236,14 @@ JavaScriptCompiler.prototype = {
//
// Appends the string value of `content` to the current buffer
appendContent: function(content) {
- this.pushSource(this.appendToBuffer(this.quotedString(content)));
+ if (this.pendingContent) {
+ content = this.pendingContent + content;
+ }
+ if (this.stripNext) {
+ content = content.replace(/^\s+/, '');
+ }
+
+ this.pendingContent = content;
},
// [append]
@@ -612,7 +622,14 @@ JavaScriptCompiler.prototype = {
},
pushSource: function(source) {
- this.source.push(source);
+ if (this.pendingContent) {
+ this.source.push(this.appendToBuffer(this.quotedString(this.pendingContent)));
+ this.pendingContent = undefined;
+ }
+
+ if (source) {
+ this.source.push(source);
+ }
},
pushStack: function(item) {