xml-twig 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/doc/twig.md +16 -0
- package/package.json +1 -1
- package/twig.js +17 -6
package/doc/twig.md
CHANGED
|
@@ -143,6 +143,7 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
143
143
|
* [.pin](#Twig+pin)
|
|
144
144
|
* [.pinned](#Twig+pinned) ⇒ <code>boolean</code>
|
|
145
145
|
* [.close](#Twig+close)
|
|
146
|
+
* [.debug](#Twig+debug) ⇒ <code>string</code>
|
|
146
147
|
* [.addChild](#Twig+addChild) ℗
|
|
147
148
|
* [.writer](#Twig+writer) ⇒ [<code>XMLWriter</code>](https://www.npmjs.com/package/xml-writer)
|
|
148
149
|
* [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
|
|
@@ -355,6 +356,13 @@ Checks if element is pinned
|
|
|
355
356
|
Closes the element
|
|
356
357
|
|
|
357
358
|
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
359
|
+
<a name="Twig+debug"></a>
|
|
360
|
+
|
|
361
|
+
### twig.debug ⇒ <code>string</code>
|
|
362
|
+
XML-Twig for dummies :-)
|
|
363
|
+
|
|
364
|
+
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
365
|
+
**Returns**: <code>string</code> - The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
358
366
|
<a name="Twig+addChild"></a>
|
|
359
367
|
|
|
360
368
|
### twig.addChild ℗
|
|
@@ -752,6 +760,7 @@ Common function to filter Twig element
|
|
|
752
760
|
* [.pin](#Twig+pin)
|
|
753
761
|
* [.pinned](#Twig+pinned) ⇒ <code>boolean</code>
|
|
754
762
|
* [.close](#Twig+close)
|
|
763
|
+
* [.debug](#Twig+debug) ⇒ <code>string</code>
|
|
755
764
|
* [.addChild](#Twig+addChild) ℗
|
|
756
765
|
* [.writer](#Twig+writer) ⇒ [<code>XMLWriter</code>](https://www.npmjs.com/package/xml-writer)
|
|
757
766
|
* [.attr](#Twig+attr) ⇒ <code>string</code> \| <code>number</code> \| <code>object</code>
|
|
@@ -964,6 +973,13 @@ Checks if element is pinned
|
|
|
964
973
|
Closes the element
|
|
965
974
|
|
|
966
975
|
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
976
|
+
<a name="Twig+debug"></a>
|
|
977
|
+
|
|
978
|
+
### twig.debug ⇒ <code>string</code>
|
|
979
|
+
XML-Twig for dummies :-)
|
|
980
|
+
|
|
981
|
+
**Kind**: instance property of [<code>Twig</code>](#Twig)
|
|
982
|
+
**Returns**: <code>string</code> - The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
967
983
|
<a name="Twig+addChild"></a>
|
|
968
984
|
|
|
969
985
|
### twig.addChild ℗
|
package/package.json
CHANGED
package/twig.js
CHANGED
|
@@ -483,6 +483,7 @@ function reset() {
|
|
|
483
483
|
current = undefined;
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
+
let closeXMLWriterElement = true;
|
|
486
487
|
|
|
487
488
|
/**
|
|
488
489
|
* Generic class modeling a XML Node
|
|
@@ -760,21 +761,30 @@ class Twig {
|
|
|
760
761
|
Object.seal(this);
|
|
761
762
|
};
|
|
762
763
|
|
|
764
|
+
/**
|
|
765
|
+
* XML-Twig for dummies :-)
|
|
766
|
+
* @returns {string} The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
767
|
+
*/
|
|
768
|
+
debug = function () {
|
|
769
|
+
return this.root().writer(true, this).output;
|
|
770
|
+
};
|
|
771
|
+
|
|
763
772
|
/**
|
|
764
773
|
* Internal recursive function used by `writer()`
|
|
765
774
|
* @param {external:XMLWriter} xw - The writer object
|
|
766
775
|
* @param {Twig[]} childArray - Array of child elements
|
|
767
776
|
*/
|
|
768
|
-
#addChild = function (xw, childArray) {
|
|
777
|
+
#addChild = function (xw, childArray, startElement) {
|
|
769
778
|
for (let elt of childArray) {
|
|
770
779
|
xw.startElement(elt.name);
|
|
771
780
|
for (let [key, val] of Object.entries(elt.attributes))
|
|
772
781
|
xw.writeAttribute(key, val);
|
|
773
782
|
if (elt.text !== null)
|
|
774
783
|
xw.text(elt.text);
|
|
775
|
-
this.#addChild(xw, elt.children());
|
|
784
|
+
this.#addChild(xw, elt.children(), startElement);
|
|
785
|
+
if (elt === startElement) closeXMLWriterElement = false;
|
|
776
786
|
}
|
|
777
|
-
xw.endElement();
|
|
787
|
+
if (closeXMLWriterElement) xw.endElement();
|
|
778
788
|
};
|
|
779
789
|
|
|
780
790
|
/**
|
|
@@ -782,17 +792,18 @@ class Twig {
|
|
|
782
792
|
* @param {?boolean|string|external:XMLWriter} par - `true` or intention character or an already created XMLWriter
|
|
783
793
|
* @returns {external:XMLWriter}
|
|
784
794
|
*/
|
|
785
|
-
writer = function (par) {
|
|
795
|
+
writer = function (par, startElement) {
|
|
786
796
|
const XMLWriter = require('xml-writer');
|
|
787
797
|
let xw = par instanceof XMLWriter ? par : new XMLWriter(par);
|
|
798
|
+
closeXMLWriterElement = true
|
|
788
799
|
|
|
789
800
|
xw.startElement(this.#name);
|
|
790
801
|
for (let [key, val] of Object.entries(this.#attributes))
|
|
791
802
|
xw.writeAttribute(key, val);
|
|
792
803
|
if (this.#text !== null)
|
|
793
804
|
xw.text(this.#text);
|
|
794
|
-
this.#addChild(xw, this.#children);
|
|
795
|
-
xw.endElement();
|
|
805
|
+
this.#addChild(xw, this.#children, startElement);
|
|
806
|
+
if (closeXMLWriterElement) xw.endElement();
|
|
796
807
|
return xw;
|
|
797
808
|
};
|
|
798
809
|
|