aboutsummaryrefslogtreecommitdiff
path: root/node_modules/xmlbuilder/lib/XMLNode.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/xmlbuilder/lib/XMLNode.js')
-rw-r--r--node_modules/xmlbuilder/lib/XMLNode.js187
1 files changed, 43 insertions, 144 deletions
diff --git a/node_modules/xmlbuilder/lib/XMLNode.js b/node_modules/xmlbuilder/lib/XMLNode.js
index 1b3b456ab..0a6340b44 100644
--- a/node_modules/xmlbuilder/lib/XMLNode.js
+++ b/node_modules/xmlbuilder/lib/XMLNode.js
@@ -1,9 +1,13 @@
-// Generated by CoffeeScript 1.10.0
+// Generated by CoffeeScript 1.9.1
(function() {
- var XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLElement, XMLNode, XMLProcessingInstruction, XMLRaw, XMLText, isEmpty, isFunction, isObject, ref,
+ var XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLElement, XMLNode, XMLRaw, XMLText, isEmpty, isFunction, isObject,
hasProp = {}.hasOwnProperty;
- ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction, isEmpty = ref.isEmpty;
+ isObject = require('lodash/isObject');
+
+ isFunction = require('lodash/isFunction');
+
+ isEmpty = require('lodash/isEmpty');
XMLElement = null;
@@ -19,17 +23,12 @@
XMLText = null;
- XMLProcessingInstruction = null;
-
module.exports = XMLNode = (function() {
function XMLNode(parent) {
this.parent = parent;
- if (this.parent) {
- this.options = this.parent.options;
- this.stringify = this.parent.stringify;
- }
- this.children = [];
- if (!XMLElement) {
+ this.options = this.parent.options;
+ this.stringify = this.parent.stringify;
+ if (XMLElement === null) {
XMLElement = require('./XMLElement');
XMLCData = require('./XMLCData');
XMLComment = require('./XMLComment');
@@ -37,19 +36,18 @@
XMLDocType = require('./XMLDocType');
XMLRaw = require('./XMLRaw');
XMLText = require('./XMLText');
- XMLProcessingInstruction = require('./XMLProcessingInstruction');
}
}
XMLNode.prototype.element = function(name, attributes, text) {
- var childNode, item, j, k, key, lastChild, len, len1, ref1, val;
+ var childNode, item, j, k, key, lastChild, len, len1, ref, val;
lastChild = null;
if (attributes == null) {
attributes = {};
}
attributes = attributes.valueOf();
if (!isObject(attributes)) {
- ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
+ ref = [attributes, text], text = ref[0], attributes = ref[1];
}
if (name != null) {
name = name.valueOf();
@@ -73,6 +71,8 @@
}
if (!this.options.ignoreDecorators && this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
+ } else if (!this.options.ignoreDecorators && this.stringify.convertPIKey && key.indexOf(this.stringify.convertPIKey) === 0) {
+ lastChild = this.instruction(key.substr(this.stringify.convertPIKey.length), val);
} else if (!this.options.separateArrayItems && Array.isArray(val)) {
for (k = 0, len1 = val.length; k < len1; k++) {
item = val[k];
@@ -96,8 +96,6 @@
lastChild = this.comment(text);
} else if (!this.options.ignoreDecorators && this.stringify.convertRawKey && name.indexOf(this.stringify.convertRawKey) === 0) {
lastChild = this.raw(text);
- } else if (!this.options.ignoreDecorators && this.stringify.convertPIKey && name.indexOf(this.stringify.convertPIKey) === 0) {
- lastChild = this.instruction(name.substr(this.stringify.convertPIKey.length), text);
} else {
lastChild = this.node(name, attributes, text);
}
@@ -133,24 +131,26 @@
};
XMLNode.prototype.remove = function() {
- var i, ref1;
+ var i, ref;
if (this.isRoot) {
throw new Error("Cannot remove the root element");
}
i = this.parent.children.indexOf(this);
- [].splice.apply(this.parent.children, [i, i - i + 1].concat(ref1 = [])), ref1;
+ [].splice.apply(this.parent.children, [i, i - i + 1].concat(ref = [])), ref;
return this.parent;
};
XMLNode.prototype.node = function(name, attributes, text) {
- var child, ref1;
+ var child, ref;
if (name != null) {
name = name.valueOf();
}
- attributes || (attributes = {});
+ if (attributes == null) {
+ attributes = {};
+ }
attributes = attributes.valueOf();
if (!isObject(attributes)) {
- ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
+ ref = [attributes, text], text = ref[0], attributes = ref[1];
}
child = new XMLElement(this, name, attributes);
if (text != null) {
@@ -181,24 +181,6 @@
return this;
};
- XMLNode.prototype.commentBefore = function(value) {
- var child, i, removed;
- i = this.parent.children.indexOf(this);
- removed = this.parent.children.splice(i);
- child = this.parent.comment(value);
- Array.prototype.push.apply(this.parent.children, removed);
- return this;
- };
-
- XMLNode.prototype.commentAfter = function(value) {
- var child, i, removed;
- i = this.parent.children.indexOf(this);
- removed = this.parent.children.splice(i + 1);
- child = this.parent.comment(value);
- Array.prototype.push.apply(this.parent.children, removed);
- return this;
- };
-
XMLNode.prototype.raw = function(value) {
var child;
child = new XMLRaw(this, value);
@@ -206,86 +188,19 @@
return this;
};
- XMLNode.prototype.instruction = function(target, value) {
- var insTarget, insValue, instruction, j, len;
- if (target != null) {
- target = target.valueOf();
- }
- if (value != null) {
- value = value.valueOf();
- }
- if (Array.isArray(target)) {
- for (j = 0, len = target.length; j < len; j++) {
- insTarget = target[j];
- this.instruction(insTarget);
- }
- } else if (isObject(target)) {
- for (insTarget in target) {
- if (!hasProp.call(target, insTarget)) continue;
- insValue = target[insTarget];
- this.instruction(insTarget, insValue);
- }
- } else {
- if (isFunction(value)) {
- value = value.apply();
- }
- instruction = new XMLProcessingInstruction(this, target, value);
- this.children.push(instruction);
- }
- return this;
- };
-
- XMLNode.prototype.instructionBefore = function(target, value) {
- var child, i, removed;
- i = this.parent.children.indexOf(this);
- removed = this.parent.children.splice(i);
- child = this.parent.instruction(target, value);
- Array.prototype.push.apply(this.parent.children, removed);
- return this;
- };
-
- XMLNode.prototype.instructionAfter = function(target, value) {
- var child, i, removed;
- i = this.parent.children.indexOf(this);
- removed = this.parent.children.splice(i + 1);
- child = this.parent.instruction(target, value);
- Array.prototype.push.apply(this.parent.children, removed);
- return this;
- };
-
XMLNode.prototype.declaration = function(version, encoding, standalone) {
var doc, xmldec;
doc = this.document();
xmldec = new XMLDeclaration(doc, version, encoding, standalone);
- if (doc.children[0] instanceof XMLDeclaration) {
- doc.children[0] = xmldec;
- } else {
- doc.children.unshift(xmldec);
- }
- return doc.root() || doc;
+ doc.xmldec = xmldec;
+ return doc.root();
};
XMLNode.prototype.doctype = function(pubID, sysID) {
- var child, doc, doctype, i, j, k, len, len1, ref1, ref2;
+ var doc, doctype;
doc = this.document();
doctype = new XMLDocType(doc, pubID, sysID);
- ref1 = doc.children;
- for (i = j = 0, len = ref1.length; j < len; i = ++j) {
- child = ref1[i];
- if (child instanceof XMLDocType) {
- doc.children[i] = doctype;
- return doctype;
- }
- }
- ref2 = doc.children;
- for (i = k = 0, len1 = ref2.length; k < len1; i = ++k) {
- child = ref2[i];
- if (child.isRoot) {
- doc.children.splice(i, 0, doctype);
- return doctype;
- }
- }
- doc.children.push(doctype);
+ doc.doctype = doctype;
return doctype;
};
@@ -297,37 +212,30 @@
};
XMLNode.prototype.root = function() {
- var node;
- node = this;
- while (node) {
- if (node.isDocument) {
- return node.rootObject;
- } else if (node.isRoot) {
- return node;
- } else {
- node = node.parent;
- }
+ var child;
+ if (this.isRoot) {
+ return this;
+ }
+ child = this.parent;
+ while (!child.isRoot) {
+ child = child.parent;
}
+ return child;
};
XMLNode.prototype.document = function() {
- var node;
- node = this;
- while (node) {
- if (node.isDocument) {
- return node;
- } else {
- node = node.parent;
- }
- }
+ return this.root().documentObject;
};
XMLNode.prototype.end = function(options) {
- return this.document().end(options);
+ return this.document().toString(options);
};
XMLNode.prototype.prev = function() {
var i;
+ if (this.isRoot) {
+ throw new Error("Root node has no siblings");
+ }
i = this.parent.children.indexOf(this);
if (i < 1) {
throw new Error("Already at the first node");
@@ -337,6 +245,9 @@
XMLNode.prototype.next = function() {
var i;
+ if (this.isRoot) {
+ throw new Error("Root node has no siblings");
+ }
i = this.parent.children.indexOf(this);
if (i === -1 || i === this.parent.children.length - 1) {
throw new Error("Already at the last node");
@@ -344,9 +255,9 @@
return this.parent.children[i + 1];
};
- XMLNode.prototype.importDocument = function(doc) {
+ XMLNode.prototype.importXMLBuilder = function(xmlbuilder) {
var clonedRoot;
- clonedRoot = doc.root().clone();
+ clonedRoot = xmlbuilder.root().clone();
clonedRoot.parent = this;
clonedRoot.isRoot = false;
this.children.push(clonedRoot);
@@ -373,10 +284,6 @@
return this.comment(value);
};
- XMLNode.prototype.ins = function(target, value) {
- return this.instruction(target, value);
- };
-
XMLNode.prototype.doc = function() {
return this.document();
};
@@ -413,18 +320,10 @@
return this.raw(value);
};
- XMLNode.prototype.i = function(target, value) {
- return this.instruction(target, value);
- };
-
XMLNode.prototype.u = function() {
return this.up();
};
- XMLNode.prototype.importXMLBuilder = function(doc) {
- return this.importDocument(doc);
- };
-
return XMLNode;
})();