eejs: Inline `begin_capture`, `end_capture`

r-p-opts
Richard Hansen 2021-01-19 17:34:09 -05:00 committed by John McLear
parent 7d11d54323
commit c8c3929058
1 changed files with 6 additions and 14 deletions

View File

@ -47,27 +47,19 @@ exports._exit = (b, recursive) => {
exports.info.__output = exports.info.__output_stack.pop();
};
exports.begin_capture = () => {
exports.info.__output_stack.push(exports.info.__output.concat());
exports.info.__output.splice(0, exports.info.__output.length);
};
exports.end_capture = () => {
const res = exports.info.__output.join('');
exports.info.__output.splice(
0, exports.info.__output.length, ...exports.info.__output_stack.pop());
return res;
};
exports.begin_block = (name) => {
exports.info.block_stack.push(name);
exports.begin_capture();
exports.info.__output_stack.push(exports.info.__output.concat());
exports.info.__output.splice(0, exports.info.__output.length);
};
exports.end_block = () => {
const name = exports.info.block_stack.pop();
const renderContext = exports.info.args[exports.info.args.length - 1];
const args = {content: exports.end_capture(), renderContext};
const content = exports.info.__output.join('');
exports.info.__output.splice(
0, exports.info.__output.length, ...exports.info.__output_stack.pop());
const args = {content, renderContext};
hooks.callAll(`eejsBlock_${name}`, args);
exports.info.__output.push(args.content);
};