[Pkg-javascript-commits] [ltx] 36/80: Imported Upstream version 0.1.2

Jonas Smedegaard dr at jones.dk
Sun Feb 28 10:50:11 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 f1077abe25d859242aac241ac021b3b2bbeca47b
Author: Jonas Smedegaard <dr at jones.dk>
Date:   Thu Dec 22 20:15:53 2011 +0700

    Imported Upstream version 0.1.2
---
 .travis.yml                               |  4 +++
 lib/element.js                            | 47 ++++++++++++++++++-------------
 package.json                              |  6 ++--
 test/{test_element.js => element-test.js} | 32 +++++++++++++++++++--
 test/{test_parse.js => parse-test.js}     |  6 +++-
 5 files changed, 69 insertions(+), 26 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f1d0f13
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - 0.4
+  - 0.6
diff --git a/lib/element.js b/lib/element.js
index 37c2058..14d0c11 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -72,32 +72,34 @@ Element.prototype.getChild = function(name, xmlns) {
  **/
 Element.prototype.getChildren = function(name, xmlns) {
     var result = [];
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
         if (child.getName &&
             child.getName() == name &&
             (!xmlns || child.getNS() == xmlns))
             result.push(child);
-    });
+    }
     return result;
 };
 
 Element.prototype.getText = function() {
     var text = "";
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
         if (typeof child == 'string')
             text += child;
-    });
+    }
     return text;
 };
 
 Element.prototype.getChildText = function(name) {
     var text = null;
-    this.children.forEach(function(el) {
-        if (!text && el.name == name)
-        {
-            text = el.getText();
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
+        if (!text && child.name == name) {
+            text = child.getText();
         }
-    });
+    }
     return text;
 };
 
@@ -175,9 +177,10 @@ Element.prototype.clone = function() {
 	if (this.attrs.hasOwnProperty(k))
 	    clone.attrs[k] = this.attrs[k];
     }
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
 	clone.cnode(child.clone ? child.clone() : child);
-    });
+    }
     return clone;
 };
 
@@ -196,7 +199,7 @@ Element.prototype.write = function(writer) {
     writer(this.name);
     for(var k in this.attrs) {
         var v = this.attrs[k];
-	if (v || v === '') {
+	if (v || v === '' || v === 0) {
 	    writer(" ");
             writer(k);
             writer("=\"");
@@ -210,14 +213,18 @@ Element.prototype.write = function(writer) {
         writer("/>");
     } else {
         writer(">");
-        this.children.forEach(function(child) {
-            if (child.write)
-                child.write(writer);
-            else if (typeof child === 'string')
-                writer(escapeXmlText(child));
-	    else
-                writer(escapeXmlText(child.toString()));
-        });
+	for(var i = 0; i < this.children.length; i++) {
+	    var child = this.children[i];
+	    /* Skip null/undefined */
+	    if (child || child === 0) {
+		if (child.write)
+		    child.write(writer);
+		else if (typeof child === 'string')
+			writer(escapeXmlText(child));
+		else if (child.toString)
+			writer(escapeXmlText(child.toString()));
+	    }
+        }
         writer("</");
         writer(this.name);
         writer(">");
diff --git a/package.json b/package.json
index 5e8694d..e530e3e 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 { "name": "ltx"
-,"version": "0.1.1"
+,"version": "0.1.2"
 ,"main": "./lib/index"
 ,"description": "<xml for=\"node.js\">"
 ,"author": "Stephan Maka"
@@ -15,6 +15,8 @@
 		 ,"web": "http://spaceboyz.net/~astro/"
 		 }]
 ,"contributors": ["Stephan Maka"]
-,"licenses": [{"type": "GPLv3"}]
+,"licenses": [{"type": "MIT"}]
 ,"engine": "node"
+,"devDependencies": {"vows": ">=0.5.12"}
+,"scripts": {"test":"vows --spec"}
 }
diff --git a/test/test_element.js b/test/element-test.js
similarity index 77%
rename from test/test_element.js
rename to test/element-test.js
index 7f9a059..2de09e9 100644
--- a/test/test_element.js
+++ b/test/element-test.js
@@ -31,8 +31,34 @@ vows.describe('ltx').addBatch({
 	    assert.equal(e.toString(), '<e a="23"/>');
 	},
 	'serialize an element with number contents': function() {
-	    var e = new ltx.Element('e').t(23);
-	    assert.equal(e.toString(), '<e>23</e>');
+	    var e = new ltx.Element('e');
+	    e.c('foo').t(23);
+	    e.c('bar').t(0);
+	    assert.equal(e.toString(), '<e><foo>23</foo><bar>0</bar></e>');
+	},
+	'serialize with undefined attribute': function() {
+	    var e = new ltx.Element('e', { foo: undefined });
+	    assert.equal(e.toString(), '<e/>');
+	},
+	'serialize with null attribute': function() {
+	    var e = new ltx.Element('e', { foo: null });
+	    assert.equal(e.toString(), '<e/>');
+	},
+	'serialize with number attribute': function() {
+	    var e = new ltx.Element('e', { foo: 23, bar: 0 });
+	    var s = e.toString();
+	    assert.ok(s.match(/foo="23"/));
+	    assert.ok(s.match(/bar="0"/));
+	},
+	'serialize with undefined child': function() {
+	    var e = new ltx.Element('e');
+	    e.children = [undefined];
+	    assert.equal(e.toString(), '<e></e>');
+	},
+	'serialize with null child': function() {
+	    var e = new ltx.Element('e');
+	    e.children = [null];
+	    assert.equal(e.toString(), '<e></e>');
 	}
     },
 
@@ -104,4 +130,4 @@ vows.describe('ltx').addBatch({
 	    assert.equal(clone.getChildText('description'), 'foobar');
 	}
     }
-}).run();
+}).export(module);
diff --git a/test/test_parse.js b/test/parse-test.js
similarity index 80%
rename from test/test_parse.js
rename to test/parse-test.js
index 423f416..0f05708 100644
--- a/test/test_parse.js
+++ b/test/parse-test.js
@@ -9,6 +9,10 @@ vows.describe('ltx').addBatch({
             assert.equal(el.name, 'root');
             assert.equal(0, el.children.length);
         },
+	'text with commas': function() {
+	    var el = ltx.parse("<body>sa'sa'1'sasa</body>");
+	    assert.equal("sa'sa'1'sasa", el.getText());
+	},
         'erroneous document raises error': function() {
             assert.throws(function() {
                 ltx.parse('<root></toor>');
@@ -20,4 +24,4 @@ vows.describe('ltx').addBatch({
             });
         }
     }
-}).run();
+}).export(module);

-- 
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