summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-09-01 00:48:20 -0500
committerkpdecker <kpdecker@gmail.com>2015-09-01 00:48:20 -0500
commite7a64f018ca541a7e0ac8ab2108ed86820bb47b1 (patch)
tree9680f623156fad643bae1a38ae9de425d8fbd583 /lib/handlebars/runtime.js
parent0f5061e44524a431659f0665c4cd7557af9525a0 (diff)
parent6c45f49b24d63acda37072df464bd670af97a072 (diff)
downloadhandlebars.js-e7a64f018ca541a7e0ac8ab2108ed86820bb47b1.zip
handlebars.js-e7a64f018ca541a7e0ac8ab2108ed86820bb47b1.tar.gz
handlebars.js-e7a64f018ca541a7e0ac8ab2108ed86820bb47b1.tar.bz2
Merge branch 'decorators'
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index de42752..6b31a7b 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -29,6 +29,8 @@ export function template(templateSpec, env) {
throw new Exception('Unknown template object: ' + typeof templateSpec);
}
+ templateSpec.main.decorator = templateSpec.main_d;
+
// Note: Using env.VM references rather than local var references throughout this section to allow
// for external users to override these as psuedo-supported APIs.
env.VM.checkRevision(templateSpec.compiler);
@@ -90,7 +92,9 @@ export function template(templateSpec, env) {
invokePartial: invokePartialWrapper,
fn: function(i) {
- return templateSpec[i];
+ let ret = templateSpec[i];
+ ret.decorator = templateSpec[i + '_d'];
+ return ret;
},
programs: [],
@@ -142,7 +146,11 @@ export function template(templateSpec, env) {
}
}
- return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
+ function main(context/*, options*/) {
+ return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
+ }
+ main = executeDecorators(templateSpec.main, main, container, options.depths || [], data, blockParams);
+ return main(context, options);
}
ret.isTop = true;
@@ -153,9 +161,13 @@ export function template(templateSpec, env) {
if (templateSpec.usePartial) {
container.partials = container.merge(options.partials, env.partials);
}
+ if (templateSpec.useDecorators) {
+ container.decorators = container.merge(options.decorators, env.decorators);
+ }
} else {
container.helpers = options.helpers;
container.partials = options.partials;
+ container.decorators = options.decorators;
}
};
@@ -186,6 +198,9 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
blockParams && [options.blockParams].concat(blockParams),
currentDepths);
}
+
+ prog = executeDecorators(fn, prog, container, depths, data, blockParams);
+
prog.program = i;
prog.depth = depths ? depths.length : 0;
prog.blockParams = declaredBlockParams || 0;
@@ -216,6 +231,10 @@ export function invokePartial(partial, context, options) {
let partialBlock;
if (options.fn && options.fn !== noop) {
partialBlock = options.data['partial-block'] = options.fn;
+
+ if (partialBlock.partials) {
+ options.partials = Utils.extend({}, options.partials, partialBlock.partials);
+ }
}
if (partial === undefined && partialBlock) {
@@ -238,3 +257,12 @@ function initData(context, data) {
}
return data;
}
+
+function executeDecorators(fn, prog, container, depths, data, blockParams) {
+ if (fn.decorator) {
+ let props = {};
+ prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
+ Utils.extend(prog, props);
+ }
+ return prog;
+}