[Pkg-javascript-commits] [ltx] 370/469: attrs can be a string
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:03:28 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 2415606c230bcd3deea841808888b9aba3d80b61
Author: Sonny Piers <sonny at fastmail.net>
Date: Sun Feb 15 19:33:45 2015 +0100
attrs can be a string
---
lib/element.js | 11 ++++++++---
test/element-test.js | 6 ++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/lib/element.js b/lib/element.js
index a5f54e5..b9e9207 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -83,9 +83,14 @@ Element.prototype.getXmlns = function() {
Element.prototype.setAttrs = function(attrs) {
this.attrs = {}
- Object.keys(attrs || {}).forEach(function(key) {
- this.attrs[key] = attrs[key]
- }, this)
+
+ if (typeof attrs === 'string')
+ this.attrs.xmlns = attrs
+ else if (attrs) {
+ Object.keys(attrs).forEach(function(key) {
+ this.attrs[key] = attrs[key]
+ }, this)
+ }
}
/**
diff --git a/test/element-test.js b/test/element-test.js
index cfe33a4..a10aad6 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -14,6 +14,12 @@ vows.describe('ltx').addBatch({
assert.equal(o.bar, undefined)
o.foobar = 'barfoo'
assert.equal(e.attrs.foobar, undefined)
+ },
+ 'set xmlns attribute if a string is passed as second argument': function() {
+ var ns = 'xmlns:test'
+ var e = new ltx.Element('e', ns)
+ assert.equal(e.attrs.xmlns, ns)
+ assert.equal(e.getAttr('xmlns'), ns)
}
},
'serialization': {
--
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