From f6212f452ca54efd1cb46dc5bd7c72d9a2213e4d Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Thu, 8 Mar 2012 21:01:01 +0100 Subject: [PATCH] Bugfix --- src/node/eejs/eejs.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/node/eejs/eejs.js b/src/node/eejs/eejs.js index ed6b329bb..8faaab800 100644 --- a/src/node/eejs/eejs.js +++ b/src/node/eejs/eejs.js @@ -21,6 +21,7 @@ var ejs = require("ejs"); var fs = require("fs"); +var path = require("path"); exports.init = function (b, recursive) { if (!exports.info) { @@ -28,7 +29,7 @@ exports.init = function (b, recursive) { buf_stack: [], block_stack: [], blocks: {}, - level: 1 + filestack: [], } } exports.info.buf = b; @@ -71,13 +72,22 @@ exports.begin_block = exports.begin_define_block; exports.require = function (name, args) { if (args == undefined) args = {}; - if (exports.info) - exports.info.buf_stack.push(exports.info.buf); + if (!exports.info) + exports.init(null); + + if ((name.indexOf("./") == 0 || name.indexOf("../") == 0) && exports.info.file_stack) { + name = path.join(exports.info.file_stack[exports.info.file_stack.length-1], name); + } + var ejspath = require.resolve(name) + + exports.info.file_stack.push(ejpath); + exports.info.buf_stack.push(exports.info.buf); var res = ejs.render( - fs.readFileSync(require.resolve(name)).toString(), + fs.readFileSync(ejspath).toString(), args); - if (exports.info) - exports.info.buf = exports.info.buf_stack.pop(); + exports.info.buf = exports.info.buf_stack.pop(); + exports.info.file_stack.pop(); + if (exports.info.buf) exports.info.buf.push(res); return res;