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