00001
00002 (function() {
00003 var XMLCData, XMLComment, XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLProcessingInstruction, create, isObject;
00004
00005 create = require('lodash/create');
00006
00007 isObject = require('lodash/isObject');
00008
00009 XMLCData = require('./XMLCData');
00010
00011 XMLComment = require('./XMLComment');
00012
00013 XMLDTDAttList = require('./XMLDTDAttList');
00014
00015 XMLDTDEntity = require('./XMLDTDEntity');
00016
00017 XMLDTDElement = require('./XMLDTDElement');
00018
00019 XMLDTDNotation = require('./XMLDTDNotation');
00020
00021 XMLProcessingInstruction = require('./XMLProcessingInstruction');
00022
00023 module.exports = XMLDocType = (function() {
00024 function XMLDocType(parent, pubID, sysID) {
00025 var ref, ref1;
00026 this.documentObject = parent;
00027 this.stringify = this.documentObject.stringify;
00028 this.children = [];
00029 if (isObject(pubID)) {
00030 ref = pubID, pubID = ref.pubID, sysID = ref.sysID;
00031 }
00032 if (sysID == null) {
00033 ref1 = [pubID, sysID], sysID = ref1[0], pubID = ref1[1];
00034 }
00035 if (pubID != null) {
00036 this.pubID = this.stringify.dtdPubID(pubID);
00037 }
00038 if (sysID != null) {
00039 this.sysID = this.stringify.dtdSysID(sysID);
00040 }
00041 }
00042
00043 XMLDocType.prototype.element = function(name, value) {
00044 var child;
00045 child = new XMLDTDElement(this, name, value);
00046 this.children.push(child);
00047 return this;
00048 };
00049
00050 XMLDocType.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
00051 var child;
00052 child = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
00053 this.children.push(child);
00054 return this;
00055 };
00056
00057 XMLDocType.prototype.entity = function(name, value) {
00058 var child;
00059 child = new XMLDTDEntity(this, false, name, value);
00060 this.children.push(child);
00061 return this;
00062 };
00063
00064 XMLDocType.prototype.pEntity = function(name, value) {
00065 var child;
00066 child = new XMLDTDEntity(this, true, name, value);
00067 this.children.push(child);
00068 return this;
00069 };
00070
00071 XMLDocType.prototype.notation = function(name, value) {
00072 var child;
00073 child = new XMLDTDNotation(this, name, value);
00074 this.children.push(child);
00075 return this;
00076 };
00077
00078 XMLDocType.prototype.cdata = function(value) {
00079 var child;
00080 child = new XMLCData(this, value);
00081 this.children.push(child);
00082 return this;
00083 };
00084
00085 XMLDocType.prototype.comment = function(value) {
00086 var child;
00087 child = new XMLComment(this, value);
00088 this.children.push(child);
00089 return this;
00090 };
00091
00092 XMLDocType.prototype.instruction = function(target, value) {
00093 var child;
00094 child = new XMLProcessingInstruction(this, target, value);
00095 this.children.push(child);
00096 return this;
00097 };
00098
00099 XMLDocType.prototype.root = function() {
00100 return this.documentObject.root();
00101 };
00102
00103 XMLDocType.prototype.document = function() {
00104 return this.documentObject;
00105 };
00106
00107 XMLDocType.prototype.toString = function(options, level) {
00108 var child, i, indent, len, newline, offset, pretty, r, ref, ref1, ref2, ref3, space;
00109 pretty = (options != null ? options.pretty : void 0) || false;
00110 indent = (ref = options != null ? options.indent : void 0) != null ? ref : ' ';
00111 offset = (ref1 = options != null ? options.offset : void 0) != null ? ref1 : 0;
00112 newline = (ref2 = options != null ? options.newline : void 0) != null ? ref2 : '\n';
00113 level || (level = 0);
00114 space = new Array(level + offset + 1).join(indent);
00115 r = '';
00116 if (pretty) {
00117 r += space;
00118 }
00119 r += '<!DOCTYPE ' + this.root().name;
00120 if (this.pubID && this.sysID) {
00121 r += ' PUBLIC "' + this.pubID + '" "' + this.sysID + '"';
00122 } else if (this.sysID) {
00123 r += ' SYSTEM "' + this.sysID + '"';
00124 }
00125 if (this.children.length > 0) {
00126 r += ' [';
00127 if (pretty) {
00128 r += newline;
00129 }
00130 ref3 = this.children;
00131 for (i = 0, len = ref3.length; i < len; i++) {
00132 child = ref3[i];
00133 r += child.toString(options, level + 1);
00134 }
00135 r += ']';
00136 }
00137 r += '>';
00138 if (pretty) {
00139 r += newline;
00140 }
00141 return r;
00142 };
00143
00144 XMLDocType.prototype.ele = function(name, value) {
00145 return this.element(name, value);
00146 };
00147
00148 XMLDocType.prototype.att = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
00149 return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
00150 };
00151
00152 XMLDocType.prototype.ent = function(name, value) {
00153 return this.entity(name, value);
00154 };
00155
00156 XMLDocType.prototype.pent = function(name, value) {
00157 return this.pEntity(name, value);
00158 };
00159
00160 XMLDocType.prototype.not = function(name, value) {
00161 return this.notation(name, value);
00162 };
00163
00164 XMLDocType.prototype.dat = function(value) {
00165 return this.cdata(value);
00166 };
00167
00168 XMLDocType.prototype.com = function(value) {
00169 return this.comment(value);
00170 };
00171
00172 XMLDocType.prototype.ins = function(target, value) {
00173 return this.instruction(target, value);
00174 };
00175
00176 XMLDocType.prototype.up = function() {
00177 return this.root();
00178 };
00179
00180 XMLDocType.prototype.doc = function() {
00181 return this.document();
00182 };
00183
00184 return XMLDocType;
00185
00186 })();
00187
00188 }).call(this);