diff options
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r-- | lib/handlebars/runtime.js | 32 |
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; +} |