Pass on the render args to all eejs hooks
eejs.require('foo', {..render args..}) will be passed on to all eejsBlock_X hooks as `hookContext.renderContext`
This commit is contained in:
parent
f676e90199
commit
059f6d280e
|
@ -30,6 +30,7 @@ exports.info = {
|
||||||
block_stack: [],
|
block_stack: [],
|
||||||
blocks: {},
|
blocks: {},
|
||||||
file_stack: [],
|
file_stack: [],
|
||||||
|
args: []
|
||||||
};
|
};
|
||||||
|
|
||||||
exports._init = function (b, recursive) {
|
exports._init = function (b, recursive) {
|
||||||
|
@ -81,7 +82,8 @@ exports.end_define_block = function () {
|
||||||
|
|
||||||
exports.end_block = function () {
|
exports.end_block = function () {
|
||||||
var name = exports.info.block_stack[exports.info.block_stack.length-1];
|
var name = exports.info.block_stack[exports.info.block_stack.length-1];
|
||||||
var args = {content: exports.end_define_block()};
|
var renderContext = exports.info.args[exports.info.args.length-1];
|
||||||
|
var args = {content: exports.end_define_block(), renderContext: renderContext};
|
||||||
hooks.callAll("eejsBlock_" + name, args);
|
hooks.callAll("eejsBlock_" + name, args);
|
||||||
exports.info.buf.push(args.content);
|
exports.info.buf.push(args.content);
|
||||||
}
|
}
|
||||||
|
@ -118,10 +120,13 @@ exports.require = function (name, args, mod) {
|
||||||
args.e = exports;
|
args.e = exports;
|
||||||
args.require = require;
|
args.require = require;
|
||||||
var template = '<% e._init(buf); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
|
var template = '<% e._init(buf); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>';
|
||||||
|
|
||||||
|
exports.info.args.push(args);
|
||||||
exports.info.file_stack.push({path: ejspath, inherit: []});
|
exports.info.file_stack.push({path: ejspath, inherit: []});
|
||||||
|
|
||||||
var res = ejs.render(template, args);
|
var res = ejs.render(template, args);
|
||||||
exports.info.file_stack.pop();
|
exports.info.file_stack.pop();
|
||||||
|
exports.info.args.pop();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue