diff options
author | Egil Moeller <egil.moller@freecode.no> | 2012-03-13 17:42:15 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2012-03-13 17:42:15 +0100 |
commit | 3ffed708508fde8ab7597b4f66211258262d196f (patch) | |
tree | aa705f4044cc143e746310055aa96256acd7a51d /src/node | |
parent | 6fb0e00f036fa7d5bf7c56abe0b572d868ed91a3 (diff) | |
download | etherpad-lite-3ffed708508fde8ab7597b4f66211258262d196f.zip |
Added inherit function
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/eejs/eejs.js | 24 | ||||
-rw-r--r-- | src/node/eejs/examples/foo.ejs | 6 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/node/eejs/eejs.js b/src/node/eejs/eejs.js index 7401b0c4..9291a341 100644 --- a/src/node/eejs/eejs.js +++ b/src/node/eejs/eejs.js @@ -30,10 +30,18 @@ exports.info = { file_stack: [], }; -exports.init = function (b, recursive) { +exports._init = function (b, recursive) { + exports.info.buf_stack.push(exports.info.buf); exports.info.buf = b; } +exports._exit = function (b, recursive) { + exports.info.file_stack[exports.info.file_stack.length-1].inherit.forEach(function (item) { + exports.require(item.name, item.args); + }); + exports.info.buf = exports.info.buf_stack.pop(); +} + exports.begin_capture = function() { exports.info.buf_stack.push(exports.info.buf.concat()); exports.info.buf.splice(0, exports.info.buf.length); @@ -69,23 +77,25 @@ exports.end_block = function () { exports.begin_block = exports.begin_define_block; +exports.inherit = function (name, args) { + exports.info.file_stack[exports.info.file_stack.length-1].inherit.push({name:name, args:args}); +} + exports.require = function (name, args) { if (args == undefined) args = {}; if (!exports.info) exports.init(null); if ((name.indexOf("./") == 0 || name.indexOf("../") == 0) && exports.info.file_stack.length) { - name = path.join(path.dirname(exports.info.file_stack[exports.info.file_stack.length-1]), name); + name = path.join(path.dirname(exports.info.file_stack[exports.info.file_stack.length-1].path), name); } var ejspath = require.resolve(name) args.e = exports; - var template = '<% e.init(buf); %>' + fs.readFileSync(ejspath).toString(); + var template = '<% e._init(buf); %>' + fs.readFileSync(ejspath).toString() + '<% e._exit(); %>'; - exports.info.file_stack.push(ejspath); - exports.info.buf_stack.push(exports.info.buf); - var res = ejs.render(template, args); - exports.info.buf = exports.info.buf_stack.pop(); + exports.info.file_stack.push({path: ejspath, inherit: []}); + var res = ejs.render(template, args); exports.info.file_stack.pop(); if (exports.info.buf) diff --git a/src/node/eejs/examples/foo.ejs b/src/node/eejs/examples/foo.ejs index 268882cb..3778b59a 100644 --- a/src/node/eejs/examples/foo.ejs +++ b/src/node/eejs/examples/foo.ejs @@ -1,5 +1,5 @@ +<% e.inherit("./bar.ejs"); %> + <% e.begin_define_block("foo"); %> -YY + YY <% e.end_define_block(); %> - -<% e.require("./bar.ejs"); %> |