// Generated by CoffeeScript 1.10.0 (function() { var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDeclaration, XMLDocType, XMLElement, XMLProcessingInstruction, XMLRaw, XMLStreamWriter, XMLText, XMLWriterBase, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; XMLDeclaration = require('./XMLDeclaration'); XMLDocType = require('./XMLDocType'); XMLCData = require('./XMLCData'); XMLComment = require('./XMLComment'); XMLElement = require('./XMLElement'); XMLRaw = require('./XMLRaw'); XMLText = require('./XMLText'); XMLProcessingInstruction = require('./XMLProcessingInstruction'); XMLDTDAttList = require('./XMLDTDAttList'); XMLDTDElement = require('./XMLDTDElement'); XMLDTDEntity = require('./XMLDTDEntity'); XMLDTDNotation = require('./XMLDTDNotation'); XMLWriterBase = require('./XMLWriterBase'); module.exports = XMLStreamWriter = (function(superClass) { extend(XMLStreamWriter, superClass); function XMLStreamWriter(stream, options) { this.stream = stream; XMLStreamWriter.__super__.constructor.call(this, options); } XMLStreamWriter.prototype.document = function(doc) { var child, i, j, len, len1, ref, ref1, results; ref = doc.children; for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; child.isLastRootNode = false; } doc.children[doc.children.length - 1].isLastRootNode = true; ref1 = doc.children; results = []; for (j = 0, len1 = ref1.length; j < len1; j++) { child = ref1[j]; switch (false) { case !(child instanceof XMLDeclaration): results.push(this.declaration(child)); break; case !(child instanceof XMLDocType): results.push(this.docType(child)); break; case !(child instanceof XMLComment): results.push(this.comment(child)); break; case !(child instanceof XMLProcessingInstruction): results.push(this.processingInstruction(child)); break; default: results.push(this.element(child)); } } return results; }; XMLStreamWriter.prototype.attribute = function(att) { return this.stream.write(' ' + att.name + '="' + att.value + '"'); }; XMLStreamWriter.prototype.cdata = function(node, level) { return this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.comment = function(node, level) { return this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.declaration = function(node, level) { this.stream.write(this.space(level)); this.stream.write(''); return this.stream.write(this.endline(node)); }; XMLStreamWriter.prototype.docType = function(node, level) { var child, i, len, ref; level || (level = 0); this.stream.write(this.space(level)); this.stream.write(' 0) { this.stream.write(' ['); this.stream.write(this.endline(node)); ref = node.children; for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; switch (false) { case !(child instanceof XMLDTDAttList): this.dtdAttList(child, level + 1); break; case !(child instanceof XMLDTDElement): this.dtdElement(child, level + 1); break; case !(child instanceof XMLDTDEntity): this.dtdEntity(child, level + 1); break; case !(child instanceof XMLDTDNotation): this.dtdNotation(child, level + 1); break; case !(child instanceof XMLCData): this.cdata(child, level + 1); break; case !(child instanceof XMLComment): this.comment(child, level + 1); break; case !(child instanceof XMLProcessingInstruction): this.processingInstruction(child, level + 1); break; default: throw new Error("Unknown DTD node type: " + child.constructor.name); } } this.stream.write(']'); } this.stream.write('>'); return this.stream.write(this.endline(node)); }; XMLStreamWriter.prototype.element = function(node, level) { var att, child, i, len, name, ref, ref1, space; level || (level = 0); space = this.space(level); this.stream.write(space + '<' + node.name); ref = node.attributes; for (name in ref) { if (!hasProp.call(ref, name)) continue; att = ref[name]; this.attribute(att); } if (node.children.length === 0 || node.children.every(function(e) { return e.value === ''; })) { if (this.allowEmpty) { this.stream.write('>'); } else { this.stream.write('/>'); } } else if (this.pretty && node.children.length === 1 && (node.children[0].value != null)) { this.stream.write('>'); this.stream.write(node.children[0].value); this.stream.write(''); } else { this.stream.write('>' + this.newline); ref1 = node.children; for (i = 0, len = ref1.length; i < len; i++) { child = ref1[i]; switch (false) { case !(child instanceof XMLCData): this.cdata(child, level + 1); break; case !(child instanceof XMLComment): this.comment(child, level + 1); break; case !(child instanceof XMLElement): this.element(child, level + 1); break; case !(child instanceof XMLRaw): this.raw(child, level + 1); break; case !(child instanceof XMLText): this.text(child, level + 1); break; case !(child instanceof XMLProcessingInstruction): this.processingInstruction(child, level + 1); break; default: throw new Error("Unknown XML node type: " + child.constructor.name); } } this.stream.write(space + ''); } return this.stream.write(this.endline(node)); }; XMLStreamWriter.prototype.processingInstruction = function(node, level) { this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.raw = function(node, level) { return this.stream.write(this.space(level) + node.value + this.endline(node)); }; XMLStreamWriter.prototype.text = function(node, level) { return this.stream.write(this.space(level) + node.value + this.endline(node)); }; XMLStreamWriter.prototype.dtdAttList = function(node, level) { this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.dtdElement = function(node, level) { return this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.dtdEntity = function(node, level) { this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.dtdNotation = function(node, level) { this.stream.write(this.space(level) + '' + this.endline(node)); }; XMLStreamWriter.prototype.endline = function(node) { if (!node.isLastRootNode) { return this.newline; } else { return ''; } }; return XMLStreamWriter; })(XMLWriterBase); }).call(this);