XMLWriterBase.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Generated by CoffeeScript 1.10.0
  2. (function() {
  3. var XMLWriterBase,
  4. hasProp = {}.hasOwnProperty;
  5. module.exports = XMLWriterBase = (function() {
  6. function XMLWriterBase(options) {
  7. var key, ref, ref1, ref2, ref3, ref4, value;
  8. options || (options = {});
  9. this.pretty = options.pretty || false;
  10. this.allowEmpty = (ref = options.allowEmpty) != null ? ref : false;
  11. if (this.pretty) {
  12. this.indent = (ref1 = options.indent) != null ? ref1 : ' ';
  13. this.newline = (ref2 = options.newline) != null ? ref2 : '\n';
  14. this.offset = (ref3 = options.offset) != null ? ref3 : 0;
  15. } else {
  16. this.indent = '';
  17. this.newline = '';
  18. this.offset = 0;
  19. }
  20. ref4 = options.writer || {};
  21. for (key in ref4) {
  22. if (!hasProp.call(ref4, key)) continue;
  23. value = ref4[key];
  24. this[key] = value;
  25. }
  26. }
  27. XMLWriterBase.prototype.set = function(options) {
  28. var key, ref, value;
  29. options || (options = {});
  30. if ("pretty" in options) {
  31. this.pretty = options.pretty;
  32. }
  33. if ("allowEmpty" in options) {
  34. this.allowEmpty = options.allowEmpty;
  35. }
  36. if (this.pretty) {
  37. this.indent = "indent" in options ? options.indent : ' ';
  38. this.newline = "newline" in options ? options.newline : '\n';
  39. this.offset = "offset" in options ? options.offset : 0;
  40. } else {
  41. this.indent = '';
  42. this.newline = '';
  43. this.offset = 0;
  44. }
  45. ref = options.writer || {};
  46. for (key in ref) {
  47. if (!hasProp.call(ref, key)) continue;
  48. value = ref[key];
  49. this[key] = value;
  50. }
  51. return this;
  52. };
  53. XMLWriterBase.prototype.space = function(level) {
  54. if (this.pretty) {
  55. return new Array((level || 0) + this.offset + 1).join(this.indent);
  56. } else {
  57. return '';
  58. }
  59. };
  60. return XMLWriterBase;
  61. })();
  62. }).call(this);