mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
Added inherit function
This commit is contained in:
parent
6fb0e00f03
commit
3ffed70850
2 changed files with 21 additions and 11 deletions
|
@ -30,10 +30,18 @@ exports.info = {
|
||||||
file_stack: [],
|
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.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.begin_capture = function() {
|
||||||
exports.info.buf_stack.push(exports.info.buf.concat());
|
exports.info.buf_stack.push(exports.info.buf.concat());
|
||||||
exports.info.buf.splice(0, exports.info.buf.length);
|
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.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) {
|
exports.require = function (name, args) {
|
||||||
if (args == undefined) args = {};
|
if (args == undefined) args = {};
|
||||||
if (!exports.info)
|
if (!exports.info)
|
||||||
exports.init(null);
|
exports.init(null);
|
||||||
|
|
||||||
if ((name.indexOf("./") == 0 || name.indexOf("../") == 0) && exports.info.file_stack.length) {
|
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)
|
var ejspath = require.resolve(name)
|
||||||
|
|
||||||
args.e = exports;
|
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.file_stack.push({path: ejspath, inherit: []});
|
||||||
exports.info.buf_stack.push(exports.info.buf);
|
|
||||||
var res = ejs.render(template, args);
|
var res = ejs.render(template, args);
|
||||||
exports.info.buf = exports.info.buf_stack.pop();
|
|
||||||
exports.info.file_stack.pop();
|
exports.info.file_stack.pop();
|
||||||
|
|
||||||
if (exports.info.buf)
|
if (exports.info.buf)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<% e.begin_define_block("foo"); %>
|
<% e.inherit("./bar.ejs"); %>
|
||||||
YY
|
|
||||||
<% e.end_define_block(); %>
|
|
||||||
|
|
||||||
<% e.require("./bar.ejs"); %>
|
<% e.begin_define_block("foo"); %>
|
||||||
|
YY
|
||||||
|
<% e.end_define_block(); %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue