From cc6afc917733a18169cd51c619627b806716f082 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Tue, 23 Jun 2015 13:45:24 -0400 Subject: [PATCH 1/5] adding npm deploy config --- .travis.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 506d918..d92bfd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,19 @@ env: - secure: Nvi1f97+rXj7eW39Wu+YsCVPsLUSW+Zj3AiAgKpxY+vgy64Bw103982gdcbDPZfmhqIQSUYAE+LMuudD7zpnF89Ib0QP9aH2ksSMH5+tP7+MLhshqxd4PlJRNU5dqmknawIGUGDGfHCc6fXpp9CCHpfHy5GstKdCkh6LPegIqGxzp7UFhXeKCUcmCz2hFp0oB6vDtPJ8HCupCFkcQRM0rQetY7uZXfBdFZAAK4rtWgu2i09tTdYBCwn+iVrZjjTJvSixM/7ks5coFmkSmzr0UoiN2wxvYQanws8pg3zYiL65eJN46J1zu9UdTPLZ0gS9VmhPQbHHUkETjHYnT0ztqPlxc0K2BxQwkqLBdC/g7KQ3RQgOzsfbRlGQTTXlp1+AxXbRLhS+RSP+w9HFFffb8wc3SXd05NyEnFIuvxyy0qAQlw/6WxWHxC/zII0FacK5iC+9ZYe0RIEUnUQ7BczaJhFalUqn5IX5PMqwJ3c8b0YaXhe09QXd1eqC0CG69kCRbF8dzW7UE2dL94Lj7aGx4VWNc0gYcwr3d0jB1pyQqUyp6ETYqUTpIRsOOWJF7FpELqchMsOIJucfDLN2kh3+sYR4jjbPmry4bmLMekCVEEYtbBSdAd+XGLFwzwaKzBPNhxiTS211xGY9n2haytQ2sOHX7yoTJZ42Kn659QHPfi0= - secure: Ta4d95k2C3TsLl8q7vZMmXgUBN77WHU6jZGGprPUztHiL9Pj/c3E5AvL7ypaL2lisL7a3dHqP2rriYgfmOv0ZGiUcn9Hsx+ButYWBucYU5sugYHglUb9LQnjJP22xJBTLFonLHPEs6MqzeKQSN056KlyY3s86dA3P5BfgIEUZAg/H/72+Sgh/rQBk1D+avzSF6u7Dbv6xse0LwUNISuIq2HBITL7jjRLnsFnbXTf/jwU+5YhVys7hU7KnmP1upMDphFhWFuiVFk91Vo8m5r2Qtr40msFIpD0re0DjKwCDWXk5BgY7xURXdUTMTjc4086Qbve01GZATQkvxl/lyHPJBeNvkW54COhGG3G6HQND6bklUCDhC4q9+ckL5ruTbRcZMW7YiZMHRwoI6AqpPAzyjXGm+/oPNmwBaWaVmb7sRQwhibHMsTVhIeAce679TgmHZHrH3JRIzPUw7lAr8AJz+KbTEeMid9djztTqrU+R+PisM9LJZ3KmuDjaOAm9DoI9td74yHXYq+5aF9N7sfkPNBwJNktXBdTkl61MmCEOdydP/E9Dg/g+meErITa2soL97P7jFcai5CxxTccFByJ6/SQiUIeywK9MoeHv208sdNtwhdtR+e42b6NbASOuIRZLK0IlkuEjwF+dUP3ERs3nj9whFV5FdWJYJRjddPW+5I= deploy: - provider: releases - file_glob: true - api_key: - secure: BK4uk/HK2vC8h46/GMkw8hN8IZheQu2f2DQ9gE/CTYZqe2uy3xwbcXCGrYFa2Cz7rWnfuP3Zm8w4e1z0LyXL3iptqmjvqEWxuoilLOhkjQaVbbkPbQUye/TxiW6RO4OB0GF09YopqT+sIDQdzJkyk5s/TvszbWGRMjU/Bfore3x2Z0EBtK9/2xCQyC6mo7WBrPGP8IAC0BhPCGGmM0R50ve56xdbxx8F1WzJRKBKZtztFa2Ql+GEk8Yn7rfHwfUmfasb5qYX7eGmMJQERiwMmBm8nVrg5dUt/itqyAjLtXE2xFSvp7kDs+HTIPd+8Uh93XGgREucXUK/+71nuN2oz84mhEXaSzSEGPNGHxiZGZ3Ihibv4eq/XJuR9TGijmo6mhPPgZuMEhtuJz41JSGPCwVyXA9/8ZIQRqdD12oJqoxWepMbuCPhkzQ1fQfkQu6WR4saUfK64JsJmcfxeQNU8kUXSdw+nmi65p/JixzQt/QnxHKJlQIoHV9Km0itCsVJfTxOZUYHBsV1fck37nL2Xe3zqiMBUBeZo68c0e+oSqZLasWSVC6LewrxoshyFXAkkV3Q2G2TY5BK3Y/6iovf/QLlu71v7ZDN0WIvCNoaRy4Otod9kRlhIsSo92b5X5hq48k/3E5ZrUYbQ2oZusETUt38ogI9SCbcR6FAKQLO7k4= - file: dist/*.zip - skip_cleanup: true - on: - repo: murrayju/xslt - tags: true + - provider: releases + file_glob: true + api_key: + secure: BK4uk/HK2vC8h46/GMkw8hN8IZheQu2f2DQ9gE/CTYZqe2uy3xwbcXCGrYFa2Cz7rWnfuP3Zm8w4e1z0LyXL3iptqmjvqEWxuoilLOhkjQaVbbkPbQUye/TxiW6RO4OB0GF09YopqT+sIDQdzJkyk5s/TvszbWGRMjU/Bfore3x2Z0EBtK9/2xCQyC6mo7WBrPGP8IAC0BhPCGGmM0R50ve56xdbxx8F1WzJRKBKZtztFa2Ql+GEk8Yn7rfHwfUmfasb5qYX7eGmMJQERiwMmBm8nVrg5dUt/itqyAjLtXE2xFSvp7kDs+HTIPd+8Uh93XGgREucXUK/+71nuN2oz84mhEXaSzSEGPNGHxiZGZ3Ihibv4eq/XJuR9TGijmo6mhPPgZuMEhtuJz41JSGPCwVyXA9/8ZIQRqdD12oJqoxWepMbuCPhkzQ1fQfkQu6WR4saUfK64JsJmcfxeQNU8kUXSdw+nmi65p/JixzQt/QnxHKJlQIoHV9Km0itCsVJfTxOZUYHBsV1fck37nL2Xe3zqiMBUBeZo68c0e+oSqZLasWSVC6LewrxoshyFXAkkV3Q2G2TY5BK3Y/6iovf/QLlu71v7ZDN0WIvCNoaRy4Otod9kRlhIsSo92b5X5hq48k/3E5ZrUYbQ2oZusETUt38ogI9SCbcR6FAKQLO7k4= + file: dist/*.zip + skip_cleanup: true + on: + repo: murrayju/xslt + tags: true + - provider: npm + email: murrayju@addpcs.com + api_key: + secure: pxKis/Q588HnyH8Nyrt1N3bCkmOQtudYIfZowVAIy6RQw6yN48vzmTj/D8RmGkJFdFgaz1ofOSgxjAoLr3qj2v7nUgWH323ixMtnAUISaydokE9gFdbjpg7bhxT3dNWwCCv0z3v02xHYWTTFKI1K/9U4guHdvnbSfciW5zjS8gkQ3QilysCB07ipFpXb9f4ZoKlI3+qa/32jiVdUPkIweMlLLXyUqR1PfYRsxpsPaYGRTDIXR5NU0uKJJnUB5qOImef1DociQ5Ahr+kyAP4K9Wnnys5Xe9on7M6k8ITWKbtlWfsbCXW/49oln0v5f/hTDrhTVyPr5bVX6y/whGHaEmWg0FrglYo6vzpL6jJckFyqlH+HKTSpqZZA2xIJGr+YyHJGX9WHXgXF1A44TTnmDqrWapeCYgrjyqp4KbnVZPWP47Bf1KVqp60dNQ3cYDrclgLlDsMlqLgfhj21lHZalUh8rYAPCr5medjNyzL8+3b0dguOo+5kbD+hRNxpgRE0tA9KTf2G5ZVp8f3WLmuZ4q3j9OlTaW8332wPAF7uh9tPIVjuC1vzoj3HKv7SZY5euJquCWwKVRe7ZqrR3+M0KPo9eiCXDyrCEcgC3mmNuD9MgPOI0ilivtK8oTe+llQHcDF0Te38SXzWlEaovdKukjbB+n+yuvTkcyh6IPtfIuE= + on: + repo: murrayju/xslt + tags: true From fc59523f7ca425d6c2828e2afb25c27ae3be9ed4 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Tue, 23 Jun 2015 16:15:47 -0400 Subject: [PATCH 2/5] Include IE in default tests --- Gruntfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 27c522a..9c5bdcf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -142,7 +142,8 @@ module.exports = function (grunt) { // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: [ 'Chrome', - 'Firefox' + 'Firefox', + 'IE' ], customLaunchers: { @@ -280,8 +281,7 @@ module.exports = function (grunt) { var browsers = _.union(_.keys(opts.customLaunchers), opts.browsers, [ 'PhantomJS', 'Opera', - 'Safari', - 'IE' + 'Safari' ]); if (grunt.option('all-bs')) { opts.browsers = _.filter(browsers, function (b) { From 747c845e840974ffe27d437eca4b7293d37cd965 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Tue, 23 Jun 2015 16:15:59 -0400 Subject: [PATCH 3/5] Increment version --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ca8b3a0..fcf49ae 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { "major": 0, - "minor": 1, + "minor": 2, "patch": 0 } From baca642ef9fe7dfdbcc698f6c8604e1701199a7d Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Tue, 23 Jun 2015 16:16:48 -0400 Subject: [PATCH 4/5] Make xml header in output an explicit choice --- README.md | 1 + src/xslt.coffee | 17 +++++++++++++---- test/data/hello.html | 1 + test/karma/specs/xsltSpec.coffee | 7 +++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 489260d..067ad5b 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Several options are available to get started: ```js options = { fullDocument: false, // Is the output a complete document, or a fragment? + xmlHeaderInOutput: true, cleanup: true, // false will disable all of the below options removeDupNamespace: true, removeDupAttrs: true, diff --git a/src/xslt.coffee b/src/xslt.coffee index 20b4997..2742f19 100644 --- a/src/xslt.coffee +++ b/src/xslt.coffee @@ -15,6 +15,7 @@ needsHeader = (str) -> isXml(str) && !hasXmlHeader(str) xmlHeader = '' prependHeader = (str) -> xmlHeader + str + stripHeader = (str) -> str.replace(/\s*<\?xml[^<]+/, '') activeXSupported = ActiveXObject? || 'ActiveXObject' of window tryCreateActiveX = (objIds...) -> @@ -81,11 +82,18 @@ throw new Error("Failed to load document from string:\r\n#{d.documentElement.textContent}") return d - docToStr = (doc) -> + docToStr = (doc, opt) -> return null unless doc? - xml = doc?.xml || new XMLSerializer?()?.serializeToString?(doc) + xml = if typeof doc == 'string' + doc + else + doc?.xml || new XMLSerializer?()?.serializeToString?(doc) if xml?.indexOf?("= 0 xml = xml.substring(xml.indexOf(">") + 1, xml.lastIndexOf("<")) + if opt.xmlHeaderInOutput + xml = prependHeader(xml) if needsHeader(xml) + else + xml = stripHeader(xml) return xml arrayContains = (arr, val) -> @@ -143,6 +151,7 @@ defaults = fullDocument: false + xmlHeaderInOutput: true cleanup: true removeDupNamespace: true removeDupAttrs: true @@ -167,7 +176,7 @@ else processor.transformToFragment(xmlDoc, document) else if 'transformNode' of xmlDoc - return xmlDoc.transformNode(xsltDoc) + trans = xmlDoc.transformNode(xsltDoc) else if activeXSupported xslt = createXSLTemplate() xslt.stylesheet = xsltDoc @@ -176,7 +185,7 @@ xslProc.transform() trans = xslProc.output - outStr = docToStr(trans) + outStr = docToStr(trans, opt) if opt.cleanup outStr = cleanupXmlNodes(outStr, opt) outStr = stripRedundantNamespaces(outStr) if opt.removeDupNamespace diff --git a/test/data/hello.html b/test/data/hello.html index 3f24594..1bd2dc0 100644 --- a/test/data/hello.html +++ b/test/data/hello.html @@ -1,3 +1,4 @@ +

Hello, World!

from An XSLT Programmer
diff --git a/test/karma/specs/xsltSpec.coffee b/test/karma/specs/xsltSpec.coffee index 517efd3..0009c4e 100644 --- a/test/karma/specs/xsltSpec.coffee +++ b/test/karma/specs/xsltSpec.coffee @@ -21,3 +21,10 @@ define [ it 'can do a simple transform', -> str = xslt(helloXml, helloXsl, {removeAllNamespaces: true}) util.xmlDiff(helloOutput, str, true) + + it 'can strip xml header', -> + str = xslt(helloXml, helloXsl, { + removeAllNamespaces: true + xmlHeaderInOutput: false + }) + util.xmlDiff(helloOutput.replace(/\s*<\?xml[^<]+/, ''), str, true) From f75094d0f1a15577970015c431838868ed898e0c Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Tue, 23 Jun 2015 16:22:18 -0400 Subject: [PATCH 5/5] Move implementation under the cleanup option --- src/xslt.coffee | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/xslt.coffee b/src/xslt.coffee index 2742f19..11bb594 100644 --- a/src/xslt.coffee +++ b/src/xslt.coffee @@ -82,18 +82,14 @@ throw new Error("Failed to load document from string:\r\n#{d.documentElement.textContent}") return d - docToStr = (doc, opt) -> + docToStr = (doc) -> return null unless doc? - xml = if typeof doc == 'string' + xml = if (typeof doc) == 'string' doc else doc?.xml || new XMLSerializer?()?.serializeToString?(doc) if xml?.indexOf?("= 0 xml = xml.substring(xml.indexOf(">") + 1, xml.lastIndexOf("<")) - if opt.xmlHeaderInOutput - xml = prependHeader(xml) if needsHeader(xml) - else - xml = stripHeader(xml) return xml arrayContains = (arr, val) -> @@ -185,8 +181,12 @@ xslProc.transform() trans = xslProc.output - outStr = docToStr(trans, opt) + outStr = docToStr(trans) if opt.cleanup + outStr = if opt.xmlHeaderInOutput and needsHeader(outStr) + prependHeader(outStr) + else + stripHeader(outStr) outStr = cleanupXmlNodes(outStr, opt) outStr = stripRedundantNamespaces(outStr) if opt.removeDupNamespace return outStr