[Pkg-javascript-commits] [ltx] 288/469: Merge #32. Thanks @julien51.

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 1402c593bc044d0de7bc7a9b2cde7fe8a341504e
Author: Lloyd Watkin <lloyd.watkin at surevine.com>
Date:   Thu Jan 9 08:49:07 2014 +0000

    Merge #32. Thanks @julien51.
---
 lib/element.js | 254 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 127 insertions(+), 127 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index 72aff2a..4611e74 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -5,10 +5,10 @@
  * either other Elements or Strings for text content.
  **/
 function Element(name, attrs) {
-    this.name = name;
-    this.parent = null;
-    this.attrs = attrs || {};
-    this.children = [];
+    this.name = name
+    this.parent = null
+    this.attrs = attrs || {}
+    this.children = []
 }
 
 /*** Accessors ***/
@@ -18,28 +18,28 @@ function Element(name, attrs) {
  **/
 Element.prototype.is = function(name, xmlns) {
     return this.getName() == name &&
-        (!xmlns || this.getNS() == xmlns);
-};
+        (!xmlns || this.getNS() == xmlns)
+}
 
 /* without prefix */
 Element.prototype.getName = function() {
     if (this.name.indexOf(":") >= 0)
-        return this.name.substr(this.name.indexOf(":") + 1);
+        return this.name.substr(this.name.indexOf(":") + 1)
     else
-        return this.name;
-};
+        return this.name
+}
 
 /**
  * retrieves the namespace of the current element, upwards recursively
  **/
 Element.prototype.getNS = function() {
     if (this.name.indexOf(":") >= 0) {
-        var prefix = this.name.substr(0, this.name.indexOf(":"));
-        return this.findNS(prefix);
+        var prefix = this.name.substr(0, this.name.indexOf(":"))
+        return this.findNS(prefix)
     } else {
-        return this.findNS();
+        return this.findNS()
     }
-};
+}
 
 /**
  * find the namespace to the given prefix, upwards recursively
@@ -48,36 +48,36 @@ Element.prototype.findNS = function(prefix) {
     if (!prefix) {
         /* default namespace */
         if (this.attrs.xmlns)
-            return this.attrs.xmlns;
+            return this.attrs.xmlns
         else if (this.parent)
-            return this.parent.findNS();
+            return this.parent.findNS()
     } else {
         /* prefixed namespace */
-        var attr = 'xmlns:' + prefix;
+        var attr = 'xmlns:' + prefix
         if (this.attrs[attr])
-            return this.attrs[attr];
+            return this.attrs[attr]
         else if (this.parent)
-            return this.parent.findNS(prefix);
+            return this.parent.findNS(prefix)
     }
-};
+}
 
 /**
  * Recursiverly gets all xmlns defined, in the form of {url:prefix}
  **/
 Element.prototype.getXmlns = function() {
-    var namespaces = {};
+    var namespaces = {}
 
     if (this.parent)
-        namespaces = this.parent.getXmlns();
+        namespaces = this.parent.getXmlns()
 
     for (var attr in this.attrs) {
-        var m = attr.match('xmlns:?(.*)');
+        var m = attr.match('xmlns:?(.*)')
         if (this.attrs.hasOwnProperty(attr) && m) {
-            namespaces[this.attrs[attr]] = m[1];
+            namespaces[this.attrs[attr]] = m[1]
         }
     }
-    return namespaces;
-};
+    return namespaces
+}
 
 
 /**
@@ -85,156 +85,156 @@ Element.prototype.getXmlns = function() {
  **/
 Element.prototype.getAttr = function(name, xmlns) {
     if(!xmlns)
-        return this.attrs[name];
+        return this.attrs[name]
 
-    var namespaces = this.getXmlns();
+    var namespaces = this.getXmlns()
 
     if(!namespaces[xmlns])
-        return null;
+        return null
 
-    return this.attrs[[namespaces[xmlns], name].join(':')];
-};
+    return this.attrs[[namespaces[xmlns], name].join(':')]
+}
 
 /**
  * xmlns can be null
  **/
 Element.prototype.getChild = function(name, xmlns) {
-    return this.getChildren(name, xmlns)[0];
-};
+    return this.getChildren(name, xmlns)[0]
+}
 
 /**
  * xmlns can be null
  **/
 Element.prototype.getChildren = function(name, xmlns) {
-    var result = [];
+    var result = []
     for(var i = 0; i < this.children.length; i++) {
-	      var child = this.children[i];
+	      var child = this.children[i]
         if (child.getName &&
             child.getName() == name &&
             (!xmlns || child.getNS() == xmlns))
-            result.push(child);
+            result.push(child)
     }
-    return result;
-};
+    return result
+}
 
 /**
  * xmlns and recursive can be null
  **/
 Element.prototype.getChildByAttr = function(attr, val, xmlns, recursive) {
-    return this.getChildrenByAttr(attr, val, xmlns, recursive)[0];
-};
+    return this.getChildrenByAttr(attr, val, xmlns, recursive)[0]
+}
 
 /**
  * xmlns and recursive can be null
  **/
 Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
-    var result = [];
+    var result = []
     for(var i = 0; i < this.children.length; i++) {
-	      var child = this.children[i];
+	      var child = this.children[i]
         if (child.attrs &&
             child.attrs[attr] == val &&
             (!xmlns || child.getNS() == xmlns))
-            result.push(child);
+            result.push(child)
         if (recursive && child.getChildrenByAttr)
-            result.push(child.getChildrenByAttr(attr, val, xmlns, true));
+            result.push(child.getChildrenByAttr(attr, val, xmlns, true))
     }
-    if (recursive) result = [].concat.apply([], result);
-    return result;
-};
+    if (recursive) result = [].concat.apply([], result)
+    return result
+}
 
 Element.prototype.getChildrenByFilter = function(filter, recursive) {
-    var result = [];
+    var result = []
     for(var i = 0; i < this.children.length; i++) {
-        var child = this.children[i];
+        var child = this.children[i]
         if (filter(child))
-            result.push(child);
+            result.push(child)
         if (recursive && child.getChildrenByFilter){
-            result.push(child.getChildrenByFilter(filter, true));
+            result.push(child.getChildrenByFilter(filter, true))
         }
     }
     if (recursive){
-      result = [].concat.apply([], result);
+      result = [].concat.apply([], result)
     }
-    return result;
-};
+    return result
+}
 
 Element.prototype.getText = function() {
-    var text = "";
+    var text = ""
     for(var i = 0; i < this.children.length; i++) {
 	var child = this.children[i]
         if (typeof child == 'string' || typeof child == 'number')
-            text += child;
+            text += child
     }
-    return text;
-};
+    return text
+}
 
 Element.prototype.getChildText = function(name, xmlns) {
-    var child = this.getChild(name, xmlns);
-    return child ? child.getText() : null;
-};
+    var child = this.getChild(name, xmlns)
+    return child ? child.getText() : null
+}
 
 /*** Builder ***/
 
 /** returns uppermost parent */
 Element.prototype.root = function() {
     if (this.parent)
-        return this.parent.root();
+        return this.parent.root()
     else
-        return this;
-};
-Element.prototype.tree = Element.prototype.root;
+        return this
+}
+Element.prototype.tree = Element.prototype.root
 
 /** just parent or itself */
 Element.prototype.up = function() {
     if (this.parent)
-        return this.parent;
+        return this.parent
     else
-        return this;
-};
+        return this
+}
 
 /** create child node and return it */
 Element.prototype.c = function(name, attrs) {
-    return this.cnode(new Element(name, attrs));
-};
+    return this.cnode(new Element(name, attrs))
+}
 
 Element.prototype.cnode = function(child) {
-    this.children.push(child);
-    child.parent = this;
-    return child;
-};
+    this.children.push(child)
+    child.parent = this
+    return child
+}
 
 /** add text node and return element */
 Element.prototype.t = function(text) {
-    this.children.push(text);
-    return this;
-};
+    this.children.push(text)
+    return this
+}
 
 /*** Manipulation ***/
 
 /**
  * Either:
- *   el.remove(childEl);
- *   el.remove('author', 'urn:...');
+ *   el.remove(childEl)
+ *   el.remove('author', 'urn:...')
  */
 Element.prototype.remove = function(el, xmlns) {
-    var filter;
+    var filter
     if (typeof el === 'string') {
 	/* 1st parameter is tag name */
 	filter = function(child) {
 	    return !(child.is &&
-		     child.is(el, xmlns));
-	};
+		     child.is(el, xmlns))
+	}
     } else {
 	/* 1st parameter is element */
 	filter = function(child) {
-	    return child !== el;
-	};
+	    return child !== el
+	}
     }
 
-    this.children = this.children.filter(filter);
+    this.children = this.children.filter(filter)
 
-    return this;
-};
+    return this
+}
 
 /**
  * To use in case you want the same XML data for separate uses.
@@ -242,83 +242,83 @@ Element.prototype.remove = function(el, xmlns) {
  * doing. Building XML with ltx is easy!
  */
 Element.prototype.clone = function() {
-    var clone = new Element(this.name, {});
+    var clone = new Element(this.name, {})
     for(var k in this.attrs) {
 	if (this.attrs.hasOwnProperty(k))
-	    clone.attrs[k] = this.attrs[k];
+	    clone.attrs[k] = this.attrs[k]
     }
     for(var i = 0; i < this.children.length; i++) {
-	var child = this.children[i];
-	clone.cnode(child.clone ? child.clone() : child);
+	var child = this.children[i]
+	clone.cnode(child.clone ? child.clone() : child)
     }
-    return clone;
-};
+    return clone
+}
 
 Element.prototype.text = function(val) {
     if(val && this.children.length == 1){
-        this.children[0] = val;
-        return this;
+        this.children[0] = val
+        return this
     }
-    return this.getText();
-};
+    return this.getText()
+}
 
 Element.prototype.attr = function(attr, val) {
     if (!(typeof val === 'undefined' || val === null)) {
         if(!this.attrs){
-          this.attrs = {};
+          this.attrs = {}
         }
-        this.attrs[attr] = val;
-        return this;
+        this.attrs[attr] = val
+        return this
     }
-    return this.attrs[attr];
-};
+    return this.attrs[attr]
+}
 
 /*** Serialization ***/
 
 Element.prototype.toString = function() {
-    var s = "";
+    var s = ""
     this.write(function(c) {
-        s += c;
-    });
-    return s;
-};
+        s += c
+    })
+    return s
+}
 
 Element.prototype.write = function(writer) {
-    writer("<");
-    writer(this.name);
+    writer("<")
+    writer(this.name)
     for(var k in this.attrs) {
-        var v = this.attrs[k];
+        var v = this.attrs[k]
 	if (v || v === '' || v === 0) {
-	    writer(" ");
-            writer(k);
-            writer("=\"");
+	    writer(" ")
+            writer(k)
+            writer("=\"")
             if (typeof v != 'string')
-		v = v.toString(10);
-            writer(escapeXml(v));
-            writer("\"");
+		v = v.toString(10)
+            writer(escapeXml(v))
+            writer("\"")
 	}
     }
     if (this.children.length == 0) {
-        writer("/>");
+        writer("/>")
     } else {
-        writer(">");
+        writer(">")
 	for(var i = 0; i < this.children.length; i++) {
-	    var child = this.children[i];
+	    var child = this.children[i]
 	    /* Skip null/undefined */
 	    if (child || child === 0) {
 		if (child.write)
-		    child.write(writer);
+		    child.write(writer)
 		else if (typeof child === 'string')
-			writer(escapeXmlText(child));
+			writer(escapeXmlText(child))
 		else if (child.toString)
-			writer(escapeXmlText(child.toString(10)));
+			writer(escapeXmlText(child.toString(10)))
 	    }
         }
-        writer("</");
-        writer(this.name);
-        writer(">");
+        writer("</")
+        writer(this.name)
+        writer(">")
     }
-};
+}
 
 function escapeXml(s) {
     return s.
@@ -336,5 +336,5 @@ function escapeXmlText(s) {
         replace(/>/g, '>');
 }
 
-exports.Element = Element;
-exports.escapeXml = escapeXml;
+exports.Element = Element
+exports.escapeXml = escapeXml

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list