a zip code crypto-currency system good for red ONLY

XMLNode.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. // Generated by CoffeeScript 1.12.7
  2. (function() {
  3. var XMLCData, XMLComment, XMLDeclaration, XMLDocType, XMLElement, XMLNode, XMLProcessingInstruction, XMLRaw, XMLText, isEmpty, isFunction, isObject, ref,
  4. hasProp = {}.hasOwnProperty;
  5. ref = require('./Utility'), isObject = ref.isObject, isFunction = ref.isFunction, isEmpty = ref.isEmpty;
  6. XMLElement = null;
  7. XMLCData = null;
  8. XMLComment = null;
  9. XMLDeclaration = null;
  10. XMLDocType = null;
  11. XMLRaw = null;
  12. XMLText = null;
  13. XMLProcessingInstruction = null;
  14. module.exports = XMLNode = (function() {
  15. function XMLNode(parent) {
  16. this.parent = parent;
  17. if (this.parent) {
  18. this.options = this.parent.options;
  19. this.stringify = this.parent.stringify;
  20. }
  21. this.children = [];
  22. if (!XMLElement) {
  23. XMLElement = require('./XMLElement');
  24. XMLCData = require('./XMLCData');
  25. XMLComment = require('./XMLComment');
  26. XMLDeclaration = require('./XMLDeclaration');
  27. XMLDocType = require('./XMLDocType');
  28. XMLRaw = require('./XMLRaw');
  29. XMLText = require('./XMLText');
  30. XMLProcessingInstruction = require('./XMLProcessingInstruction');
  31. }
  32. }
  33. XMLNode.prototype.element = function(name, attributes, text) {
  34. var childNode, item, j, k, key, lastChild, len, len1, ref1, val;
  35. lastChild = null;
  36. if (attributes == null) {
  37. attributes = {};
  38. }
  39. attributes = attributes.valueOf();
  40. if (!isObject(attributes)) {
  41. ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
  42. }
  43. if (name != null) {
  44. name = name.valueOf();
  45. }
  46. if (Array.isArray(name)) {
  47. for (j = 0, len = name.length; j < len; j++) {
  48. item = name[j];
  49. lastChild = this.element(item);
  50. }
  51. } else if (isFunction(name)) {
  52. lastChild = this.element(name.apply());
  53. } else if (isObject(name)) {
  54. for (key in name) {
  55. if (!hasProp.call(name, key)) continue;
  56. val = name[key];
  57. if (isFunction(val)) {
  58. val = val.apply();
  59. }
  60. if ((isObject(val)) && (isEmpty(val))) {
  61. val = null;
  62. }
  63. if (!this.options.ignoreDecorators && this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
  64. lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
  65. } else if (!this.options.separateArrayItems && Array.isArray(val)) {
  66. for (k = 0, len1 = val.length; k < len1; k++) {
  67. item = val[k];
  68. childNode = {};
  69. childNode[key] = item;
  70. lastChild = this.element(childNode);
  71. }
  72. } else if (isObject(val)) {
  73. lastChild = this.element(key);
  74. lastChild.element(val);
  75. } else {
  76. lastChild = this.element(key, val);
  77. }
  78. }
  79. } else {
  80. if (!this.options.ignoreDecorators && this.stringify.convertTextKey && name.indexOf(this.stringify.convertTextKey) === 0) {
  81. lastChild = this.text(text);
  82. } else if (!this.options.ignoreDecorators && this.stringify.convertCDataKey && name.indexOf(this.stringify.convertCDataKey) === 0) {
  83. lastChild = this.cdata(text);
  84. } else if (!this.options.ignoreDecorators && this.stringify.convertCommentKey && name.indexOf(this.stringify.convertCommentKey) === 0) {
  85. lastChild = this.comment(text);
  86. } else if (!this.options.ignoreDecorators && this.stringify.convertRawKey && name.indexOf(this.stringify.convertRawKey) === 0) {
  87. lastChild = this.raw(text);
  88. } else if (!this.options.ignoreDecorators && this.stringify.convertPIKey && name.indexOf(this.stringify.convertPIKey) === 0) {
  89. lastChild = this.instruction(name.substr(this.stringify.convertPIKey.length), text);
  90. } else {
  91. lastChild = this.node(name, attributes, text);
  92. }
  93. }
  94. if (lastChild == null) {
  95. throw new Error("Could not create any elements with: " + name);
  96. }
  97. return lastChild;
  98. };
  99. XMLNode.prototype.insertBefore = function(name, attributes, text) {
  100. var child, i, removed;
  101. if (this.isRoot) {
  102. throw new Error("Cannot insert elements at root level");
  103. }
  104. i = this.parent.children.indexOf(this);
  105. removed = this.parent.children.splice(i);
  106. child = this.parent.element(name, attributes, text);
  107. Array.prototype.push.apply(this.parent.children, removed);
  108. return child;
  109. };
  110. XMLNode.prototype.insertAfter = function(name, attributes, text) {
  111. var child, i, removed;
  112. if (this.isRoot) {
  113. throw new Error("Cannot insert elements at root level");
  114. }
  115. i = this.parent.children.indexOf(this);
  116. removed = this.parent.children.splice(i + 1);
  117. child = this.parent.element(name, attributes, text);
  118. Array.prototype.push.apply(this.parent.children, removed);
  119. return child;
  120. };
  121. XMLNode.prototype.remove = function() {
  122. var i, ref1;
  123. if (this.isRoot) {
  124. throw new Error("Cannot remove the root element");
  125. }
  126. i = this.parent.children.indexOf(this);
  127. [].splice.apply(this.parent.children, [i, i - i + 1].concat(ref1 = [])), ref1;
  128. return this.parent;
  129. };
  130. XMLNode.prototype.node = function(name, attributes, text) {
  131. var child, ref1;
  132. if (name != null) {
  133. name = name.valueOf();
  134. }
  135. attributes || (attributes = {});
  136. attributes = attributes.valueOf();
  137. if (!isObject(attributes)) {
  138. ref1 = [attributes, text], text = ref1[0], attributes = ref1[1];
  139. }
  140. child = new XMLElement(this, name, attributes);
  141. if (text != null) {
  142. child.text(text);
  143. }
  144. this.children.push(child);
  145. return child;
  146. };
  147. XMLNode.prototype.text = function(value) {
  148. var child;
  149. child = new XMLText(this, value);
  150. this.children.push(child);
  151. return this;
  152. };
  153. XMLNode.prototype.cdata = function(value) {
  154. var child;
  155. child = new XMLCData(this, value);
  156. this.children.push(child);
  157. return this;
  158. };
  159. XMLNode.prototype.comment = function(value) {
  160. var child;
  161. child = new XMLComment(this, value);
  162. this.children.push(child);
  163. return this;
  164. };
  165. XMLNode.prototype.commentBefore = function(value) {
  166. var child, i, removed;
  167. i = this.parent.children.indexOf(this);
  168. removed = this.parent.children.splice(i);
  169. child = this.parent.comment(value);
  170. Array.prototype.push.apply(this.parent.children, removed);
  171. return this;
  172. };
  173. XMLNode.prototype.commentAfter = function(value) {
  174. var child, i, removed;
  175. i = this.parent.children.indexOf(this);
  176. removed = this.parent.children.splice(i + 1);
  177. child = this.parent.comment(value);
  178. Array.prototype.push.apply(this.parent.children, removed);
  179. return this;
  180. };
  181. XMLNode.prototype.raw = function(value) {
  182. var child;
  183. child = new XMLRaw(this, value);
  184. this.children.push(child);
  185. return this;
  186. };
  187. XMLNode.prototype.instruction = function(target, value) {
  188. var insTarget, insValue, instruction, j, len;
  189. if (target != null) {
  190. target = target.valueOf();
  191. }
  192. if (value != null) {
  193. value = value.valueOf();
  194. }
  195. if (Array.isArray(target)) {
  196. for (j = 0, len = target.length; j < len; j++) {
  197. insTarget = target[j];
  198. this.instruction(insTarget);
  199. }
  200. } else if (isObject(target)) {
  201. for (insTarget in target) {
  202. if (!hasProp.call(target, insTarget)) continue;
  203. insValue = target[insTarget];
  204. this.instruction(insTarget, insValue);
  205. }
  206. } else {
  207. if (isFunction(value)) {
  208. value = value.apply();
  209. }
  210. instruction = new XMLProcessingInstruction(this, target, value);
  211. this.children.push(instruction);
  212. }
  213. return this;
  214. };
  215. XMLNode.prototype.instructionBefore = function(target, value) {
  216. var child, i, removed;
  217. i = this.parent.children.indexOf(this);
  218. removed = this.parent.children.splice(i);
  219. child = this.parent.instruction(target, value);
  220. Array.prototype.push.apply(this.parent.children, removed);
  221. return this;
  222. };
  223. XMLNode.prototype.instructionAfter = function(target, value) {
  224. var child, i, removed;
  225. i = this.parent.children.indexOf(this);
  226. removed = this.parent.children.splice(i + 1);
  227. child = this.parent.instruction(target, value);
  228. Array.prototype.push.apply(this.parent.children, removed);
  229. return this;
  230. };
  231. XMLNode.prototype.declaration = function(version, encoding, standalone) {
  232. var doc, xmldec;
  233. doc = this.document();
  234. xmldec = new XMLDeclaration(doc, version, encoding, standalone);
  235. if (doc.children[0] instanceof XMLDeclaration) {
  236. doc.children[0] = xmldec;
  237. } else {
  238. doc.children.unshift(xmldec);
  239. }
  240. return doc.root() || doc;
  241. };
  242. XMLNode.prototype.doctype = function(pubID, sysID) {
  243. var child, doc, doctype, i, j, k, len, len1, ref1, ref2;
  244. doc = this.document();
  245. doctype = new XMLDocType(doc, pubID, sysID);
  246. ref1 = doc.children;
  247. for (i = j = 0, len = ref1.length; j < len; i = ++j) {
  248. child = ref1[i];
  249. if (child instanceof XMLDocType) {
  250. doc.children[i] = doctype;
  251. return doctype;
  252. }
  253. }
  254. ref2 = doc.children;
  255. for (i = k = 0, len1 = ref2.length; k < len1; i = ++k) {
  256. child = ref2[i];
  257. if (child.isRoot) {
  258. doc.children.splice(i, 0, doctype);
  259. return doctype;
  260. }
  261. }
  262. doc.children.push(doctype);
  263. return doctype;
  264. };
  265. XMLNode.prototype.up = function() {
  266. if (this.isRoot) {
  267. throw new Error("The root node has no parent. Use doc() if you need to get the document object.");
  268. }
  269. return this.parent;
  270. };
  271. XMLNode.prototype.root = function() {
  272. var node;
  273. node = this;
  274. while (node) {
  275. if (node.isDocument) {
  276. return node.rootObject;
  277. } else if (node.isRoot) {
  278. return node;
  279. } else {
  280. node = node.parent;
  281. }
  282. }
  283. };
  284. XMLNode.prototype.document = function() {
  285. var node;
  286. node = this;
  287. while (node) {
  288. if (node.isDocument) {
  289. return node;
  290. } else {
  291. node = node.parent;
  292. }
  293. }
  294. };
  295. XMLNode.prototype.end = function(options) {
  296. return this.document().end(options);
  297. };
  298. XMLNode.prototype.prev = function() {
  299. var i;
  300. i = this.parent.children.indexOf(this);
  301. if (i < 1) {
  302. throw new Error("Already at the first node");
  303. }
  304. return this.parent.children[i - 1];
  305. };
  306. XMLNode.prototype.next = function() {
  307. var i;
  308. i = this.parent.children.indexOf(this);
  309. if (i === -1 || i === this.parent.children.length - 1) {
  310. throw new Error("Already at the last node");
  311. }
  312. return this.parent.children[i + 1];
  313. };
  314. XMLNode.prototype.importDocument = function(doc) {
  315. var clonedRoot;
  316. clonedRoot = doc.root().clone();
  317. clonedRoot.parent = this;
  318. clonedRoot.isRoot = false;
  319. this.children.push(clonedRoot);
  320. return this;
  321. };
  322. XMLNode.prototype.ele = function(name, attributes, text) {
  323. return this.element(name, attributes, text);
  324. };
  325. XMLNode.prototype.nod = function(name, attributes, text) {
  326. return this.node(name, attributes, text);
  327. };
  328. XMLNode.prototype.txt = function(value) {
  329. return this.text(value);
  330. };
  331. XMLNode.prototype.dat = function(value) {
  332. return this.cdata(value);
  333. };
  334. XMLNode.prototype.com = function(value) {
  335. return this.comment(value);
  336. };
  337. XMLNode.prototype.ins = function(target, value) {
  338. return this.instruction(target, value);
  339. };
  340. XMLNode.prototype.doc = function() {
  341. return this.document();
  342. };
  343. XMLNode.prototype.dec = function(version, encoding, standalone) {
  344. return this.declaration(version, encoding, standalone);
  345. };
  346. XMLNode.prototype.dtd = function(pubID, sysID) {
  347. return this.doctype(pubID, sysID);
  348. };
  349. XMLNode.prototype.e = function(name, attributes, text) {
  350. return this.element(name, attributes, text);
  351. };
  352. XMLNode.prototype.n = function(name, attributes, text) {
  353. return this.node(name, attributes, text);
  354. };
  355. XMLNode.prototype.t = function(value) {
  356. return this.text(value);
  357. };
  358. XMLNode.prototype.d = function(value) {
  359. return this.cdata(value);
  360. };
  361. XMLNode.prototype.c = function(value) {
  362. return this.comment(value);
  363. };
  364. XMLNode.prototype.r = function(value) {
  365. return this.raw(value);
  366. };
  367. XMLNode.prototype.i = function(target, value) {
  368. return this.instruction(target, value);
  369. };
  370. XMLNode.prototype.u = function() {
  371. return this.up();
  372. };
  373. XMLNode.prototype.importXMLBuilder = function(doc) {
  374. return this.importDocument(doc);
  375. };
  376. return XMLNode;
  377. })();
  378. }).call(this);