UNPKG

woltlab-compiler

Version:

A compiler for WoltLab-Package Archives and WoltLab-Package Components

62 lines 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const XMLFileCompiler_1 = require("./XMLFileCompiler"); /** * Provides the functionality to compile `xml`-files which contain `EJS`-strings. */ class EJSFileCompiler extends XMLFileCompiler_1.XMLFileCompiler { /** * Initializes a new instance of the `EJSFileCompiler<T>` class. * * @param item * The item to compile. */ constructor(item) { super(item); } /** * Gets the delimiter of the EJS-strings inside the document. */ get Delimiter() { return "%"; } /** * Gets the pattern to match against the document. */ get Pattern() { return new RegExp(`<${this.Delimiter}.*?${this.Delimiter}>`, "g"); } /** * @inheritdoc */ get Document() { let document = super.Document; this.FixEJSTags(document); return document; } /** * Fixes the ejs-tags inside the node. * * @param node * The node to fix. */ FixEJSTags(node) { switch (node.nodeType) { case node.TEXT_NODE: if (this.Pattern.test(node.textContent)) { node.parentNode.replaceChild(node.ownerDocument.createCDATASection(node.textContent), node); } break; default: if (node.hasChildNodes()) { for (let i = 0; i < node.childNodes.length; i++) { let child = node.childNodes.item(i); this.FixEJSTags(child); } } break; } } } exports.EJSFileCompiler = EJSFileCompiler; //# sourceMappingURL=EJSFileCompiler.js.map