[Pkg-javascript-commits] [ltx] 383/469: createElement and createDOMElement

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:29 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 99d99581a33ce236229d7a8368bd310b07f1d4c0
Author: Sonny Piers <sonny at fastmail.net>
Date:   Tue Aug 25 19:12:03 2015 +0200

    createElement and createDOMElement
---
 .editorconfig                | 15 +++++++++++++
 .jshintrc                    |  2 +-
 .travis.yml                  | 20 ++++++++++-------
 CONTRIBUTING.md              |  4 ++--
 README.markdown => README.md |  2 +-
 benchmark/index.html         |  1 -
 index.js                     |  2 +-
 lib/dom-element.js           | 12 ++++++++++
 lib/element.js               | 12 ++++++++++
 lib/index-browserify.js      |  2 +-
 lib/index.js                 | 11 ++++++++--
 lib/sax/sax_easysax.js       |  2 +-
 lib/sax/sax_expat.js         |  2 +-
 lib/sax/sax_saxjs.js         |  2 +-
 ltx-browser.js               | 52 +++++++++++++++++++++++++++++++++++++-------
 test/dom-element-test.js     | 16 ++++++++++++--
 test/element-test.js         | 15 ++++++++++++-
 17 files changed, 141 insertions(+), 31 deletions(-)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..10e960a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+trim_trailing_whitespace = true
+indent_style = space
+indent_size = 2
+charset = utf-8
+
+[*.js]
+indent_size = 4
diff --git a/.jshintrc b/.jshintrc
index 303177f..33b958e 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -31,4 +31,4 @@
       "after", "window"
   ]
 
-}
\ No newline at end of file
+}
diff --git a/.travis.yml b/.travis.yml
index 23e851f..5e490fa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,14 +1,18 @@
+sudo: false
+
 language: node_js
+
 node_js:
   - "0.8"
   - "0.10"
   - "0.12"
-  - "iojs"
+  - 'iojs-v2.5.0'
+
+addons:
+  apt:
+    packages:
+      - libicu-dev
+
 before_install:
-  - "sudo apt-get install libicu-dev"
-  # Workaround for a permissions issue with Travis virtual machine images
-  # that breaks Python's multiprocessing:
-  # https://github.com/travis-ci/travis-cookbooks/issues/155
-  - version=`node -v`; if [[ $version == *"0.8."* ]]; then npm i -g npm; fi
-  - sudo rm -rf /dev/shm
-  - sudo ln -s /run/shm /dev/shm
+  # npm shipped with Node.js 0.8 doesn't support carret so let's update it
+  - 'if [ "$TRAVIS_NODE_VERSION" == "0.8" ]; then npm i -g npm; fi'
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3058471..98e136e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,7 +10,7 @@ __Note:__ If there's a feature you'd like, there's a bug you'd like to fix, or y
 
 ## Coding standards
 
-Most of the coding standards are covered by `.jshintrc`. You can also test 
+Most of the coding standards are covered by `.jshintrc`. You can also test
 any changes with `grunt test` (this will also run the tests).
 
 Things not covered by jshint:
@@ -21,7 +21,7 @@ Things not covered by jshint:
 * `exports`/`module.exports` should be at the end of the file
 * Longer, descriptive variable names are preferred, e.g. `error` vs `err`
 
-We acknowledge all the code does not meet these standards but we are working 
+We acknowledge all the code does not meet these standards but we are working
 to change this over time.
 
 ## Tests
diff --git a/README.markdown b/README.md
similarity index 97%
rename from README.markdown
rename to README.md
index 431562f..015847e 100644
--- a/README.markdown
+++ b/README.md
@@ -18,7 +18,7 @@ For documentation please see http://node-xmpp.org/doc/ltx.html
 * More documentation
 * More tests (Using [Vows](http://vowsjs.org/))
 
-# Licence 
+# Licence
 
 MIT
 
diff --git a/benchmark/index.html b/benchmark/index.html
index 44a50c8..481935a 100644
--- a/benchmark/index.html
+++ b/benchmark/index.html
@@ -6,4 +6,3 @@
   <body>
   </body>
 </html>
-
diff --git a/index.js b/index.js
index 97f8296..b01e345 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,3 @@
 'use strict';
 
-module.exports = require('./lib/index.js')
\ No newline at end of file
+module.exports = require('./lib/index.js')
diff --git a/lib/dom-element.js b/lib/dom-element.js
index 55311c2..f50d1be 100644
--- a/lib/dom-element.js
+++ b/lib/dom-element.js
@@ -107,4 +107,16 @@ DOMElement.prototype.removeChild = function (el) {
     this.remove(el)
 }
 
+DOMElement.createElement = function(name, attrs /*, child1, child2, ...*/) {
+    var el = new DOMElement(name, attrs)
+
+    var children = Array.prototype.slice.call(arguments, 2)
+
+    children.forEach(function(child) {
+        el.appendChild(child)
+    })
+    return el
+}
+
+
 module.exports = DOMElement
diff --git a/lib/element.js b/lib/element.js
index 24772e2..c72b22a 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -372,6 +372,18 @@ Element.prototype.write = function(writer) {
     }
 }
 
+Element.createElement = function(name, attrs /*, child1, child2, ...*/) {
+    var el = new Element(name, attrs)
+
+    var children = Array.prototype.slice.call(arguments, 2)
+
+    children.forEach(function(child) {
+        el.cnode(child)
+    })
+    return el
+}
+
+
 function escapeXml(s) {
     return s.
         replace(/\&/g, '&').
diff --git a/lib/index-browserify.js b/lib/index-browserify.js
index 3260a5e..223ebf4 100644
--- a/lib/index-browserify.js
+++ b/lib/index-browserify.js
@@ -6,4 +6,4 @@ var parse = require('./parse')
 parse.availableSaxParsers.push(parse.bestSaxParser = require('./sax/sax_ltx'))
 
 /* SHIM */
-module.exports = require('./index')
\ No newline at end of file
+module.exports = require('./index')
diff --git a/lib/index.js b/lib/index.js
index e208cbe..1536cc2 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,16 +1,23 @@
 'use strict';
 
 var parse = require('./parse')
+var element = require('./element')
+var Element = element.Element
+var DOMElement = require('./dom-element')
 
 /**
  * The only (relevant) data structure
  */
-exports.Element = require('./dom-element')
+exports.Element = DOMElement
+exports.createElement = Element.createElement
+
+exports.DOMElement = DOMElement
+exports.createDOMElement = DOMElement.createElement
 
 /**
  * Helper
  */
-exports.escapeXml = require('./element').escapeXml
+exports.escapeXml = element.escapeXml
 
 /**
  * DOM parser interface
diff --git a/lib/sax/sax_easysax.js b/lib/sax/sax_easysax.js
index 1a08e68..027bb61 100644
--- a/lib/sax/sax_easysax.js
+++ b/lib/sax/sax_easysax.js
@@ -57,4 +57,4 @@ function SaxEasysax() {
         this.parser(sbuffer)
         sbuffer = ''
     }
-}
\ No newline at end of file
+}
diff --git a/lib/sax/sax_expat.js b/lib/sax/sax_expat.js
index 5af770e..ca854e4 100644
--- a/lib/sax/sax_expat.js
+++ b/lib/sax/sax_expat.js
@@ -40,4 +40,4 @@ SaxExpat.prototype.end = function() {
     } else {
         this.emit('end')
     }
-}
\ No newline at end of file
+}
diff --git a/lib/sax/sax_saxjs.js b/lib/sax/sax_saxjs.js
index 05dda18..4589e33 100644
--- a/lib/sax/sax_saxjs.js
+++ b/lib/sax/sax_saxjs.js
@@ -42,4 +42,4 @@ SaxSaxjs.prototype.end = function(data) {
         this.parser.write(data)
     }
     this.parser.close()
-}
\ No newline at end of file
+}
diff --git a/ltx-browser.js b/ltx-browser.js
index 4840997..693106a 100644
--- a/ltx-browser.js
+++ b/ltx-browser.js
@@ -108,6 +108,18 @@ DOMElement.prototype.removeChild = function (el) {
     this.remove(el)
 }
 
+DOMElement.createElement = function(name, attrs /*, child1, child2, ...*/) {
+    var el = new DOMElement(name, attrs)
+
+    var children = Array.prototype.slice.call(arguments, 2)
+
+    children.forEach(function(child) {
+        el.appendChild(child)
+    })
+    return el
+}
+
+
 module.exports = DOMElement
 
 },{"./element":2,"util":11}],2:[function(require,module,exports){
@@ -485,6 +497,18 @@ Element.prototype.write = function(writer) {
     }
 }
 
+Element.createElement = function(name, attrs /*, child1, child2, ...*/) {
+    var el = new Element(name, attrs)
+
+    var children = Array.prototype.slice.call(arguments, 2)
+
+    children.forEach(function(child) {
+        el.cnode(child)
+    })
+    return el
+}
+
+
 function escapeXml(s) {
     return s.
         replace(/\&/g, '&').
@@ -514,20 +538,28 @@ parse.availableSaxParsers.push(parse.bestSaxParser = require('./sax/sax_ltx'))
 
 /* SHIM */
 module.exports = require('./index')
+
 },{"./index":4,"./parse":5,"./sax/sax_ltx":6}],4:[function(require,module,exports){
 'use strict';
 
 var parse = require('./parse')
+var element = require('./element')
+var Element = element.Element
+var DOMElement = require('./dom-element')
 
 /**
  * The only (relevant) data structure
  */
-exports.Element = require('./dom-element')
+exports.Element = DOMElement
+exports.createElement = Element.createElement
+
+exports.DOMElement = DOMElement
+exports.createDOMElement = DOMElement.createElement
 
 /**
  * Helper
  */
-exports.escapeXml = require('./element').escapeXml
+exports.escapeXml = element.escapeXml
 
 /**
  * DOM parser interface
@@ -892,10 +924,8 @@ EventEmitter.prototype.emit = function(type) {
       er = arguments[1];
       if (er instanceof Error) {
         throw er; // Unhandled 'error' event
-      } else {
-        throw TypeError('Uncaught, unspecified "error" event.');
       }
-      return false;
+      throw TypeError('Uncaught, unspecified "error" event.');
     }
   }
 
@@ -980,7 +1010,10 @@ EventEmitter.prototype.addListener = function(type, listener) {
                     'leak detected. %d listeners added. ' +
                     'Use emitter.setMaxListeners() to increase limit.',
                     this._events[type].length);
-      console.trace();
+      if (typeof console.trace === 'function') {
+        // not supported in IE 10
+        console.trace();
+      }
     }
   }
 
@@ -1207,8 +1240,11 @@ process.argv = [];
 function noop() {}
 
 process.on = noop;
+process.addListener = noop;
 process.once = noop;
 process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
 process.emit = noop;
 
 process.binding = function (name) {
@@ -1817,5 +1853,5 @@ function hasOwnProperty(obj, prop) {
   return Object.prototype.hasOwnProperty.call(obj, prop);
 }
 
-}).call(this,require("/home/lloyd/Dropbox/code/node-xmpp/ltx/node_modules/grunt-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
-},{"./support/isBuffer":10,"/home/lloyd/Dropbox/code/node-xmpp/ltx/node_modules/grunt-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":9,"inherits":8}]},{},[3])
\ No newline at end of file
+}).call(this,require("JkpR2F"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./support/isBuffer":10,"JkpR2F":9,"inherits":8}]},{},[3])
\ No newline at end of file
diff --git a/test/dom-element-test.js b/test/dom-element-test.js
index 2dfeb00..59f8c6c 100644
--- a/test/dom-element-test.js
+++ b/test/dom-element-test.js
@@ -35,6 +35,18 @@ ltx.availableSaxParsers.forEach(function(saxParser) {
 
                 assert.equal(body.getChild('p').textContent, 'DOM')
             }
-        }
+        },
+        'createElement': {
+            'create a new element and set children': function() {
+                var c = new ltx.DOMElement('bar')
+                var e = ltx.createDOMElement('foo', {'foo': 'bar'}, 'foo', c)
+                assert(e instanceof ltx.DOMElement)
+                assert.equal(e.localName, 'foo')
+                assert.equal(e.getAttribute('foo'), 'bar')
+                assert.equal(e.childNodes.length, 2)
+                assert.equal(e.childNodes[0], 'foo')
+                assert.equal(e.childNodes[1], c)
+            }
+        },
     }).export(module)
-})
\ No newline at end of file
+})
diff --git a/test/element-test.js b/test/element-test.js
index a10aad6..c895822 100644
--- a/test/element-test.js
+++ b/test/element-test.js
@@ -2,7 +2,8 @@
 
 var vows = require('vows')
   , assert = require('assert')
-  , ltx = require('./../lib/index')
+  , ltx = require('../lib/index')
+  , Element = require('../lib/element').Element
 
 vows.describe('ltx').addBatch({
     'new element': {
@@ -22,6 +23,18 @@ vows.describe('ltx').addBatch({
             assert.equal(e.getAttr('xmlns'), ns)
         }
     },
+    'createElement': {
+        'create a new element and set children': function() {
+            var c = new ltx.Element('bar')
+            var e = ltx.createElement('foo', {'foo': 'bar'}, 'foo', c)
+            assert(e instanceof Element)
+            assert(e.is('foo'))
+            assert.equal(e.attrs.foo, 'bar')
+            assert.equal(e.children.length, 2)
+            assert.equal(e.children[0], 'foo')
+            assert.equal(e.children[1], c)
+        }
+    },
     'serialization': {
         'serialize an element': function() {
             var e = new ltx.Element('e')

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