summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-08-12 14:08:12 -0500
committerkpdecker <kpdecker@gmail.com>2014-08-12 14:41:58 -0500
commite93d5166723c9ea7da3cca3e6b2ba524a19e768e (patch)
treeab392798253d7279503431955e45c9a88baa88e6 /lib/handlebars/runtime.js
parent2a47d66ee9fdf467588f68de48a521ed2a1f59e1 (diff)
downloadhandlebars.js-e93d5166723c9ea7da3cca3e6b2ba524a19e768e.zip
handlebars.js-e93d5166723c9ea7da3cca3e6b2ba524a19e768e.tar.gz
handlebars.js-e93d5166723c9ea7da3cca3e6b2ba524a19e768e.tar.bz2
Render indent for standalone partials
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index b9fc77d..9b61afe 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -31,18 +31,31 @@ export function template(templateSpec, env) {
// for external users to override these as psuedo-supported APIs.
env.VM.checkRevision(templateSpec.compiler);
- var invokePartialWrapper = function(partial, name, context, hash, helpers, partials, data) {
+ var invokePartialWrapper = function(partial, indent, name, context, hash, helpers, partials, data) {
if (hash) {
context = Utils.extend({}, context, hash);
}
var result = env.VM.invokePartial.call(this, partial, name, context, helpers, partials, data);
- if (result != null) { return result; }
- if (env.compile) {
+ if (result == null && env.compile) {
var options = { helpers: helpers, partials: partials, data: data };
partials[name] = env.compile(partial, { data: data !== undefined }, env);
- return partials[name](context, options);
+ result = partials[name](context, options);
+ }
+ if (result != null) {
+ if (indent) {
+ var lines = result.split('\n');
+ for (var i = 0, l = lines.length; i < l; i++) {
+ if (!lines[i] && i + 1 === l) {
+ break;
+ }
+
+ lines[i] = indent + lines[i];
+ }
+ result = lines.join('\n');
+ }
+ return result;
} else {
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
}