[Pkg-javascript-commits] [ltx] 311/469: Cleaned up lib/element.js

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:20 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 7220bd4a40778ff16d90e3f615ce92eab8026701
Author: Lloyd Watkin <lloyd at evilprofessor.co.uk>
Date:   Sun Feb 16 20:13:51 2014 +0000

    Cleaned up lib/element.js
---
 lib/element.js | 51 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index 29fe252..7968a5e 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -287,6 +287,26 @@ Element.prototype.toString = function() {
     return s
 }
 
+Element.prototype._addChildren = function(writer) {
+    writer('>')
+    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(10)))
+            }
+        }
+    }
+    writer('</')
+    writer(this.name)
+    writer('>')
+}
+
 Element.prototype.write = function(writer) {
     writer('<')
     writer(this.name)
@@ -294,34 +314,19 @@ Element.prototype.write = function(writer) {
         var v = this.attrs[k]
         if (v || (v === '') || (v === 0)) {
             writer(' ')
-                writer(k)
-                writer('="')
-                if (typeof v !== 'string')
-            v = v.toString(10)
-                writer(escapeXml(v))
-                writer('"')
+            writer(k)
+            writer('="')
+            if (typeof v !== 'string') {
+                v = v.toString(10)
+            }
+            writer(escapeXml(v))
+            writer('"')
         }
     }
     if (this.children.length === 0) {
         writer('/>')
     } else {
-        writer('>')
-        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(10)))
-                }
-            }
-        }
-        writer('</')
-        writer(this.name)
-        writer('>')
+        this._addChildren(writer)
     }
 }
 

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