'use strict'; var Node = require('./Node'); var escapeXmlAttr = require('raptor-util/escapeXml').attr; var HtmlAttributeCollection = require('./HtmlAttributeCollection'); class HtmlElement extends Node { constructor(def) { super('HtmlElement'); this.tagName = def.tagName; this._attributes = def.attributes; if (!(this._attributes instanceof HtmlAttributeCollection)) { this._attributes = new HtmlAttributeCollection(this._attributes); } this.body = this.makeContainer(def.body); this.argument = def.argument; this.allowSelfClosing = false; this.startTagOnly = false; this._dynamicAttributesExpressionArray = undefined; } generateHtmlCode(generator) { var tagName = this.tagName; var body = this.body; var startTagOnly = this.startTagOnly; var allowSelfClosing = this.allowSelfClosing; var hasBody = body && body.length; var builder = generator.builder; // Starting tag generator.addWriteLiteral('<' + tagName); var attributes = this._attributes && this._attributes.all; if (attributes) { for (let i=0; i'); } else { if (startTagOnly) { generator.addWriteLiteral('>'); } else if (allowSelfClosing) { generator.addWriteLiteral('/>'); } } // Body if (hasBody) { generator.generateStatements(body); } // Ending tag if (tagName instanceof Node) { generator.addWriteLiteral(''); } else { if (hasBody) { generator.addWriteLiteral(''); } else { if (!startTagOnly && !allowSelfClosing) { generator.addWriteLiteral('>'); } } } } addDynamicAttributes(expression) { if (!this._dynamicAttributesExpressionArray) { this._dynamicAttributesExpressionArray = []; } this._dynamicAttributesExpressionArray.push(expression); } removeAttribute(name) { if (this._attributes) { this._attributes.removeAttribute(name); } } hasAttribute(name) { return this._attributes != null && this._attributes.hasAttribute(name); } getAttributes() { return this._attributes.all; } get attributes() { return this._attributes.all; } forEachAttribute(callback, thisObj) { var attributes = this._attributes.all.concat([]); for (let i=0, len=attributes.length; i'; } } module.exports = HtmlElement;