UNPKG

woltlab-compiler

Version:

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

80 lines 3.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("util"); const XMLEditor_1 = require("../../Serialization/XMLEditor"); const NamedObjectDeletionFileCompiler_1 = require("../NamedObjectDeletionFileCompiler"); /** * Provides the functionality to compile bb-codes. */ class BBCodeFileCompiler extends NamedObjectDeletionFileCompiler_1.NamedObjectDeletionFileCompiler { /** * Initializes a new instance of the `BBCodeFileCompiler` class. * * @param item * The item to compile. */ constructor(item) { super(item); } /** * @inheritdoc */ get SchemaLocation() { return "https://www.woltlab.com/XSD/vortex/bbcode.xsd"; } /** * @inheritdoc */ get ObjectTagName() { return "bbcode"; } /** * @inheritdoc */ CreateImport() { let editor = new XMLEditor_1.XMLEditor(super.CreateImport()); for (let bbCode of this.Item.BBCodes) { editor.AddElement(this.ObjectTagName, (bbCodeEditor) => { bbCodeEditor.SetAttribute("name", bbCode.Name); if (bbCode.DisplayName.GetLocales().length > 0) { bbCodeEditor.AddTextElement("buttonLabel", `wcf.editor.button.${bbCode.Name}`); } if (!util_1.isNullOrUndefined(bbCode.Icon)) { bbCodeEditor.AddTextElement("wysiwygicon", bbCode.Icon); } if (!util_1.isNullOrUndefined(bbCode.ClassName)) { bbCodeEditor.AddTextElement("classname", bbCode.ClassName); } if (!util_1.isNullOrUndefined(bbCode.TagName)) { bbCodeEditor.AddTextElement("htmlopen", bbCode.TagName); if (!bbCode.IsSelfClosing) { bbCodeEditor.AddTextElement("htmlclose", bbCode.TagName); } } bbCodeEditor.AddTextElement("isBlockElement", bbCode.IsBlockElement ? "1" : "0"); bbCodeEditor.AddTextElement("sourcecode", bbCode.ParseContent ? "0" : "1"); if (bbCode.Attributes.length > 0) { bbCodeEditor.AddElement("attributes", (attributes) => { for (let i = 0; i < bbCode.Attributes.length; i++) { let attribute = bbCode.Attributes[i]; attributes.AddElement("attribute", (attributeEditor) => { attributeEditor.SetAttribute("name", i.toString()); attributeEditor.AddTextElement("required", attribute.Required ? "1" : "0"); attributeEditor.AddTextElement("useText", attribute.ValueByContent ? "1" : "0"); if (!util_1.isNullOrUndefined(attribute.Code)) { attributeEditor.AddTextElement("html", attribute.Code); } if (!util_1.isNullOrUndefined(attribute.ValidationPattern)) { attributeEditor.AddTextElement("validationpattern", attribute.ValidationPattern.source); } }); } }); } }); } return editor.Element; } } exports.BBCodeFileCompiler = BBCodeFileCompiler; //# sourceMappingURL=BBCodeFileCompiler.js.map