Implement block decorators
These allow for a given block to be wrapped in helper methods or metadata and allow for more control over the current container and method before the code is run.
This commit is contained in:
@@ -90,7 +90,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 +144,17 @@ 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);
|
||||
}
|
||||
|
||||
if (templateSpec.main_d) {
|
||||
// Note that we are ignoring the props value here as we apply things slightly differently
|
||||
// when applying decorators to the root function.
|
||||
main = templateSpec.main_d(main, {}, container, undefined, data, blockParams, depths);
|
||||
}
|
||||
|
||||
return main(context, options);
|
||||
}
|
||||
ret.isTop = true;
|
||||
|
||||
@@ -190,6 +202,13 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
|
||||
blockParams && [options.blockParams].concat(blockParams),
|
||||
currentDepths);
|
||||
}
|
||||
|
||||
if (fn.decorator) {
|
||||
let props = {};
|
||||
prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
|
||||
Utils.extend(prog, props);
|
||||
}
|
||||
|
||||
prog.program = i;
|
||||
prog.depth = depths ? depths.length : 0;
|
||||
prog.blockParams = declaredBlockParams || 0;
|
||||
|
||||
Reference in New Issue
Block a user