From 059f6d280e970c0f8959738732ca8aa0e25335af Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 1 Nov 2012 13:44:06 +0100 Subject: [PATCH 1/2] 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` --- src/node/eejs/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/node/eejs/index.js b/src/node/eejs/index.js index 2d02a45a6..7b43de634 100644 --- a/src/node/eejs/index.js +++ b/src/node/eejs/index.js @@ -30,6 +30,7 @@ exports.info = { block_stack: [], blocks: {}, file_stack: [], + args: [] }; exports._init = function (b, recursive) { @@ -81,7 +82,8 @@ exports.end_define_block = function () { exports.end_block = function () { 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); exports.info.buf.push(args.content); } @@ -118,10 +120,13 @@ exports.require = function (name, args, mod) { args.e = exports; args.require = require; var template = '<% e._init(buf); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>'; - + + exports.info.args.push(args); exports.info.file_stack.push({path: ejspath, inherit: []}); + var res = ejs.render(template, args); exports.info.file_stack.pop(); + exports.info.args.pop(); return res; } From ed2faa68c964a4aadc222d6d3225506ee20f25ab Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 1 Nov 2012 13:44:59 +0100 Subject: [PATCH 2/2] Pass on the req object to eejs hooks --- src/node/hooks/express/specialpages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js index 474f475ec..a5834492e 100644 --- a/src/node/hooks/express/specialpages.js +++ b/src/node/hooks/express/specialpages.js @@ -34,13 +34,13 @@ exports.expressCreateServer = function (hook_name, args, cb) { //serve pad.html under /p args.app.get('/p/:pad', function(req, res, next) { - res.send(eejs.require("ep_etherpad-lite/templates/pad.html")); + res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req})); }); //serve timeslider.html under /p/$padname/timeslider args.app.get('/p/:pad/timeslider', function(req, res, next) { - res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html")); + res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html", {req: req})); }); } \ No newline at end of file