twing
Version:
First-class Twig engine for Node.js
37 lines (36 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSandboxTagHandler = void 0;
const parsing_1 = require("../error/parsing");
const sandbox_1 = require("../node/sandbox");
const node_1 = require("../node");
const is_made_of_whitespace_only_1 = require("../helpers/is-made-of-whitespace-only");
const createSandboxTagHandler = () => {
const tag = 'sandbox';
return {
tag,
initialize: (parser) => {
return (token, stream) => {
stream.expect("TAG_END");
let body = parser.subparse(stream, tag, (token) => {
return token.test("NAME", 'endsandbox');
});
stream.next();
stream.expect("TAG_END");
// in a sandbox tag, only include tags are allowed
if (body.type !== "include" && body.type !== "embed") {
for (const keyAndChild of (0, node_1.getChildren)(body)) {
const child = keyAndChild[1];
if (!(child.type === "text" && (0, is_made_of_whitespace_only_1.isMadeOfWhitespaceOnly)(child.attributes.data))) {
if (child.type !== "include" && child.type !== "embed") {
throw (0, parsing_1.createParsingError)('Only "include" tags are allowed within a "sandbox" section.', child, stream.source);
}
}
}
}
return (0, sandbox_1.createSandboxNode)(body, token.line, token.column, tag);
};
}
};
};
exports.createSandboxTagHandler = createSandboxTagHandler;