[Pkg-javascript-commits] [ltx] 15/80: Imported Upstream version 0.0.4+20110330

Jonas Smedegaard dr at jones.dk
Sun Feb 28 10:50:08 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 100f6608311fe4126853f86e3043ffaf30b4c468
Author: dr at jones.dk <dr at jones.dk>
Date:   Fri Apr 22 11:56:58 2011 +0200

    Imported Upstream version 0.0.4+20110330
---
 lib/element.js       | 27 +++++++++++++++++++++++++++
 test/test_element.js | 21 +++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/lib/element.js b/lib/element.js
index c583375..8e0e981 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -137,6 +137,33 @@ Element.prototype.t = function(text) {
     return this;
 };
 
+/*** Manipulation ***/
+
+/**
+ * Either:
+ *   el.remove(childEl);
+ *   el.remove('author', 'urn:...');
+ */
+Element.prototype.remove = function(el, xmlns) {
+    var filter;
+    if (typeof el === 'string') {
+	/* 1st parameter is tag name */
+	filter = function(child) {
+	    return !(child.is &&
+		     child.is(el, xmlns));
+	};
+    } else {
+	/* 1st parameter is element */
+	filter = function(child) {
+	    return child !== el;
+	};
+    }
+
+    this.children = this.children.filter(filter);
+
+    return this;
+};
+
 /*** Serialization ***/
 
 Element.prototype.toString = function() {
diff --git a/test/test_element.js b/test/test_element.js
index 0535cff..27bed1a 100644
--- a/test/test_element.js
+++ b/test/test_element.js
@@ -26,5 +26,26 @@ vows.describe('ltx').addBatch({
 	    var e = new ltx.Element('e').t('1 < 2').root();
 	    assert.equal(e.toString(), '<e>1 < 2</e>');
 	}
+    },
+
+    'remove': {
+	'by element': function() {
+	    var el = new ltx.Element('e').
+		c('c').c('x').up().up().
+		c('c2').up().
+		c('c').up();
+	    el.remove(el.getChild('c'));
+	    assert.equal(el.getChildren('c').length, 1);
+	    assert.equal(el.getChildren('c2').length, 1);
+	},
+	'by name': function() {
+	    var el = new ltx.Element('e').
+		c('c').up().
+		c('c2').up().
+		c('c').up();
+	    el.remove('c');
+	    assert.equal(el.getChildren('c').length, 0);
+	    assert.equal(el.getChildren('c2').length, 1);
+	}
     }
 }).run();

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