XMLWriterBase.js
 1  // Generated by CoffeeScript 1.12.7
 2  (function() {
 3    var XMLWriterBase,
 4      hasProp = {}.hasOwnProperty;
 5  
 6    module.exports = XMLWriterBase = (function() {
 7      function XMLWriterBase(options) {
 8        var key, ref, ref1, ref2, ref3, ref4, ref5, ref6, value;
 9        options || (options = {});
10        this.pretty = options.pretty || false;
11        this.allowEmpty = (ref = options.allowEmpty) != null ? ref : false;
12        if (this.pretty) {
13          this.indent = (ref1 = options.indent) != null ? ref1 : '  ';
14          this.newline = (ref2 = options.newline) != null ? ref2 : '\n';
15          this.offset = (ref3 = options.offset) != null ? ref3 : 0;
16          this.dontprettytextnodes = (ref4 = options.dontprettytextnodes) != null ? ref4 : 0;
17        } else {
18          this.indent = '';
19          this.newline = '';
20          this.offset = 0;
21          this.dontprettytextnodes = 0;
22        }
23        this.spacebeforeslash = (ref5 = options.spacebeforeslash) != null ? ref5 : '';
24        if (this.spacebeforeslash === true) {
25          this.spacebeforeslash = ' ';
26        }
27        this.newlinedefault = this.newline;
28        this.prettydefault = this.pretty;
29        ref6 = options.writer || {};
30        for (key in ref6) {
31          if (!hasProp.call(ref6, key)) continue;
32          value = ref6[key];
33          this[key] = value;
34        }
35      }
36  
37      XMLWriterBase.prototype.set = function(options) {
38        var key, ref, value;
39        options || (options = {});
40        if ("pretty" in options) {
41          this.pretty = options.pretty;
42        }
43        if ("allowEmpty" in options) {
44          this.allowEmpty = options.allowEmpty;
45        }
46        if (this.pretty) {
47          this.indent = "indent" in options ? options.indent : '  ';
48          this.newline = "newline" in options ? options.newline : '\n';
49          this.offset = "offset" in options ? options.offset : 0;
50          this.dontprettytextnodes = "dontprettytextnodes" in options ? options.dontprettytextnodes : 0;
51        } else {
52          this.indent = '';
53          this.newline = '';
54          this.offset = 0;
55          this.dontprettytextnodes = 0;
56        }
57        this.spacebeforeslash = "spacebeforeslash" in options ? options.spacebeforeslash : '';
58        if (this.spacebeforeslash === true) {
59          this.spacebeforeslash = ' ';
60        }
61        this.newlinedefault = this.newline;
62        this.prettydefault = this.pretty;
63        ref = options.writer || {};
64        for (key in ref) {
65          if (!hasProp.call(ref, key)) continue;
66          value = ref[key];
67          this[key] = value;
68        }
69        return this;
70      };
71  
72      XMLWriterBase.prototype.space = function(level) {
73        var indent;
74        if (this.pretty) {
75          indent = (level || 0) + this.offset + 1;
76          if (indent > 0) {
77            return new Array(indent).join(this.indent);
78          } else {
79            return '';
80          }
81        } else {
82          return '';
83        }
84      };
85  
86      return XMLWriterBase;
87  
88    })();
89  
90  }).call(this);