@kosatyi/ejs 0.0.96 → 0.0.98

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.
@@ -4,6 +4,14 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejs = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
+ function _assertClassBrand(e, t, n) {
8
+ if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
9
+ throw new TypeError("Private element is not present on this object");
10
+ }
11
+ function _assertThisInitialized(e) {
12
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
+ return e;
14
+ }
7
15
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
8
16
  try {
9
17
  var i = n[a](c),
@@ -29,6 +37,45 @@
29
37
  });
30
38
  };
31
39
  }
40
+ function _callSuper(t, o, e) {
41
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
42
+ }
43
+ function _checkPrivateRedeclaration(e, t) {
44
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
45
+ }
46
+ function _classCallCheck(a, n) {
47
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
48
+ }
49
+ function _classPrivateFieldGet2(s, a) {
50
+ return s.get(_assertClassBrand(s, a));
51
+ }
52
+ function _classPrivateFieldInitSpec(e, t, a) {
53
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
54
+ }
55
+ function _classPrivateFieldSet2(s, a, r) {
56
+ return s.set(_assertClassBrand(s, a), r), r;
57
+ }
58
+ function _classPrivateMethodInitSpec(e, a) {
59
+ _checkPrivateRedeclaration(e, a), a.add(e);
60
+ }
61
+ function _construct(t, e, r) {
62
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
63
+ var o = [null];
64
+ o.push.apply(o, e);
65
+ var p = new (t.bind.apply(t, o))();
66
+ return r && _setPrototypeOf(p, r.prototype), p;
67
+ }
68
+ function _defineProperties(e, r) {
69
+ for (var t = 0; t < r.length; t++) {
70
+ var o = r[t];
71
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
72
+ }
73
+ }
74
+ function _createClass(e, r, t) {
75
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
76
+ writable: !1
77
+ }), e;
78
+ }
32
79
  function _defineProperty(e, r, t) {
33
80
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
34
81
  value: t,
@@ -37,6 +84,43 @@
37
84
  writable: !0
38
85
  }) : e[r] = t, e;
39
86
  }
87
+ function _getPrototypeOf(t) {
88
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
89
+ return t.__proto__ || Object.getPrototypeOf(t);
90
+ }, _getPrototypeOf(t);
91
+ }
92
+ function _inherits(t, e) {
93
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
94
+ t.prototype = Object.create(e && e.prototype, {
95
+ constructor: {
96
+ value: t,
97
+ writable: !0,
98
+ configurable: !0
99
+ }
100
+ }), Object.defineProperty(t, "prototype", {
101
+ writable: !1
102
+ }), e && _setPrototypeOf(t, e);
103
+ }
104
+ function _isNativeFunction(t) {
105
+ try {
106
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
107
+ } catch (n) {
108
+ return "function" == typeof t;
109
+ }
110
+ }
111
+ function _isNativeReflectConstruct() {
112
+ try {
113
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
114
+ } catch (t) {}
115
+ return (_isNativeReflectConstruct = function () {
116
+ return !!t;
117
+ })();
118
+ }
119
+ function _possibleConstructorReturn(t, e) {
120
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
121
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
122
+ return _assertThisInitialized(t);
123
+ }
40
124
  function _regeneratorRuntime() {
41
125
  _regeneratorRuntime = function () {
42
126
  return e;
@@ -338,20 +422,47 @@
338
422
  }
339
423
  }, e;
340
424
  }
425
+ function _setPrototypeOf(t, e) {
426
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
427
+ return t.__proto__ = e, t;
428
+ }, _setPrototypeOf(t, e);
429
+ }
341
430
  function _toPrimitive(t, r) {
342
431
  if ("object" != typeof t || !t) return t;
343
432
  var e = t[Symbol.toPrimitive];
344
433
  if (void 0 !== e) {
345
- var i = e.call(t, r || "default");
434
+ var i = e.call(t, r);
346
435
  if ("object" != typeof i) return i;
347
436
  throw new TypeError("@@toPrimitive must return a primitive value.");
348
437
  }
349
- return ("string" === r ? String : Number)(t);
438
+ return (String )(t);
350
439
  }
351
440
  function _toPropertyKey(t) {
352
441
  var i = _toPrimitive(t, "string");
353
442
  return "symbol" == typeof i ? i : i + "";
354
443
  }
444
+ function _wrapNativeSuper(t) {
445
+ var r = "function" == typeof Map ? new Map() : void 0;
446
+ return _wrapNativeSuper = function (t) {
447
+ if (null === t || !_isNativeFunction(t)) return t;
448
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
449
+ if (void 0 !== r) {
450
+ if (r.has(t)) return r.get(t);
451
+ r.set(t, Wrapper);
452
+ }
453
+ function Wrapper() {
454
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
455
+ }
456
+ return Wrapper.prototype = Object.create(t.prototype, {
457
+ constructor: {
458
+ value: Wrapper,
459
+ enumerable: !1,
460
+ writable: !0,
461
+ configurable: !0
462
+ }
463
+ }), _setPrototypeOf(Wrapper, t);
464
+ }, _wrapNativeSuper(t);
465
+ }
355
466
 
356
467
  var typeProp = function typeProp() {
357
468
  var args = [].slice.call(arguments);
@@ -417,6 +528,9 @@
417
528
  var instanceOf = function instanceOf(object, instance) {
418
529
  return Boolean(object instanceof instance);
419
530
  };
531
+ var assertInstanceOf = function assertInstanceOf(object, instance) {
532
+ if (instanceOf(object, instance) === false) throw new TypeError("".concat(object, " in not instance of ").concat(instance));
533
+ };
420
534
  var getPath = function getPath(context, name, strict) {
421
535
  var data = context;
422
536
  var chunks = String(name).split('.');
@@ -437,6 +551,14 @@
437
551
  }
438
552
  return [data, prop];
439
553
  };
554
+ var bindContext = function bindContext(object) {
555
+ var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
556
+ methods.forEach(function (name) {
557
+ if (name in object) {
558
+ object[name] = object[name].bind(object);
559
+ }
560
+ });
561
+ };
440
562
  var ext = function ext(path, defaults) {
441
563
  var ext = path.split('.').pop();
442
564
  if (ext !== defaults) {
@@ -499,9 +621,27 @@
499
621
  }
500
622
  });
501
623
  };
624
+
625
+ /**
626
+ *
627
+ * @param object
628
+ * @param prop
629
+ * @return {boolean}
630
+ */
502
631
  var hasProp = function hasProp(object, prop) {
503
632
  return object && object.hasOwnProperty(prop);
504
633
  };
634
+ var matchTokens = function matchTokens(regex, text, callback) {
635
+ var index = 0;
636
+ text.replace(regex, function () {
637
+ var params = [].slice.call(arguments, 0, -1);
638
+ var offset = params.pop();
639
+ var match = params.shift();
640
+ callback(params, index, offset);
641
+ index = offset + match.length;
642
+ return match;
643
+ });
644
+ };
505
645
 
506
646
  var defaults = {};
507
647
  defaults["export"] = 'ejsPrecompiled';
@@ -547,183 +687,221 @@
547
687
  };
548
688
 
549
689
  var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
550
- function Cache(config) {
551
- if (instanceOf(this, Cache) === false) return new Cache();
552
- var cache = {
553
- enabled: true,
554
- list: {}
555
- };
556
- this.configure = function (config) {
557
- cache.enabled = config.cache;
558
- if (isNode() === false) {
559
- this.load(global[config["export"]]);
690
+ var _enabled = /*#__PURE__*/new WeakMap();
691
+ var _list = /*#__PURE__*/new WeakMap();
692
+ var Cache = /*#__PURE__*/function () {
693
+ function Cache(config) {
694
+ _classCallCheck(this, Cache);
695
+ _classPrivateFieldInitSpec(this, _enabled, true);
696
+ _classPrivateFieldInitSpec(this, _list, {});
697
+ bindContext(this, ['configure']);
698
+ this.configure(config);
699
+ }
700
+ return _createClass(Cache, [{
701
+ key: "load",
702
+ value: function load(data) {
703
+ if (_classPrivateFieldGet2(_enabled, this)) {
704
+ extend(_classPrivateFieldGet2(_list, this), data || {});
705
+ }
560
706
  }
561
- };
562
- this.clear = function () {
563
- cache.list = {};
564
- };
565
- this.load = function (data) {
566
- if (cache.enabled) {
567
- extend(cache.list, data || {});
707
+ }, {
708
+ key: "get",
709
+ value: function get(key) {
710
+ if (_classPrivateFieldGet2(_enabled, this)) {
711
+ return _classPrivateFieldGet2(_list, this)[key];
712
+ }
568
713
  }
569
- return this;
570
- };
571
- this.get = function (key) {
572
- if (cache.enabled) {
573
- return cache.list[key];
714
+ }, {
715
+ key: "set",
716
+ value: function set(key, value) {
717
+ if (_classPrivateFieldGet2(_enabled, this)) {
718
+ _classPrivateFieldGet2(_list, this)[key] = value;
719
+ }
574
720
  }
575
- };
576
- this.set = function (key, value) {
577
- if (cache.enabled) {
578
- cache.list[key] = value;
721
+ }, {
722
+ key: "exist",
723
+ value: function exist(key) {
724
+ return hasProp(_classPrivateFieldGet2(_list, this), key);
579
725
  }
580
- return this;
581
- };
582
- this.resolve = function (key) {
583
- return Promise.resolve(this.get(key));
584
- };
585
- this.remove = function (key) {
586
- delete cache.list[key];
587
- };
588
- this.exist = function (key) {
589
- return hasProp(cache.list, key);
590
- };
591
- }
726
+ }, {
727
+ key: "clear",
728
+ value: function clear() {
729
+ _classPrivateFieldSet2(_list, this, {});
730
+ }
731
+ }, {
732
+ key: "remove",
733
+ value: function remove(key) {
734
+ delete _classPrivateFieldGet2(_list, this)[key];
735
+ }
736
+ }, {
737
+ key: "resolve",
738
+ value: function resolve(key) {
739
+ return Promise.resolve(this.get(key));
740
+ }
741
+ }, {
742
+ key: "configure",
743
+ value: function configure(config) {
744
+ _classPrivateFieldSet2(_enabled, this, config.cache);
745
+ if (isNode() === false) {
746
+ this.load(global[config["export"]]);
747
+ }
748
+ }
749
+ }]);
750
+ }();
592
751
 
593
- var tagList = [{
594
- symbol: '-',
595
- format: function format(value) {
596
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
597
- }
598
- }, {
599
- symbol: '=',
600
- format: function format(value) {
601
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
602
- }
603
- }, {
604
- symbol: '#',
605
- format: function format(value) {
606
- return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
607
- }
608
- }, {
609
- symbol: '',
610
- format: function format(value) {
611
- return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
752
+ var _config$1 = /*#__PURE__*/new WeakMap();
753
+ var _symbols = /*#__PURE__*/new WeakMap();
754
+ var Compiler = /*#__PURE__*/function () {
755
+ function Compiler(config) {
756
+ _classCallCheck(this, Compiler);
757
+ _classPrivateFieldInitSpec(this, _config$1, {});
758
+ _classPrivateFieldInitSpec(this, _symbols, [{
759
+ symbol: '-',
760
+ format: function format(value) {
761
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
762
+ }
763
+ }, {
764
+ symbol: '=',
765
+ format: function format(value) {
766
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
767
+ }
768
+ }, {
769
+ symbol: '#',
770
+ format: function format(value) {
771
+ return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
772
+ }
773
+ }, {
774
+ symbol: '',
775
+ format: function format(value) {
776
+ return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
777
+ }
778
+ }]);
779
+ bindContext(this, ['configure', 'compile']);
780
+ this.configure(config);
612
781
  }
613
- }];
614
- function matchTokens(regex, text, callback) {
615
- var index = 0;
616
- text.replace(regex, function () {
617
- var params = [].slice.call(arguments, 0, -1);
618
- var offset = params.pop();
619
- var match = params.shift();
620
- callback(params, index, offset);
621
- index = offset + match.length;
622
- return match;
623
- });
624
- }
625
- function Compiler(config) {
626
- if (instanceOf(this, Compiler) === false) return new Compiler(config);
627
- var compiler = {};
628
- this.configure = function (config) {
629
- compiler.withObject = config.withObject;
630
- compiler.rmWhitespace = config.rmWhitespace;
631
- compiler.token = config.token;
632
- compiler.vars = config.vars;
633
- compiler.globalHelpers = config.globalHelpers;
634
- compiler.matches = [];
635
- compiler.formats = [];
636
- compiler.slurp = {
637
- match: '[\s\t\n]*',
638
- start: [compiler.token.start, '_'],
639
- end: ['_', compiler.token.end]
640
- };
641
- tagList.forEach(function (item) {
642
- compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
643
- compiler.formats.push(item.format.bind(compiler.vars));
644
- });
645
- compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
646
- compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
647
- compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
648
- };
649
- this.compile = function (content, path) {
650
- var _compiler$vars = compiler.vars,
651
- SCOPE = _compiler$vars.SCOPE,
652
- SAFE = _compiler$vars.SAFE,
653
- BUFFER = _compiler$vars.BUFFER,
654
- COMPONENT = _compiler$vars.COMPONENT;
655
- var GLOBALS = compiler.globalHelpers;
656
- content = String(content);
657
- if (compiler.rmWhitespace) {
658
- content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
659
- }
660
- content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
661
- var source = "".concat(BUFFER, "('");
662
- matchTokens(compiler.regex, content, function (params, index, offset) {
663
- source += symbols(content.slice(index, offset));
664
- params.forEach(function (value, index) {
665
- if (value) {
666
- source += compiler.formats[index](value);
667
- }
782
+ return _createClass(Compiler, [{
783
+ key: "configure",
784
+ value: function configure(config) {
785
+ var _this = this;
786
+ _classPrivateFieldGet2(_config$1, this).withObject = config.withObject;
787
+ _classPrivateFieldGet2(_config$1, this).rmWhitespace = config.rmWhitespace;
788
+ _classPrivateFieldGet2(_config$1, this).token = config.token;
789
+ _classPrivateFieldGet2(_config$1, this).vars = config.vars;
790
+ _classPrivateFieldGet2(_config$1, this).globalHelpers = config.globalHelpers;
791
+ _classPrivateFieldGet2(_config$1, this).matches = [];
792
+ _classPrivateFieldGet2(_config$1, this).formats = [];
793
+ _classPrivateFieldGet2(_config$1, this).slurp = {
794
+ match: '[s\t\n]*',
795
+ start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
796
+ end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
797
+ };
798
+ _classPrivateFieldGet2(_symbols, this).forEach(function (item) {
799
+ _classPrivateFieldGet2(_config$1, _this).matches.push(_classPrivateFieldGet2(_config$1, _this).token.start.concat(item.symbol).concat(_classPrivateFieldGet2(_config$1, _this).token.regex).concat(_classPrivateFieldGet2(_config$1, _this).token.end));
800
+ _classPrivateFieldGet2(_config$1, _this).formats.push(item.format.bind(_classPrivateFieldGet2(_config$1, _this).vars));
668
801
  });
669
- });
670
- source += "');";
671
- source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
672
- if (compiler.withObject) {
673
- source = "with(".concat(SCOPE, "){").concat(source, "}");
674
- }
675
- source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
676
- source += "\n//# sourceURL=".concat(path);
677
- var result = null;
678
- var params = [SCOPE, COMPONENT, BUFFER, SAFE].concat(GLOBALS);
679
- try {
680
- result = Function.apply(null, params.concat(source));
681
- result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
682
- } catch (e) {
683
- e.filename = path;
684
- e.source = source;
685
- throw e;
686
- }
687
- return result;
688
- };
689
- this.configure(config);
690
- }
691
-
692
- function Template(config, cache, compiler) {
693
- if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
694
- if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
695
- if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
696
- var template = {};
697
- var result = function result(template, content) {
698
- cache.set(template, content);
699
- return content;
700
- };
701
- var resolve = function resolve(path) {
702
- return template.resolver(template.path, path);
703
- };
704
- var compile = function compile(content, template) {
705
- if (isFunction(content)) {
706
- return content;
707
- } else {
708
- return compiler.compile(content, template);
802
+ _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
803
+ _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
804
+ _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
709
805
  }
710
- };
711
- this.configure = function (config) {
712
- template.path = config.path;
713
- template.cache = config.cache;
714
- if (isFunction(config.resolver)) {
715
- template.resolver = config.resolver;
806
+ }, {
807
+ key: "compile",
808
+ value: function compile(content, path) {
809
+ var _this2 = this;
810
+ var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config$1, this).vars,
811
+ SCOPE = _classPrivateFieldGet2$1.SCOPE,
812
+ SAFE = _classPrivateFieldGet2$1.SAFE,
813
+ BUFFER = _classPrivateFieldGet2$1.BUFFER,
814
+ COMPONENT = _classPrivateFieldGet2$1.COMPONENT;
815
+ var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
816
+ if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
817
+ content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
818
+ }
819
+ content = String(content).replace(_classPrivateFieldGet2(_config$1, this).slurpStart, _classPrivateFieldGet2(_config$1, this).token.start).replace(_classPrivateFieldGet2(_config$1, this).slurpEnd, _classPrivateFieldGet2(_config$1, this).token.end);
820
+ var source = "".concat(BUFFER, "('");
821
+ matchTokens(_classPrivateFieldGet2(_config$1, this).regex, content, function (params, index, offset) {
822
+ source += symbols(content.slice(index, offset));
823
+ params.forEach(function (value, index) {
824
+ if (value) {
825
+ source += _classPrivateFieldGet2(_config$1, _this2).formats[index](value);
826
+ }
827
+ });
828
+ });
829
+ source += "');";
830
+ source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
831
+ if (_classPrivateFieldGet2(_config$1, this).withObject) {
832
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
833
+ }
834
+ source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
835
+ source += "\n//# sourceURL=".concat(path);
836
+ var result = null;
837
+ var params = [SCOPE, COMPONENT, BUFFER, SAFE].concat(GLOBALS);
838
+ try {
839
+ result = Function.apply(null, params.concat(source));
840
+ result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
841
+ } catch (e) {
842
+ e.filename = path;
843
+ e.source = source;
844
+ throw e;
845
+ }
846
+ return result;
716
847
  }
717
- };
718
- this.get = function (template) {
719
- if (cache.exist(template)) {
720
- return cache.resolve(template);
848
+ }]);
849
+ }();
850
+
851
+ var _path = /*#__PURE__*/new WeakMap();
852
+ var _cache$1 = /*#__PURE__*/new WeakMap();
853
+ var _compiler$1 = /*#__PURE__*/new WeakMap();
854
+ var _resolver = /*#__PURE__*/new WeakMap();
855
+ var _Template_brand = /*#__PURE__*/new WeakSet();
856
+ var Template = /*#__PURE__*/function () {
857
+ function Template(config, cache, compiler) {
858
+ _classCallCheck(this, Template);
859
+ _classPrivateMethodInitSpec(this, _Template_brand);
860
+ _classPrivateFieldInitSpec(this, _path, void 0);
861
+ _classPrivateFieldInitSpec(this, _cache$1, void 0);
862
+ _classPrivateFieldInitSpec(this, _compiler$1, void 0);
863
+ _classPrivateFieldInitSpec(this, _resolver, void 0);
864
+ assertInstanceOf(cache, Cache);
865
+ assertInstanceOf(compiler, Compiler);
866
+ _classPrivateFieldSet2(_cache$1, this, cache);
867
+ _classPrivateFieldSet2(_compiler$1, this, compiler);
868
+ bindContext(this, ['configure', 'get']);
869
+ this.configure(config);
870
+ }
871
+ return _createClass(Template, [{
872
+ key: "configure",
873
+ value: function configure(config) {
874
+ _classPrivateFieldSet2(_path, this, config.path);
875
+ if (isFunction(config.resolver)) {
876
+ _classPrivateFieldSet2(_resolver, this, config.resolver);
877
+ }
721
878
  }
722
- return resolve(template).then(function (content) {
723
- return result(template, compile(content, template));
724
- });
725
- };
726
- this.configure(config);
879
+ }, {
880
+ key: "get",
881
+ value: function get(template) {
882
+ var _this = this;
883
+ if (_classPrivateFieldGet2(_cache$1, this).exist(template)) {
884
+ return _classPrivateFieldGet2(_cache$1, this).resolve(template);
885
+ }
886
+ return _assertClassBrand(_Template_brand, this, _resolve).call(this, template).then(function (content) {
887
+ return _assertClassBrand(_Template_brand, _this, _result).call(_this, template, _assertClassBrand(_Template_brand, _this, _compile).call(_this, content, template));
888
+ });
889
+ }
890
+ }]);
891
+ }();
892
+ function _resolve(path) {
893
+ return _classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path, this), path);
894
+ }
895
+ function _result(template, content) {
896
+ _classPrivateFieldGet2(_cache$1, this).set(template, content);
897
+ return content;
898
+ }
899
+ function _compile(content, template) {
900
+ if (isFunction(content)) {
901
+ return content;
902
+ } else {
903
+ return _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
904
+ }
727
905
  }
728
906
 
729
907
  var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
@@ -742,7 +920,7 @@
742
920
  }
743
921
  }).join(space);
744
922
  result.push([lt, tag, space, attributes, gt].join(''));
745
- if (content) {
923
+ if (content && hasClosedTag) {
746
924
  result.push(content instanceof Array ? content.join('') : content);
747
925
  }
748
926
  if (hasClosedTag) {
@@ -751,82 +929,61 @@
751
929
  return result.join('');
752
930
  };
753
931
 
754
- /**
755
- * @extends Error
756
- * @property code
757
- * @param {string} message
758
- * @constructor
759
- */
760
- function TemplateError(message) {
761
- this.name = 'TemplateError';
762
- this.message = message;
763
- Error.call(this);
764
- }
765
-
766
- /**
767
- *
768
- */
769
- Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
770
- Object.assign(TemplateError.prototype, {
771
- code: 1
772
- });
773
- /**
774
- *
775
- * @return {number}
776
- */
777
- TemplateError.prototype.getCode = function () {
778
- return this.code;
779
- };
780
- /**
781
- *
782
- * @return {string}
783
- */
784
- TemplateError.prototype.getMessage = function () {
785
- return this.message;
786
- };
787
- /**
788
- * @return {string}
789
- */
790
- TemplateError.prototype.toString = function () {
791
- return this.getMessage();
792
- };
793
-
794
- /**
795
- * @extends TemplateError
796
- * @param {string} message
797
- * @constructor
798
- */
799
- function TemplateNotFound(message) {
800
- TemplateError.call(this);
801
- this.name = 'TemplateNotFound';
802
- this.message = message;
803
- }
804
-
805
- /**
806
- *
807
- */
808
- Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
809
- Object.assign(TemplateNotFound.prototype, {
810
- code: 404
811
- });
812
- /**
813
- * @extends TemplateError
814
- * @param {string} message
815
- * @constructor
816
- */
817
- function TemplateSyntaxError(message) {
818
- TemplateError.call(this);
819
- this.name = 'TemplateSyntaxError';
820
- this.message = message;
821
- }
822
-
823
- /**
824
- *
825
- */
826
- Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
827
- Object.assign(TemplateSyntaxError.prototype, {
828
- code: 500
829
- });
932
+ var TemplateError = /*#__PURE__*/function (_Error) {
933
+ function TemplateError(message) {
934
+ var _this;
935
+ _classCallCheck(this, TemplateError);
936
+ _this = _callSuper(this, TemplateError);
937
+ _defineProperty(_this, "code", 0);
938
+ _this.message = message;
939
+ return _this;
940
+ }
941
+ _inherits(TemplateError, _Error);
942
+ return _createClass(TemplateError, [{
943
+ key: "getCode",
944
+ value: function getCode() {
945
+ return this.code;
946
+ }
947
+ }, {
948
+ key: "getMessage",
949
+ value: function getMessage() {
950
+ return this.message;
951
+ }
952
+ }, {
953
+ key: "toString",
954
+ value: function toString() {
955
+ return this.getMessage();
956
+ }
957
+ }]);
958
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
959
+ var TemplateNotFound = /*#__PURE__*/function (_TemplateError2) {
960
+ function TemplateNotFound() {
961
+ var _this2;
962
+ _classCallCheck(this, TemplateNotFound);
963
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
964
+ args[_key] = arguments[_key];
965
+ }
966
+ _this2 = _callSuper(this, TemplateNotFound, [].concat(args));
967
+ _defineProperty(_this2, "code", 404);
968
+ return _this2;
969
+ }
970
+ _inherits(TemplateNotFound, _TemplateError2);
971
+ return _createClass(TemplateNotFound);
972
+ }(TemplateError);
973
+ var TemplateSyntaxError = /*#__PURE__*/function (_TemplateError3) {
974
+ function TemplateSyntaxError() {
975
+ var _this3;
976
+ _classCallCheck(this, TemplateSyntaxError);
977
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
978
+ args[_key2] = arguments[_key2];
979
+ }
980
+ _this3 = _callSuper(this, TemplateSyntaxError, [].concat(args));
981
+ _defineProperty(_this3, "code", 500);
982
+ return _this3;
983
+ }
984
+ _inherits(TemplateSyntaxError, _TemplateError3);
985
+ return _createClass(TemplateSyntaxError);
986
+ }(TemplateError);
830
987
 
831
988
  function resolve(list) {
832
989
  return Promise.all(list || []).then(function (list) {
@@ -838,12 +995,17 @@
838
995
  function reject(error) {
839
996
  return Promise.reject(new TemplateSyntaxError(error.message));
840
997
  }
998
+
999
+ /**
1000
+ *
1001
+ * @return {buffer}
1002
+ */
841
1003
  function createBuffer() {
842
1004
  var store = [],
843
1005
  array = [];
844
- function buffer(value) {
1006
+ var buffer = function buffer(value) {
845
1007
  array.push(value);
846
- }
1008
+ };
847
1009
  buffer.start = function () {
848
1010
  array = [];
849
1011
  };
@@ -865,420 +1027,531 @@
865
1027
  return buffer;
866
1028
  }
867
1029
 
868
- function Context(config) {
869
- if (instanceOf(this, Context) === false) return new Context(config);
870
- this.configure = function (config, methods) {
871
- var _Object$definePropert;
872
- var _config$vars = config.vars,
873
- BLOCKS = _config$vars.BLOCKS,
874
- MACRO = _config$vars.MACRO,
875
- EXTEND = _config$vars.EXTEND,
876
- LAYOUT = _config$vars.LAYOUT,
877
- BUFFER = _config$vars.BUFFER,
878
- COMPONENT = _config$vars.COMPONENT;
879
- this.create = function (data) {
880
- return new Scope(data);
881
- };
882
- this.helpers = function (methods) {
883
- extend(Scope.prototype, methods || {});
884
- };
885
- /**
886
- * @name ContextScope
887
- * @param data
888
- * @constructor
889
- */
890
- function Scope(data) {
891
- this[BLOCKS] = {};
892
- this[MACRO] = {};
893
- extend(this, data || {});
894
- }
895
- Scope.prototype = extend({}, methods || {});
896
- Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, BUFFER, {
897
- value: createBuffer(),
898
- writable: true,
899
- configurable: false,
900
- enumerable: false
901
- }), BLOCKS, {
902
- value: {},
903
- writable: true,
904
- configurable: false,
905
- enumerable: false
906
- }), MACRO, {
907
- value: {},
908
- writable: true,
909
- configurable: false,
910
- enumerable: false
911
- }), LAYOUT, {
912
- value: false,
913
- writable: true,
914
- configurable: false,
915
- enumerable: false
916
- }), EXTEND, {
917
- value: false,
918
- writable: true,
919
- configurable: false,
920
- enumerable: false
921
- }), "getMacro", {
922
- value: function value() {
923
- return this[MACRO];
924
- },
925
- writable: false,
926
- configurable: false,
927
- enumerable: false
928
- }), "getBuffer", {
929
- value: function value() {
930
- return this[BUFFER];
931
- },
932
- writable: false,
933
- configurable: false,
934
- enumerable: false
935
- }), "getComponent", {
936
- value: function value() {
937
- var context = this;
938
- if (COMPONENT in context) {
939
- return function () {
940
- return context[COMPONENT].apply(context, arguments);
941
- };
942
- }
1030
+ var createScope = function createScope(config, methods) {
1031
+ var _Object$definePropert;
1032
+ var _config$vars = config.vars,
1033
+ BLOCKS = _config$vars.BLOCKS,
1034
+ MACRO = _config$vars.MACRO,
1035
+ EXTEND = _config$vars.EXTEND,
1036
+ LAYOUT = _config$vars.LAYOUT,
1037
+ BUFFER = _config$vars.BUFFER,
1038
+ COMPONENT = _config$vars.COMPONENT,
1039
+ SAFE = _config$vars.SAFE,
1040
+ SCOPE = _config$vars.SCOPE;
1041
+ /**
1042
+ * @name ContextScope
1043
+ * @param data
1044
+ * @constructor
1045
+ */
1046
+ function ContextScope(data) {
1047
+ this[BLOCKS] = {};
1048
+ this[MACRO] = {};
1049
+ Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT]));
1050
+ }
1051
+ Object.assign(ContextScope.prototype, methods);
1052
+ Object.defineProperties(ContextScope.prototype, (_Object$definePropert = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, BUFFER, {
1053
+ value: createBuffer()
1054
+ }), BLOCKS, {
1055
+ value: {},
1056
+ writable: true
1057
+ }), MACRO, {
1058
+ value: {},
1059
+ writable: true
1060
+ }), LAYOUT, {
1061
+ value: false,
1062
+ writable: true
1063
+ }), EXTEND, {
1064
+ value: false,
1065
+ writable: true
1066
+ }), "getMacro", {
1067
+ value: function value() {
1068
+ return this[MACRO];
1069
+ }
1070
+ }), "getBuffer", {
1071
+ value: function value() {
1072
+ return this[BUFFER];
1073
+ }
1074
+ }), "getComponent", {
1075
+ value: function value() {
1076
+ var context = this;
1077
+ if (COMPONENT in context) {
943
1078
  return function () {
944
- console.log('%s function not defined', COMPONENT);
1079
+ return context[COMPONENT].apply(context, arguments);
945
1080
  };
946
- },
947
- writable: false,
948
- configurable: false,
949
- enumerable: false
950
- }), "getBlocks", {
951
- value: function value() {
952
- return this[BLOCKS];
953
- },
954
- writable: false,
955
- configurable: false,
956
- enumerable: false
957
- }), "setExtend", {
958
- value: function value(_value) {
959
- this[EXTEND] = _value;
960
- },
961
- writable: false,
962
- configurable: false,
963
- enumerable: false
964
- }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
965
- value: function value() {
966
- return this[EXTEND];
967
- },
968
- writable: false,
969
- configurable: false,
970
- enumerable: false
971
- }), "setLayout", {
972
- value: function value(layout) {
973
- this[LAYOUT] = layout;
974
- },
975
- writable: false,
976
- configurable: false,
977
- enumerable: false
978
- }), "getLayout", {
979
- value: function value() {
980
- return this[LAYOUT];
981
- },
982
- writable: false,
983
- configurable: false,
984
- enumerable: false
985
- }), "clone", {
986
- value: function value(exclude_blocks) {
987
- var filter = [LAYOUT, EXTEND, BUFFER];
988
- if (exclude_blocks === true) {
989
- filter.push(BLOCKS);
1081
+ }
1082
+ return function () {
1083
+ console.log('%s function not defined', COMPONENT);
1084
+ };
1085
+ }
1086
+ }), "getBlocks", {
1087
+ value: function value() {
1088
+ return this[BLOCKS];
1089
+ }
1090
+ }), "setExtend", {
1091
+ value: function value(_value) {
1092
+ this[EXTEND] = _value;
1093
+ }
1094
+ }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
1095
+ value: function value() {
1096
+ return this[EXTEND];
1097
+ }
1098
+ }), "setLayout", {
1099
+ value: function value(layout) {
1100
+ this[LAYOUT] = layout;
1101
+ }
1102
+ }), "getLayout", {
1103
+ value: function value() {
1104
+ return this[LAYOUT];
1105
+ }
1106
+ }), "clone", {
1107
+ value: function value(exclude_blocks) {
1108
+ var filter = [LAYOUT, EXTEND, BUFFER];
1109
+ if (exclude_blocks === true) {
1110
+ filter.push(BLOCKS);
1111
+ }
1112
+ return omit(this, filter);
1113
+ }
1114
+ }), "extend", {
1115
+ value: function value(layout) {
1116
+ this.setExtend(true);
1117
+ this.setLayout(layout);
1118
+ }
1119
+ }), "echo", {
1120
+ value: function value(layout) {
1121
+ var buffer = this.getBuffer();
1122
+ var params = [].slice.call(arguments);
1123
+ params.forEach(buffer);
1124
+ }
1125
+ }), "fn", {
1126
+ value: function value(callback) {
1127
+ var buffer = this.getBuffer();
1128
+ var context = this;
1129
+ return function () {
1130
+ buffer.backup();
1131
+ if (isFunction(callback)) {
1132
+ callback.apply(context, arguments);
990
1133
  }
991
- return omit(this, filter);
992
- },
993
- writable: false,
994
- configurable: false,
995
- enumerable: false
996
- }), "extend", {
997
- value: function value(layout) {
998
- this.setExtend(true);
999
- this.setLayout(layout);
1000
- },
1001
- writable: false,
1002
- configurable: false,
1003
- enumerable: false
1004
- }), "echo", {
1005
- value: function value(layout) {
1006
- var buffer = this.getBuffer();
1007
- var params = [].slice.call(arguments);
1008
- params.forEach(buffer);
1009
- },
1010
- writable: false,
1011
- configurable: false,
1012
- enumerable: false
1013
- }), "fn", {
1014
- value: function value(callback) {
1015
- var buffer = this.getBuffer();
1016
- var context = this;
1017
- return function () {
1018
- buffer.backup();
1019
- if (isFunction(callback)) {
1020
- callback.apply(context, arguments);
1021
- }
1022
- return buffer.restore();
1023
- };
1024
- },
1025
- writable: false,
1026
- configurable: false,
1027
- enumerable: false
1028
- }), "get", {
1029
- value: function value(name, defaults) {
1030
- var path = getPath(this, name, true);
1031
- var result = path.shift();
1032
- var prop = path.pop();
1033
- return hasProp(result, prop) ? result[prop] : defaults;
1034
- },
1035
- writable: true,
1036
- configurable: true,
1037
- enumerable: false
1038
- }), "set", {
1039
- value: function value(name, _value2) {
1040
- var path = getPath(this, name, false);
1041
- var result = path.shift();
1042
- var prop = path.pop();
1043
- if (this.getExtend() && hasProp(result, prop)) {
1044
- return result[prop];
1134
+ return buffer.restore();
1135
+ };
1136
+ }
1137
+ }), "get", {
1138
+ value: function value(name, defaults) {
1139
+ var path = getPath(this, name, true);
1140
+ var result = path.shift();
1141
+ var prop = path.pop();
1142
+ return hasProp(result, prop) ? result[prop] : defaults;
1143
+ }
1144
+ }), "set", {
1145
+ value: function value(name, _value2) {
1146
+ var path = getPath(this, name, false);
1147
+ var result = path.shift();
1148
+ var prop = path.pop();
1149
+ if (this.getExtend() && hasProp(result, prop)) {
1150
+ return result[prop];
1151
+ }
1152
+ return result[prop] = _value2;
1153
+ }
1154
+ }), "macro", {
1155
+ value: function value(name, callback) {
1156
+ var list = this.getMacro();
1157
+ var macro = this.fn(callback);
1158
+ var context = this;
1159
+ list[name] = function () {
1160
+ return context.echo(macro.apply(undefined, arguments));
1161
+ };
1162
+ }
1163
+ }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "call", {
1164
+ value: function value(name) {
1165
+ var list = this.getMacro();
1166
+ var macro = list[name];
1167
+ var params = [].slice.call(arguments, 1);
1168
+ if (isFunction(macro)) {
1169
+ return macro.apply(macro, params);
1170
+ }
1171
+ }
1172
+ }), "block", {
1173
+ value: function value(name, callback) {
1174
+ var _this = this;
1175
+ var blocks = this.getBlocks();
1176
+ blocks[name] = blocks[name] || [];
1177
+ blocks[name].push(this.fn(callback));
1178
+ if (this.getExtend()) return;
1179
+ var list = Object.assign([], blocks[name]);
1180
+ var current = function current() {
1181
+ return list.shift();
1182
+ };
1183
+ var _next = function next() {
1184
+ var parent = current();
1185
+ if (parent) {
1186
+ return function () {
1187
+ _this.echo(parent(_next()));
1188
+ };
1189
+ } else {
1190
+ return noop;
1045
1191
  }
1046
- return result[prop] = _value2;
1047
- },
1048
- writable: false,
1049
- configurable: false,
1050
- enumerable: false
1051
- }), "macro", {
1052
- value: function value(name, callback) {
1053
- var list = this.getMacro();
1054
- var macro = this.fn(callback);
1055
- var context = this;
1056
- list[name] = function () {
1057
- return context.echo(macro.apply(undefined, arguments));
1058
- };
1059
- },
1060
- writable: false,
1061
- configurable: false,
1062
- enumerable: false
1063
- }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "call", {
1064
- value: function value(name) {
1192
+ };
1193
+ this.echo(current()(_next()));
1194
+ }
1195
+ }), "hasBlock", {
1196
+ value: function value(name) {
1197
+ return this.getBlocks().hasOwnProperty(name);
1198
+ }
1199
+ }), "include", {
1200
+ value: function value(path, data, cx) {
1201
+ var context = cx === false ? {} : this.clone(true);
1202
+ var params = extend(context, data || {});
1203
+ var promise = this.render(path, params);
1204
+ this.echo(promise);
1205
+ }
1206
+ }), "promiseResolve", {
1207
+ value: function value(_value3, callback) {
1208
+ return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
1209
+ }
1210
+ }), "use", {
1211
+ value: function value(path, namespace) {
1212
+ this.echo(this.promiseResolve(this.require(path), function (exports) {
1065
1213
  var list = this.getMacro();
1066
- var macro = list[name];
1067
- var params = [].slice.call(arguments, 1);
1068
- if (isFunction(macro)) {
1069
- return macro.apply(macro, params);
1070
- }
1071
- },
1072
- writable: false,
1073
- configurable: false,
1074
- enumerable: false
1075
- }), "block", {
1076
- value: function value(name, callback) {
1077
- var _this = this;
1078
- var blocks = this.getBlocks();
1079
- blocks[name] = blocks[name] || [];
1080
- blocks[name].push(this.fn(callback));
1081
- if (this.getExtend()) return;
1082
- var list = Object.assign([], blocks[name]);
1083
- var current = function current() {
1084
- return list.shift();
1085
- };
1086
- var _next = function next() {
1087
- var parent = current();
1088
- if (parent) {
1089
- return function () {
1090
- _this.echo(parent(_next()));
1091
- };
1092
- } else {
1093
- return noop;
1094
- }
1095
- };
1096
- this.echo(current()(_next()));
1097
- },
1098
- writable: false,
1099
- configurable: false,
1100
- enumerable: false
1101
- }), "hasBlock", {
1102
- value: function value(name) {
1103
- return this.getBlocks().hasOwnProperty(name);
1104
- },
1105
- writable: false,
1106
- configurable: false,
1107
- enumerable: false
1108
- }), "include", {
1109
- value: function value(path, data, cx) {
1110
- var context = cx === false ? {} : this.clone(true);
1111
- var params = extend(context, data || {});
1112
- var promise = this.render(path, params);
1113
- this.echo(promise);
1114
- },
1115
- writable: false,
1116
- configurable: false,
1117
- enumerable: false
1118
- }), "promiseResolve", {
1119
- value: function value(_value3, callback) {
1120
- return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
1121
- },
1122
- writable: false,
1123
- configurable: false,
1124
- enumerable: false
1125
- }), "use", {
1126
- value: function value(path, namespace) {
1127
- this.echo(this.promiseResolve(this.require(path), function (exports) {
1128
- var list = this.getMacro();
1129
- each(exports, function (macro, name) {
1130
- list[[namespace, name].join('.')] = macro;
1131
- });
1132
- }));
1133
- },
1134
- writable: false,
1135
- configurable: false,
1136
- enumerable: false
1137
- }), "async", {
1138
- value: function value(promise, callback) {
1139
- this.echo(this.promiseResolve(promise, function (data) {
1140
- return this.fn(callback)(data);
1141
- }));
1142
- },
1143
- writable: false,
1144
- configurable: false,
1145
- enumerable: false
1146
- }), "each", {
1147
- value: function value(object, callback) {
1148
- if (isString(object)) {
1149
- object = this.get(object, []);
1150
- }
1151
- each(object, callback);
1152
- },
1153
- writable: false,
1154
- configurable: false,
1155
- enumerable: false
1156
- }), "element", {
1157
- value: function value(tag, attr, content) {
1158
- return element(tag, attr, content);
1159
- },
1160
- writable: false,
1161
- configurable: false,
1162
- enumerable: false
1163
- }), "el", {
1164
- value: function value(tag, attr, content) {
1165
- this.echo(this.promiseResolve(content, function (content) {
1166
- return this.element(tag, attr, content);
1167
- }));
1168
- },
1169
- writable: false,
1170
- configurable: false,
1171
- enumerable: false
1172
- })));
1173
- };
1174
- this.configure(config);
1175
- }
1176
-
1177
- function EJS(options) {
1178
- if (instanceOf(this, EJS) === false) return new EJS(options);
1179
- var scope = {};
1180
- var config = {};
1181
- configSchema(config, options || {});
1182
- var context = new Context(config);
1183
- var compiler = new Compiler(config);
1184
- var cache = new Cache();
1185
- var template = new Template(config, cache, compiler);
1186
- var output = function output(path, scope) {
1187
- var globalHelpers = config.globalHelpers;
1188
- var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
1189
- return isFunction(scope[name]);
1190
- }).map(function (name) {
1191
- return scope[name].bind(scope);
1192
- }));
1193
- return template.get(path).then(function (callback) {
1194
- return callback.apply(scope, params);
1195
- });
1196
- };
1197
- var require = function require(name) {
1198
- var filepath = ext(name, config.extension);
1199
- var scope = context.create({});
1200
- return output(filepath, scope).then(function () {
1201
- return scope.getMacro();
1202
- });
1203
- };
1204
- var _render = function render(name, data) {
1205
- var filepath = ext(name, config.extension);
1206
- var scope = context.create(data);
1207
- return output(filepath, scope).then(function (content) {
1208
- if (scope.getExtend()) {
1209
- scope.setExtend(false);
1210
- var layout = scope.getLayout();
1211
- var _data = scope.clone();
1212
- return _render(layout, _data);
1214
+ each(exports, function (macro, name) {
1215
+ list[[namespace, name].join('.')] = macro;
1216
+ });
1217
+ }));
1218
+ }
1219
+ }), "async", {
1220
+ value: function value(promise, callback) {
1221
+ this.echo(this.promiseResolve(promise, function (data) {
1222
+ return this.fn(callback)(data);
1223
+ }));
1224
+ }
1225
+ }), "each", {
1226
+ value: function value(object, callback) {
1227
+ if (isString(object)) {
1228
+ object = this.get(object, []);
1213
1229
  }
1214
- return content;
1230
+ each(object, callback);
1231
+ }
1232
+ }), "element", {
1233
+ value: function value(tag, attr, content) {
1234
+ return element(tag, attr, content);
1235
+ }
1236
+ }), "el", {
1237
+ value: function value(tag, attr, content) {
1238
+ this.echo(this.promiseResolve(content, function (content) {
1239
+ return this.element(tag, attr, content);
1240
+ }));
1241
+ }
1242
+ })));
1243
+ return ContextScope;
1244
+ };
1245
+ var _scope = /*#__PURE__*/new WeakMap();
1246
+ var Context = /*#__PURE__*/function () {
1247
+ function Context(config, methods) {
1248
+ _classCallCheck(this, Context);
1249
+ _classPrivateFieldInitSpec(this, _scope, void 0);
1250
+ bindContext(this, ['create', 'helpers', 'configure']);
1251
+ this.configure(config, methods);
1252
+ }
1253
+ return _createClass(Context, [{
1254
+ key: "create",
1255
+ value: function create(data) {
1256
+ return new (_classPrivateFieldGet2(_scope, this))(data);
1257
+ }
1258
+ }, {
1259
+ key: "configure",
1260
+ value: function configure(config, methods) {
1261
+ _classPrivateFieldSet2(_scope, this, createScope(config, methods));
1262
+ }
1263
+ }, {
1264
+ key: "helpers",
1265
+ value: function helpers(methods) {
1266
+ extend(_classPrivateFieldGet2(_scope, this).prototype, methods || {});
1267
+ }
1268
+ }]);
1269
+ }();
1270
+
1271
+ var _config = /*#__PURE__*/new WeakMap();
1272
+ var _extend = /*#__PURE__*/new WeakMap();
1273
+ var _context = /*#__PURE__*/new WeakMap();
1274
+ var _compiler = /*#__PURE__*/new WeakMap();
1275
+ var _cache = /*#__PURE__*/new WeakMap();
1276
+ var _template = /*#__PURE__*/new WeakMap();
1277
+ var _EJS_brand = /*#__PURE__*/new WeakSet();
1278
+ var EJS = /*#__PURE__*/function () {
1279
+ function EJS(options) {
1280
+ _classCallCheck(this, EJS);
1281
+ _classPrivateMethodInitSpec(this, _EJS_brand);
1282
+ _classPrivateFieldInitSpec(this, _config, {});
1283
+ _classPrivateFieldInitSpec(this, _extend, {});
1284
+ _classPrivateFieldInitSpec(this, _context, void 0);
1285
+ _classPrivateFieldInitSpec(this, _compiler, void 0);
1286
+ _classPrivateFieldInitSpec(this, _cache, void 0);
1287
+ _classPrivateFieldInitSpec(this, _template, void 0);
1288
+ configSchema(_classPrivateFieldGet2(_config, this), options || {});
1289
+ _classPrivateFieldSet2(_context, this, new Context(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this)));
1290
+ _classPrivateFieldSet2(_compiler, this, new Compiler(_classPrivateFieldGet2(_config, this)));
1291
+ _classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
1292
+ _classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
1293
+ //
1294
+ bindContext(this, ['configure', 'create', 'render', 'context', 'preload', 'compile', 'helpers']);
1295
+ //
1296
+ this.helpers({
1297
+ require: _assertClassBrand(_EJS_brand, this, _require),
1298
+ render: this.render
1215
1299
  });
1216
- };
1217
- this.configure = function (options) {
1218
- options = options || {};
1219
- configSchema(config, options);
1220
- context.configure(config, scope);
1221
- compiler.configure(config);
1222
- cache.configure(config);
1223
- template.configure(config);
1224
- return config;
1225
- };
1226
- this.render = function (name, data) {
1227
- return _render(name, data);
1228
- };
1229
- this.helpers = function (methods) {
1230
- context.helpers(extend(scope, methods));
1231
- };
1232
- this.preload = function (list) {
1233
- return cache.load(list || {});
1234
- };
1235
- this.create = function (options) {
1236
- return new EJS(options);
1237
- };
1238
- this.compile = function (content, path) {
1239
- return compiler.compile(content, path);
1240
- };
1241
- this.context = function (data) {
1242
- return context.create(data);
1243
- };
1244
- this.helpers({
1245
- require: require,
1246
- render: _render
1300
+ }
1301
+ return _createClass(EJS, [{
1302
+ key: "configure",
1303
+ value: function configure(options) {
1304
+ configSchema(_classPrivateFieldGet2(_config, this), options || {});
1305
+ _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this));
1306
+ _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
1307
+ _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
1308
+ _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
1309
+ return _classPrivateFieldGet2(_config, this);
1310
+ }
1311
+ }, {
1312
+ key: "render",
1313
+ value: function render(name, data) {
1314
+ var _this = this;
1315
+ var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
1316
+ var scope = this.context(data);
1317
+ return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function (content) {
1318
+ if (scope.getExtend()) {
1319
+ scope.setExtend(false);
1320
+ var layout = scope.getLayout();
1321
+ var _data = scope.clone();
1322
+ return _this.render(layout, _data);
1323
+ }
1324
+ return content;
1325
+ });
1326
+ }
1327
+ }, {
1328
+ key: "helpers",
1329
+ value: function helpers(methods) {
1330
+ _classPrivateFieldGet2(_context, this).helpers(extend(_classPrivateFieldGet2(_extend, this), methods));
1331
+ }
1332
+ }, {
1333
+ key: "context",
1334
+ value: function context(data) {
1335
+ return _classPrivateFieldGet2(_context, this).create(data);
1336
+ }
1337
+ }, {
1338
+ key: "compile",
1339
+ value: function compile(content, path) {
1340
+ return _classPrivateFieldGet2(_compiler, this).compile(content, path);
1341
+ }
1342
+ }, {
1343
+ key: "preload",
1344
+ value: function preload(list) {
1345
+ return _classPrivateFieldGet2(_cache, this).load(list || {});
1346
+ }
1347
+ }, {
1348
+ key: "create",
1349
+ value: function create(options) {
1350
+ return new this.constructor(options);
1351
+ }
1352
+ }]);
1353
+ }();
1354
+
1355
+ // export function EJS2(options) {
1356
+ // const self = {
1357
+ // config: {},
1358
+ // helpers: {},
1359
+ // /**
1360
+ // * @type {Context}
1361
+ // */
1362
+ // context: null,
1363
+ // /**
1364
+ // * @type {Compiler}
1365
+ // */
1366
+ // compiler: null,
1367
+ // /**
1368
+ // * @type {Template}
1369
+ // */
1370
+ // template: null,
1371
+ // /**
1372
+ // * @type {Cache}
1373
+ // */
1374
+ // cache: null,
1375
+ // }
1376
+ // /**
1377
+ // *
1378
+ // */
1379
+ // configSchema(self.config, options || {})
1380
+ // self.context = useContext(self.config, self.helpers)
1381
+ // self.compiler = useCompiler(self.config)
1382
+ // self.cache = useCache(self.config)
1383
+ // self.template = useTemplate(self.config, self.cache, self.compiler)
1384
+ // /**
1385
+ // *
1386
+ // * @param {string} path
1387
+ // * @param {ContextScope} scope
1388
+ // * @return {Promise<string>}
1389
+ // */
1390
+ // const output = (path, scope) => {
1391
+ // const { globalHelpers } = self.config
1392
+ // const params = [
1393
+ // scope,
1394
+ // scope.getComponent(),
1395
+ // scope.getBuffer(),
1396
+ // safeValue,
1397
+ // ].concat(
1398
+ // globalHelpers
1399
+ // .filter((name) => isFunction(scope[name]))
1400
+ // .map((name) => scope[name].bind(scope))
1401
+ // )
1402
+ // return self.template
1403
+ // .get(path)
1404
+ // .then((callback) => callback.apply(scope, params))
1405
+ // }
1406
+ // /**
1407
+ // *
1408
+ // * @param name
1409
+ // * @return {Promise<string>}
1410
+ // */
1411
+ // const require = (name) => {
1412
+ // const filepath = ext(name, self.config.extension)
1413
+ // const scope = context({})
1414
+ // return output(filepath, scope).then(() => scope.getMacro())
1415
+ // }
1416
+ // /**
1417
+ // *
1418
+ // * @param {string} name
1419
+ // * @param {{}} [data]
1420
+ // * @return {Promise<string>}
1421
+ // */
1422
+ // const render = (name, data) => {
1423
+ // const filepath = ext(name, self.config.extension)
1424
+ // const scope = context(data)
1425
+ // return output(filepath, scope).then((content) => {
1426
+ // if (scope.getExtend()) {
1427
+ // scope.setExtend(false)
1428
+ // const layout = scope.getLayout()
1429
+ // const data = scope.clone()
1430
+ // return render(layout, data)
1431
+ // }
1432
+ // return content
1433
+ // })
1434
+ // }
1435
+ // /**
1436
+ // *
1437
+ // * @param options
1438
+ // * @return {{}}
1439
+ // */
1440
+ // const configure = (options = {}) => {
1441
+ // configSchema(self.config, options || {})
1442
+ // self.context.configure(self.config, self.helpers)
1443
+ // self.compiler.configure(self.config)
1444
+ // self.cache.configure(self.config)
1445
+ // self.template.configure(self.config)
1446
+ // return self.config
1447
+ // }
1448
+ // /**
1449
+ // *
1450
+ // * @param methods
1451
+ // */
1452
+ // const helpers = (methods) => {
1453
+ // self.context.helpers(extend(self.helpers, methods))
1454
+ // }
1455
+ // /**
1456
+ // *
1457
+ // * @param list
1458
+ // * @return {*}
1459
+ // */
1460
+ // const preload = (list) => {
1461
+ // return self.cache.load(list || {})
1462
+ // }
1463
+ // /**
1464
+ // *
1465
+ // * @param options
1466
+ // * @return {any}
1467
+ // */
1468
+ // const create = (options) => {
1469
+ // return EJS(options)
1470
+ // }
1471
+ // /**
1472
+ // *
1473
+ // * @param content
1474
+ // * @param path
1475
+ // * @return {Function}
1476
+ // */
1477
+ // const compile = (content, path) => {
1478
+ // return self.compiler.compile(content, path)
1479
+ // }
1480
+ // /**
1481
+ // *
1482
+ // * @param data
1483
+ // * @return {ContextScope}
1484
+ // */
1485
+ // const context = (data = {}) => {
1486
+ // return self.context.create(data)
1487
+ // }
1488
+ // /**
1489
+ // *
1490
+ // */
1491
+ // helpers({ require, render })
1492
+ // /**
1493
+ // *
1494
+ // */
1495
+ // return {
1496
+ // configure,
1497
+ // helpers,
1498
+ // preload,
1499
+ // context,
1500
+ // compile,
1501
+ // create,
1502
+ // render,
1503
+ // }
1504
+ // }
1505
+ function _output(path, scope) {
1506
+ var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
1507
+ globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
1508
+ var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
1509
+ return isFunction(scope[name]);
1510
+ }).map(function (name) {
1511
+ return scope[name].bind(scope);
1512
+ }));
1513
+ return _classPrivateFieldGet2(_template, this).get(path).then(function (callback) {
1514
+ return callback.apply(scope, params);
1515
+ });
1516
+ }
1517
+ function _require(name) {
1518
+ var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
1519
+ var scope = this.context({});
1520
+ return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
1521
+ return scope.getMacro();
1247
1522
  });
1248
- return this;
1249
1523
  }
1250
1524
 
1251
- var hash = Math.floor(Math.random() * 1e12).toString(36);
1252
1525
  var templates = {};
1253
- var ejs = new EJS({
1254
- cache: false,
1255
- withObject: false,
1256
- resolver: function resolver(path, name) {
1257
- return new Promise(function (resolve, reject) {
1258
- if (templates.hasOwnProperty(name)) {
1259
- resolve(templates[name]);
1260
- } else {
1261
- reject(new TemplateNotFound("template ".concat(name, " not found")));
1262
- }
1263
- });
1264
- }
1265
- });
1266
- var render = ejs.render,
1267
- context = ejs.context,
1268
- helpers = ejs.helpers,
1269
- configure = ejs.configure,
1270
- create = ejs.create;
1271
1526
  var getOrigin = function getOrigin(url, secure) {
1272
1527
  url = new URL(url);
1273
- if (secure) url.protocol = 'https:';
1528
+ url.protocol = secure ? 'https:' : 'http:';
1274
1529
  return url.origin;
1275
1530
  };
1531
+ var _EJS = new EJS({
1532
+ cache: false,
1533
+ withObject: false,
1534
+ resolver: function resolver(path, name) {
1535
+ return new Promise(function (resolve, reject) {
1536
+ if (templates.hasOwnProperty(name)) {
1537
+ resolve(templates[name]);
1538
+ } else {
1539
+ reject(new TemplateNotFound("template ".concat(name, " not found")));
1540
+ }
1541
+ });
1542
+ }
1543
+ }),
1544
+ render = _EJS.render,
1545
+ context = _EJS.context,
1546
+ helpers = _EJS.helpers,
1547
+ configure = _EJS.configure,
1548
+ create = _EJS.create;
1276
1549
  function setTemplates(list) {
1277
1550
  Object.assign(templates, list || {});
1278
1551
  }
1279
1552
 
1280
1553
  /**
1281
- * @typedef {Object<string,any>} HonoContext
1554
+ * @typedef {{}} HonoContext
1282
1555
  * @property {function(*):Promise<Response>} html
1283
1556
  * @property {function():Promise<Response>} notFound
1284
1557
  * @property {function(methods:{}):void} helpers
@@ -1289,12 +1562,11 @@
1289
1562
 
1290
1563
  /**
1291
1564
  * @param {Object<string,any>} options
1292
- * @return {(function(c:Context, next): Promise<any>)|*}
1565
+ * @return {(function(c:HonoContext, next): Promise<any>)|*}
1293
1566
  */
1294
1567
  function setRenderer() {
1295
1568
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1296
- _ref$version = _ref.version,
1297
- version = _ref$version === void 0 ? hash : _ref$version,
1569
+ version = _ref.version,
1298
1570
  _ref$secure = _ref.secure,
1299
1571
  secure = _ref$secure === void 0 ? true : _ref$secure;
1300
1572
  return /*#__PURE__*/function () {
@@ -1331,7 +1603,8 @@
1331
1603
  };
1332
1604
  }();
1333
1605
  }
1334
- var version = hash;
1606
+
1607
+ //export { render, context, helpers, configure, create }
1335
1608
 
1336
1609
  exports.TemplateError = TemplateError;
1337
1610
  exports.TemplateNotFound = TemplateNotFound;
@@ -1343,6 +1616,5 @@
1343
1616
  exports.render = render;
1344
1617
  exports.setRenderer = setRenderer;
1345
1618
  exports.setTemplates = setTemplates;
1346
- exports.version = version;
1347
1619
 
1348
1620
  }));