Merge pull request #1268 from ether/fix/eejs-block-caching
Fix #1247, #1201: Don't cache eejs blocks!
This commit is contained in:
commit
98e03c1d87
1 changed files with 13 additions and 18 deletions
|
@ -28,18 +28,25 @@ var resolve = require("resolve");
|
||||||
exports.info = {
|
exports.info = {
|
||||||
buf_stack: [],
|
buf_stack: [],
|
||||||
block_stack: [],
|
block_stack: [],
|
||||||
blocks: {},
|
|
||||||
file_stack: [],
|
file_stack: [],
|
||||||
args: []
|
args: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getCurrentFile() {
|
||||||
|
return exports.info.file_stack[exports.info.file_stack.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBlockId(name) {
|
||||||
|
return getCurrentFile().path + '|' + name;
|
||||||
|
}
|
||||||
|
|
||||||
exports._init = function (b, recursive) {
|
exports._init = function (b, recursive) {
|
||||||
exports.info.buf_stack.push(exports.info.buf);
|
exports.info.buf_stack.push(exports.info.buf);
|
||||||
exports.info.buf = b;
|
exports.info.buf = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports._exit = function (b, recursive) {
|
exports._exit = function (b, recursive) {
|
||||||
exports.info.file_stack[exports.info.file_stack.length-1].inherit.forEach(function (item) {
|
getCurrentFile().inherit.forEach(function (item) {
|
||||||
exports._require(item.name, item.args);
|
exports._require(item.name, item.args);
|
||||||
});
|
});
|
||||||
exports.info.buf = exports.info.buf_stack.pop();
|
exports.info.buf = exports.info.buf_stack.pop();
|
||||||
|
@ -59,29 +66,17 @@ exports.end_capture = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.begin_define_block = function (name) {
|
exports.begin_define_block = function (name) {
|
||||||
if (typeof exports.info.blocks[name] == "undefined")
|
|
||||||
exports.info.blocks[name] = {};
|
|
||||||
exports.info.block_stack.push(name);
|
exports.info.block_stack.push(name);
|
||||||
exports.begin_capture();
|
exports.begin_capture();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.super = function () {
|
|
||||||
exports.info.buf.push('<!eejs!super!>');
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.end_define_block = function () {
|
exports.end_define_block = function () {
|
||||||
content = exports.end_capture();
|
content = exports.end_capture();
|
||||||
var name = exports.info.block_stack.pop();
|
return content;
|
||||||
if (typeof exports.info.blocks[name].content == "undefined")
|
|
||||||
exports.info.blocks[name].content = content;
|
|
||||||
else if (typeof exports.info.blocks[name].content.indexOf('<!eejs!super!>'))
|
|
||||||
exports.info.blocks[name].content = exports.info.blocks[name].content.replace('<!eejs!super!>', content);
|
|
||||||
|
|
||||||
return exports.info.blocks[name].content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.pop();
|
||||||
var renderContext = exports.info.args[exports.info.args.length-1];
|
var renderContext = exports.info.args[exports.info.args.length-1];
|
||||||
var args = {content: exports.end_define_block(), renderContext: renderContext};
|
var args = {content: exports.end_define_block(), renderContext: renderContext};
|
||||||
hooks.callAll("eejsBlock_" + name, args);
|
hooks.callAll("eejsBlock_" + name, args);
|
||||||
|
@ -91,7 +86,7 @@ exports.end_block = function () {
|
||||||
exports.begin_block = exports.begin_define_block;
|
exports.begin_block = exports.begin_define_block;
|
||||||
|
|
||||||
exports.inherit = function (name, args) {
|
exports.inherit = function (name, args) {
|
||||||
exports.info.file_stack[exports.info.file_stack.length-1].inherit.push({name:name, args:args});
|
getCurrentFile().inherit.push({name:name, args:args});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.require = function (name, args, mod) {
|
exports.require = function (name, args, mod) {
|
||||||
|
@ -101,7 +96,7 @@ exports.require = function (name, args, mod) {
|
||||||
var paths = [];
|
var paths = [];
|
||||||
|
|
||||||
if (exports.info.file_stack.length) {
|
if (exports.info.file_stack.length) {
|
||||||
basedir = path.dirname(exports.info.file_stack[exports.info.file_stack.length-1].path);
|
basedir = path.dirname(getCurrentFile().path);
|
||||||
}
|
}
|
||||||
if (mod) {
|
if (mod) {
|
||||||
basedir = path.dirname(mod.filename);
|
basedir = path.dirname(mod.filename);
|
||||||
|
|
Loading…
Reference in a new issue