@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,139 @@
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
+ }
11
+ function _callSuper(t, o, e) {
12
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
13
+ }
14
+ function _checkPrivateRedeclaration(e, t) {
15
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
16
+ }
17
+ function _classCallCheck(a, n) {
18
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
19
+ }
20
+ function _classPrivateFieldGet2(s, a) {
21
+ return s.get(_assertClassBrand(s, a));
22
+ }
23
+ function _classPrivateFieldInitSpec(e, t, a) {
24
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
25
+ }
26
+ function _classPrivateFieldSet2(s, a, r) {
27
+ return s.set(_assertClassBrand(s, a), r), r;
28
+ }
29
+ function _classPrivateMethodInitSpec(e, a) {
30
+ _checkPrivateRedeclaration(e, a), a.add(e);
31
+ }
32
+ function _construct(t, e, r) {
33
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
34
+ var o = [null];
35
+ o.push.apply(o, e);
36
+ var p = new (t.bind.apply(t, o))();
37
+ return r && _setPrototypeOf(p, r.prototype), p;
38
+ }
39
+ function _defineProperties(e, r) {
40
+ for (var t = 0; t < r.length; t++) {
41
+ var o = r[t];
42
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
43
+ }
44
+ }
45
+ function _createClass(e, r, t) {
46
+ return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
47
+ writable: !1
48
+ }), e;
49
+ }
50
+ function _defineProperty(e, r, t) {
51
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
52
+ value: t,
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0
56
+ }) : e[r] = t, e;
57
+ }
58
+ function _getPrototypeOf(t) {
59
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
60
+ return t.__proto__ || Object.getPrototypeOf(t);
61
+ }, _getPrototypeOf(t);
62
+ }
63
+ function _inherits(t, e) {
64
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
65
+ t.prototype = Object.create(e && e.prototype, {
66
+ constructor: {
67
+ value: t,
68
+ writable: !0,
69
+ configurable: !0
70
+ }
71
+ }), Object.defineProperty(t, "prototype", {
72
+ writable: !1
73
+ }), e && _setPrototypeOf(t, e);
74
+ }
75
+ function _isNativeFunction(t) {
76
+ try {
77
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
78
+ } catch (n) {
79
+ return "function" == typeof t;
80
+ }
81
+ }
82
+ function _isNativeReflectConstruct() {
83
+ try {
84
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
85
+ } catch (t) {}
86
+ return (_isNativeReflectConstruct = function () {
87
+ return !!t;
88
+ })();
89
+ }
90
+ function _possibleConstructorReturn(t, e) {
91
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
92
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
93
+ return _assertThisInitialized(t);
94
+ }
95
+ function _setPrototypeOf(t, e) {
96
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
97
+ return t.__proto__ = e, t;
98
+ }, _setPrototypeOf(t, e);
99
+ }
100
+ function _toPrimitive(t, r) {
101
+ if ("object" != typeof t || !t) return t;
102
+ var e = t[Symbol.toPrimitive];
103
+ if (void 0 !== e) {
104
+ var i = e.call(t, r);
105
+ if ("object" != typeof i) return i;
106
+ throw new TypeError("@@toPrimitive must return a primitive value.");
107
+ }
108
+ return (String )(t);
109
+ }
110
+ function _toPropertyKey(t) {
111
+ var i = _toPrimitive(t, "string");
112
+ return "symbol" == typeof i ? i : i + "";
113
+ }
114
+ function _wrapNativeSuper(t) {
115
+ var r = "function" == typeof Map ? new Map() : void 0;
116
+ return _wrapNativeSuper = function (t) {
117
+ if (null === t || !_isNativeFunction(t)) return t;
118
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
119
+ if (void 0 !== r) {
120
+ if (r.has(t)) return r.get(t);
121
+ r.set(t, Wrapper);
122
+ }
123
+ function Wrapper() {
124
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
125
+ }
126
+ return Wrapper.prototype = Object.create(t.prototype, {
127
+ constructor: {
128
+ value: Wrapper,
129
+ enumerable: !1,
130
+ writable: !0,
131
+ configurable: !0
132
+ }
133
+ }), _setPrototypeOf(Wrapper, t);
134
+ }, _wrapNativeSuper(t);
135
+ }
136
+
3
137
  var typeProp = function typeProp() {
4
138
  var args = [].slice.call(arguments);
5
139
  var callback = args.shift();
@@ -64,6 +198,9 @@ var safeValue = function safeValue(value, escape) {
64
198
  var instanceOf = function instanceOf(object, instance) {
65
199
  return Boolean(object instanceof instance);
66
200
  };
201
+ var assertInstanceOf = function assertInstanceOf(object, instance) {
202
+ if (instanceOf(object, instance) === false) throw new TypeError("".concat(object, " in not instance of ").concat(instance));
203
+ };
67
204
  var getPath = function getPath(context, name, strict) {
68
205
  var data = context;
69
206
  var chunks = String(name).split('.');
@@ -84,6 +221,14 @@ var getPath = function getPath(context, name, strict) {
84
221
  }
85
222
  return [data, prop];
86
223
  };
224
+ var bindContext = function bindContext(object) {
225
+ var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
226
+ methods.forEach(function (name) {
227
+ if (name in object) {
228
+ object[name] = object[name].bind(object);
229
+ }
230
+ });
231
+ };
87
232
  var ext = function ext(path, defaults) {
88
233
  var ext = path.split('.').pop();
89
234
  if (ext !== defaults) {
@@ -146,6 +291,13 @@ var omit = function omit(object, list) {
146
291
  }
147
292
  });
148
293
  };
294
+
295
+ /**
296
+ *
297
+ * @param object
298
+ * @param prop
299
+ * @return {boolean}
300
+ */
149
301
  var hasProp = function hasProp(object, prop) {
150
302
  return object && object.hasOwnProperty(prop);
151
303
  };
@@ -154,6 +306,17 @@ var joinPath = function joinPath(path, template) {
154
306
  template = template.replace(/\/\//g, '/');
155
307
  return template;
156
308
  };
309
+ var matchTokens = function matchTokens(regex, text, callback) {
310
+ var index = 0;
311
+ text.replace(regex, function () {
312
+ var params = [].slice.call(arguments, 0, -1);
313
+ var offset = params.pop();
314
+ var match = params.shift();
315
+ callback(params, index, offset);
316
+ index = offset + match.length;
317
+ return match;
318
+ });
319
+ };
157
320
 
158
321
  var defaults = {};
159
322
  defaults["export"] = 'ejsPrecompiled';
@@ -199,206 +362,221 @@ var configSchema = function configSchema(config, options) {
199
362
  };
200
363
 
201
364
  var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
202
- function Cache(config) {
203
- if (instanceOf(this, Cache) === false) return new Cache();
204
- var cache = {
205
- enabled: true,
206
- list: {}
207
- };
208
- this.configure = function (config) {
209
- cache.enabled = config.cache;
210
- if (isNode() === false) {
211
- this.load(global[config["export"]]);
365
+ var _enabled = /*#__PURE__*/new WeakMap();
366
+ var _list = /*#__PURE__*/new WeakMap();
367
+ var Cache = /*#__PURE__*/function () {
368
+ function Cache(config) {
369
+ _classCallCheck(this, Cache);
370
+ _classPrivateFieldInitSpec(this, _enabled, true);
371
+ _classPrivateFieldInitSpec(this, _list, {});
372
+ bindContext(this, ['configure']);
373
+ this.configure(config);
374
+ }
375
+ return _createClass(Cache, [{
376
+ key: "load",
377
+ value: function load(data) {
378
+ if (_classPrivateFieldGet2(_enabled, this)) {
379
+ extend(_classPrivateFieldGet2(_list, this), data || {});
380
+ }
212
381
  }
213
- };
214
- this.clear = function () {
215
- cache.list = {};
216
- };
217
- this.load = function (data) {
218
- if (cache.enabled) {
219
- extend(cache.list, data || {});
382
+ }, {
383
+ key: "get",
384
+ value: function get(key) {
385
+ if (_classPrivateFieldGet2(_enabled, this)) {
386
+ return _classPrivateFieldGet2(_list, this)[key];
387
+ }
220
388
  }
221
- return this;
222
- };
223
- this.get = function (key) {
224
- if (cache.enabled) {
225
- return cache.list[key];
389
+ }, {
390
+ key: "set",
391
+ value: function set(key, value) {
392
+ if (_classPrivateFieldGet2(_enabled, this)) {
393
+ _classPrivateFieldGet2(_list, this)[key] = value;
394
+ }
226
395
  }
227
- };
228
- this.set = function (key, value) {
229
- if (cache.enabled) {
230
- cache.list[key] = value;
396
+ }, {
397
+ key: "exist",
398
+ value: function exist(key) {
399
+ return hasProp(_classPrivateFieldGet2(_list, this), key);
231
400
  }
232
- return this;
233
- };
234
- this.resolve = function (key) {
235
- return Promise.resolve(this.get(key));
236
- };
237
- this.remove = function (key) {
238
- delete cache.list[key];
239
- };
240
- this.exist = function (key) {
241
- return hasProp(cache.list, key);
242
- };
243
- }
401
+ }, {
402
+ key: "clear",
403
+ value: function clear() {
404
+ _classPrivateFieldSet2(_list, this, {});
405
+ }
406
+ }, {
407
+ key: "remove",
408
+ value: function remove(key) {
409
+ delete _classPrivateFieldGet2(_list, this)[key];
410
+ }
411
+ }, {
412
+ key: "resolve",
413
+ value: function resolve(key) {
414
+ return Promise.resolve(this.get(key));
415
+ }
416
+ }, {
417
+ key: "configure",
418
+ value: function configure(config) {
419
+ _classPrivateFieldSet2(_enabled, this, config.cache);
420
+ if (isNode() === false) {
421
+ this.load(global[config["export"]]);
422
+ }
423
+ }
424
+ }]);
425
+ }();
244
426
 
245
- var tagList = [{
246
- symbol: '-',
247
- format: function format(value) {
248
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
249
- }
250
- }, {
251
- symbol: '=',
252
- format: function format(value) {
253
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
254
- }
255
- }, {
256
- symbol: '#',
257
- format: function format(value) {
258
- return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
259
- }
260
- }, {
261
- symbol: '',
262
- format: function format(value) {
263
- return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
427
+ var _config$1 = /*#__PURE__*/new WeakMap();
428
+ var _symbols = /*#__PURE__*/new WeakMap();
429
+ var Compiler = /*#__PURE__*/function () {
430
+ function Compiler(config) {
431
+ _classCallCheck(this, Compiler);
432
+ _classPrivateFieldInitSpec(this, _config$1, {});
433
+ _classPrivateFieldInitSpec(this, _symbols, [{
434
+ symbol: '-',
435
+ format: function format(value) {
436
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
437
+ }
438
+ }, {
439
+ symbol: '=',
440
+ format: function format(value) {
441
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
442
+ }
443
+ }, {
444
+ symbol: '#',
445
+ format: function format(value) {
446
+ return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
447
+ }
448
+ }, {
449
+ symbol: '',
450
+ format: function format(value) {
451
+ return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
452
+ }
453
+ }]);
454
+ bindContext(this, ['configure', 'compile']);
455
+ this.configure(config);
264
456
  }
265
- }];
266
- function matchTokens(regex, text, callback) {
267
- var index = 0;
268
- text.replace(regex, function () {
269
- var params = [].slice.call(arguments, 0, -1);
270
- var offset = params.pop();
271
- var match = params.shift();
272
- callback(params, index, offset);
273
- index = offset + match.length;
274
- return match;
275
- });
276
- }
277
- function Compiler(config) {
278
- if (instanceOf(this, Compiler) === false) return new Compiler(config);
279
- var compiler = {};
280
- this.configure = function (config) {
281
- compiler.withObject = config.withObject;
282
- compiler.rmWhitespace = config.rmWhitespace;
283
- compiler.token = config.token;
284
- compiler.vars = config.vars;
285
- compiler.globalHelpers = config.globalHelpers;
286
- compiler.matches = [];
287
- compiler.formats = [];
288
- compiler.slurp = {
289
- match: '[\s\t\n]*',
290
- start: [compiler.token.start, '_'],
291
- end: ['_', compiler.token.end]
292
- };
293
- tagList.forEach(function (item) {
294
- compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
295
- compiler.formats.push(item.format.bind(compiler.vars));
296
- });
297
- compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
298
- compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
299
- compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
300
- };
301
- this.compile = function (content, path) {
302
- var _compiler$vars = compiler.vars,
303
- SCOPE = _compiler$vars.SCOPE,
304
- SAFE = _compiler$vars.SAFE,
305
- BUFFER = _compiler$vars.BUFFER,
306
- COMPONENT = _compiler$vars.COMPONENT;
307
- var GLOBALS = compiler.globalHelpers;
308
- content = String(content);
309
- if (compiler.rmWhitespace) {
310
- content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
311
- }
312
- content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
313
- var source = "".concat(BUFFER, "('");
314
- matchTokens(compiler.regex, content, function (params, index, offset) {
315
- source += symbols(content.slice(index, offset));
316
- params.forEach(function (value, index) {
317
- if (value) {
318
- source += compiler.formats[index](value);
319
- }
457
+ return _createClass(Compiler, [{
458
+ key: "configure",
459
+ value: function configure(config) {
460
+ var _this = this;
461
+ _classPrivateFieldGet2(_config$1, this).withObject = config.withObject;
462
+ _classPrivateFieldGet2(_config$1, this).rmWhitespace = config.rmWhitespace;
463
+ _classPrivateFieldGet2(_config$1, this).token = config.token;
464
+ _classPrivateFieldGet2(_config$1, this).vars = config.vars;
465
+ _classPrivateFieldGet2(_config$1, this).globalHelpers = config.globalHelpers;
466
+ _classPrivateFieldGet2(_config$1, this).matches = [];
467
+ _classPrivateFieldGet2(_config$1, this).formats = [];
468
+ _classPrivateFieldGet2(_config$1, this).slurp = {
469
+ match: '[s\t\n]*',
470
+ start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
471
+ end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
472
+ };
473
+ _classPrivateFieldGet2(_symbols, this).forEach(function (item) {
474
+ _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));
475
+ _classPrivateFieldGet2(_config$1, _this).formats.push(item.format.bind(_classPrivateFieldGet2(_config$1, _this).vars));
320
476
  });
321
- });
322
- source += "');";
323
- source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
324
- if (compiler.withObject) {
325
- source = "with(".concat(SCOPE, "){").concat(source, "}");
326
- }
327
- source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
328
- source += "\n//# sourceURL=".concat(path);
329
- var result = null;
330
- var params = [SCOPE, COMPONENT, BUFFER, SAFE].concat(GLOBALS);
331
- try {
332
- result = Function.apply(null, params.concat(source));
333
- result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
334
- } catch (e) {
335
- e.filename = path;
336
- e.source = source;
337
- throw e;
338
- }
339
- return result;
340
- };
341
- this.configure(config);
342
- }
343
-
344
- function Template(config, cache, compiler) {
345
- if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
346
- if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
347
- if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
348
- var template = {};
349
- var result = function result(template, content) {
350
- cache.set(template, content);
351
- return content;
352
- };
353
- var resolve = function resolve(path) {
354
- return template.resolver(template.path, path);
355
- };
356
- var compile = function compile(content, template) {
357
- if (isFunction(content)) {
358
- return content;
359
- } else {
360
- return compiler.compile(content, template);
477
+ _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
478
+ _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
479
+ _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
361
480
  }
362
- };
363
- this.configure = function (config) {
364
- template.path = config.path;
365
- template.cache = config.cache;
366
- if (isFunction(config.resolver)) {
367
- template.resolver = config.resolver;
481
+ }, {
482
+ key: "compile",
483
+ value: function compile(content, path) {
484
+ var _this2 = this;
485
+ var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config$1, this).vars,
486
+ SCOPE = _classPrivateFieldGet2$1.SCOPE,
487
+ SAFE = _classPrivateFieldGet2$1.SAFE,
488
+ BUFFER = _classPrivateFieldGet2$1.BUFFER,
489
+ COMPONENT = _classPrivateFieldGet2$1.COMPONENT;
490
+ var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
491
+ if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
492
+ content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
493
+ }
494
+ 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);
495
+ var source = "".concat(BUFFER, "('");
496
+ matchTokens(_classPrivateFieldGet2(_config$1, this).regex, content, function (params, index, offset) {
497
+ source += symbols(content.slice(index, offset));
498
+ params.forEach(function (value, index) {
499
+ if (value) {
500
+ source += _classPrivateFieldGet2(_config$1, _this2).formats[index](value);
501
+ }
502
+ });
503
+ });
504
+ source += "');";
505
+ source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
506
+ if (_classPrivateFieldGet2(_config$1, this).withObject) {
507
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
508
+ }
509
+ source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
510
+ source += "\n//# sourceURL=".concat(path);
511
+ var result = null;
512
+ var params = [SCOPE, COMPONENT, BUFFER, SAFE].concat(GLOBALS);
513
+ try {
514
+ result = Function.apply(null, params.concat(source));
515
+ result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
516
+ } catch (e) {
517
+ e.filename = path;
518
+ e.source = source;
519
+ throw e;
520
+ }
521
+ return result;
368
522
  }
369
- };
370
- this.get = function (template) {
371
- if (cache.exist(template)) {
372
- return cache.resolve(template);
523
+ }]);
524
+ }();
525
+
526
+ var _path = /*#__PURE__*/new WeakMap();
527
+ var _cache$1 = /*#__PURE__*/new WeakMap();
528
+ var _compiler$1 = /*#__PURE__*/new WeakMap();
529
+ var _resolver = /*#__PURE__*/new WeakMap();
530
+ var _Template_brand = /*#__PURE__*/new WeakSet();
531
+ var Template = /*#__PURE__*/function () {
532
+ function Template(config, cache, compiler) {
533
+ _classCallCheck(this, Template);
534
+ _classPrivateMethodInitSpec(this, _Template_brand);
535
+ _classPrivateFieldInitSpec(this, _path, void 0);
536
+ _classPrivateFieldInitSpec(this, _cache$1, void 0);
537
+ _classPrivateFieldInitSpec(this, _compiler$1, void 0);
538
+ _classPrivateFieldInitSpec(this, _resolver, void 0);
539
+ assertInstanceOf(cache, Cache);
540
+ assertInstanceOf(compiler, Compiler);
541
+ _classPrivateFieldSet2(_cache$1, this, cache);
542
+ _classPrivateFieldSet2(_compiler$1, this, compiler);
543
+ bindContext(this, ['configure', 'get']);
544
+ this.configure(config);
545
+ }
546
+ return _createClass(Template, [{
547
+ key: "configure",
548
+ value: function configure(config) {
549
+ _classPrivateFieldSet2(_path, this, config.path);
550
+ if (isFunction(config.resolver)) {
551
+ _classPrivateFieldSet2(_resolver, this, config.resolver);
552
+ }
373
553
  }
374
- return resolve(template).then(function (content) {
375
- return result(template, compile(content, template));
376
- });
377
- };
378
- this.configure(config);
554
+ }, {
555
+ key: "get",
556
+ value: function get(template) {
557
+ var _this = this;
558
+ if (_classPrivateFieldGet2(_cache$1, this).exist(template)) {
559
+ return _classPrivateFieldGet2(_cache$1, this).resolve(template);
560
+ }
561
+ return _assertClassBrand(_Template_brand, this, _resolve).call(this, template).then(function (content) {
562
+ return _assertClassBrand(_Template_brand, _this, _result).call(_this, template, _assertClassBrand(_Template_brand, _this, _compile).call(_this, content, template));
563
+ });
564
+ }
565
+ }]);
566
+ }();
567
+ function _resolve(path) {
568
+ return _classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path, this), path);
379
569
  }
380
-
381
- function _defineProperty(e, r, t) {
382
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
383
- value: t,
384
- enumerable: !0,
385
- configurable: !0,
386
- writable: !0
387
- }) : e[r] = t, e;
570
+ function _result(template, content) {
571
+ _classPrivateFieldGet2(_cache$1, this).set(template, content);
572
+ return content;
388
573
  }
389
- function _toPrimitive(t, r) {
390
- if ("object" != typeof t || !t) return t;
391
- var e = t[Symbol.toPrimitive];
392
- if (void 0 !== e) {
393
- var i = e.call(t, r || "default");
394
- if ("object" != typeof i) return i;
395
- throw new TypeError("@@toPrimitive must return a primitive value.");
574
+ function _compile(content, template) {
575
+ if (isFunction(content)) {
576
+ return content;
577
+ } else {
578
+ return _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
396
579
  }
397
- return ("string" === r ? String : Number)(t);
398
- }
399
- function _toPropertyKey(t) {
400
- var i = _toPrimitive(t, "string");
401
- return "symbol" == typeof i ? i : i + "";
402
580
  }
403
581
 
404
582
  var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
@@ -426,82 +604,61 @@ var element = function element(tag, attrs, content) {
426
604
  return result.join('');
427
605
  };
428
606
 
429
- /**
430
- * @extends Error
431
- * @property code
432
- * @param {string} message
433
- * @constructor
434
- */
435
- function TemplateError(message) {
436
- this.name = 'TemplateError';
437
- this.message = message;
438
- Error.call(this);
439
- }
440
-
441
- /**
442
- *
443
- */
444
- Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
445
- Object.assign(TemplateError.prototype, {
446
- code: 1
447
- });
448
- /**
449
- *
450
- * @return {number}
451
- */
452
- TemplateError.prototype.getCode = function () {
453
- return this.code;
454
- };
455
- /**
456
- *
457
- * @return {string}
458
- */
459
- TemplateError.prototype.getMessage = function () {
460
- return this.message;
461
- };
462
- /**
463
- * @return {string}
464
- */
465
- TemplateError.prototype.toString = function () {
466
- return this.getMessage();
467
- };
468
-
469
- /**
470
- * @extends TemplateError
471
- * @param {string} message
472
- * @constructor
473
- */
474
- function TemplateNotFound(message) {
475
- TemplateError.call(this);
476
- this.name = 'TemplateNotFound';
477
- this.message = message;
478
- }
479
-
480
- /**
481
- *
482
- */
483
- Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
484
- Object.assign(TemplateNotFound.prototype, {
485
- code: 404
486
- });
487
- /**
488
- * @extends TemplateError
489
- * @param {string} message
490
- * @constructor
491
- */
492
- function TemplateSyntaxError(message) {
493
- TemplateError.call(this);
494
- this.name = 'TemplateSyntaxError';
495
- this.message = message;
496
- }
497
-
498
- /**
499
- *
500
- */
501
- Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
502
- Object.assign(TemplateSyntaxError.prototype, {
503
- code: 500
504
- });
607
+ var TemplateError = /*#__PURE__*/function (_Error) {
608
+ function TemplateError(message) {
609
+ var _this;
610
+ _classCallCheck(this, TemplateError);
611
+ _this = _callSuper(this, TemplateError);
612
+ _defineProperty(_this, "code", 0);
613
+ _this.message = message;
614
+ return _this;
615
+ }
616
+ _inherits(TemplateError, _Error);
617
+ return _createClass(TemplateError, [{
618
+ key: "getCode",
619
+ value: function getCode() {
620
+ return this.code;
621
+ }
622
+ }, {
623
+ key: "getMessage",
624
+ value: function getMessage() {
625
+ return this.message;
626
+ }
627
+ }, {
628
+ key: "toString",
629
+ value: function toString() {
630
+ return this.getMessage();
631
+ }
632
+ }]);
633
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
634
+ var TemplateNotFound = /*#__PURE__*/function (_TemplateError2) {
635
+ function TemplateNotFound() {
636
+ var _this2;
637
+ _classCallCheck(this, TemplateNotFound);
638
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
639
+ args[_key] = arguments[_key];
640
+ }
641
+ _this2 = _callSuper(this, TemplateNotFound, [].concat(args));
642
+ _defineProperty(_this2, "code", 404);
643
+ return _this2;
644
+ }
645
+ _inherits(TemplateNotFound, _TemplateError2);
646
+ return _createClass(TemplateNotFound);
647
+ }(TemplateError);
648
+ var TemplateSyntaxError = /*#__PURE__*/function (_TemplateError3) {
649
+ function TemplateSyntaxError() {
650
+ var _this3;
651
+ _classCallCheck(this, TemplateSyntaxError);
652
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
653
+ args[_key2] = arguments[_key2];
654
+ }
655
+ _this3 = _callSuper(this, TemplateSyntaxError, [].concat(args));
656
+ _defineProperty(_this3, "code", 500);
657
+ return _this3;
658
+ }
659
+ _inherits(TemplateSyntaxError, _TemplateError3);
660
+ return _createClass(TemplateSyntaxError);
661
+ }(TemplateError);
505
662
 
506
663
  function resolve(list) {
507
664
  return Promise.all(list || []).then(function (list) {
@@ -513,12 +670,17 @@ function resolve(list) {
513
670
  function reject(error) {
514
671
  return Promise.reject(new TemplateSyntaxError(error.message));
515
672
  }
673
+
674
+ /**
675
+ *
676
+ * @return {buffer}
677
+ */
516
678
  function createBuffer() {
517
679
  var store = [],
518
680
  array = [];
519
- function buffer(value) {
681
+ var buffer = function buffer(value) {
520
682
  array.push(value);
521
- }
683
+ };
522
684
  buffer.start = function () {
523
685
  array = [];
524
686
  };
@@ -540,387 +702,499 @@ function createBuffer() {
540
702
  return buffer;
541
703
  }
542
704
 
543
- function Context(config) {
544
- if (instanceOf(this, Context) === false) return new Context(config);
545
- this.configure = function (config, methods) {
546
- var _Object$definePropert;
547
- var _config$vars = config.vars,
548
- BLOCKS = _config$vars.BLOCKS,
549
- MACRO = _config$vars.MACRO,
550
- EXTEND = _config$vars.EXTEND,
551
- LAYOUT = _config$vars.LAYOUT,
552
- BUFFER = _config$vars.BUFFER,
553
- COMPONENT = _config$vars.COMPONENT;
554
- this.create = function (data) {
555
- return new Scope(data);
556
- };
557
- this.helpers = function (methods) {
558
- extend(Scope.prototype, methods || {});
559
- };
560
- /**
561
- * @name ContextScope
562
- * @param data
563
- * @constructor
564
- */
565
- function Scope(data) {
566
- this[BLOCKS] = {};
567
- this[MACRO] = {};
568
- extend(this, data || {});
569
- }
570
- Scope.prototype = extend({}, methods || {});
571
- Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, BUFFER, {
572
- value: createBuffer(),
573
- writable: true,
574
- configurable: false,
575
- enumerable: false
576
- }), BLOCKS, {
577
- value: {},
578
- writable: true,
579
- configurable: false,
580
- enumerable: false
581
- }), MACRO, {
582
- value: {},
583
- writable: true,
584
- configurable: false,
585
- enumerable: false
586
- }), LAYOUT, {
587
- value: false,
588
- writable: true,
589
- configurable: false,
590
- enumerable: false
591
- }), EXTEND, {
592
- value: false,
593
- writable: true,
594
- configurable: false,
595
- enumerable: false
596
- }), "getMacro", {
597
- value: function value() {
598
- return this[MACRO];
599
- },
600
- writable: false,
601
- configurable: false,
602
- enumerable: false
603
- }), "getBuffer", {
604
- value: function value() {
605
- return this[BUFFER];
606
- },
607
- writable: false,
608
- configurable: false,
609
- enumerable: false
610
- }), "getComponent", {
611
- value: function value() {
612
- var context = this;
613
- if (COMPONENT in context) {
614
- return function () {
615
- return context[COMPONENT].apply(context, arguments);
616
- };
617
- }
705
+ var createScope = function createScope(config, methods) {
706
+ var _Object$definePropert;
707
+ var _config$vars = config.vars,
708
+ BLOCKS = _config$vars.BLOCKS,
709
+ MACRO = _config$vars.MACRO,
710
+ EXTEND = _config$vars.EXTEND,
711
+ LAYOUT = _config$vars.LAYOUT,
712
+ BUFFER = _config$vars.BUFFER,
713
+ COMPONENT = _config$vars.COMPONENT,
714
+ SAFE = _config$vars.SAFE,
715
+ SCOPE = _config$vars.SCOPE;
716
+ /**
717
+ * @name ContextScope
718
+ * @param data
719
+ * @constructor
720
+ */
721
+ function ContextScope(data) {
722
+ this[BLOCKS] = {};
723
+ this[MACRO] = {};
724
+ Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT]));
725
+ }
726
+ Object.assign(ContextScope.prototype, methods);
727
+ Object.defineProperties(ContextScope.prototype, (_Object$definePropert = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, BUFFER, {
728
+ value: createBuffer()
729
+ }), BLOCKS, {
730
+ value: {},
731
+ writable: true
732
+ }), MACRO, {
733
+ value: {},
734
+ writable: true
735
+ }), LAYOUT, {
736
+ value: false,
737
+ writable: true
738
+ }), EXTEND, {
739
+ value: false,
740
+ writable: true
741
+ }), "getMacro", {
742
+ value: function value() {
743
+ return this[MACRO];
744
+ }
745
+ }), "getBuffer", {
746
+ value: function value() {
747
+ return this[BUFFER];
748
+ }
749
+ }), "getComponent", {
750
+ value: function value() {
751
+ var context = this;
752
+ if (COMPONENT in context) {
618
753
  return function () {
619
- console.log('%s function not defined', COMPONENT);
754
+ return context[COMPONENT].apply(context, arguments);
620
755
  };
621
- },
622
- writable: false,
623
- configurable: false,
624
- enumerable: false
625
- }), "getBlocks", {
626
- value: function value() {
627
- return this[BLOCKS];
628
- },
629
- writable: false,
630
- configurable: false,
631
- enumerable: false
632
- }), "setExtend", {
633
- value: function value(_value) {
634
- this[EXTEND] = _value;
635
- },
636
- writable: false,
637
- configurable: false,
638
- enumerable: false
639
- }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
640
- value: function value() {
641
- return this[EXTEND];
642
- },
643
- writable: false,
644
- configurable: false,
645
- enumerable: false
646
- }), "setLayout", {
647
- value: function value(layout) {
648
- this[LAYOUT] = layout;
649
- },
650
- writable: false,
651
- configurable: false,
652
- enumerable: false
653
- }), "getLayout", {
654
- value: function value() {
655
- return this[LAYOUT];
656
- },
657
- writable: false,
658
- configurable: false,
659
- enumerable: false
660
- }), "clone", {
661
- value: function value(exclude_blocks) {
662
- var filter = [LAYOUT, EXTEND, BUFFER];
663
- if (exclude_blocks === true) {
664
- filter.push(BLOCKS);
756
+ }
757
+ return function () {
758
+ console.log('%s function not defined', COMPONENT);
759
+ };
760
+ }
761
+ }), "getBlocks", {
762
+ value: function value() {
763
+ return this[BLOCKS];
764
+ }
765
+ }), "setExtend", {
766
+ value: function value(_value) {
767
+ this[EXTEND] = _value;
768
+ }
769
+ }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
770
+ value: function value() {
771
+ return this[EXTEND];
772
+ }
773
+ }), "setLayout", {
774
+ value: function value(layout) {
775
+ this[LAYOUT] = layout;
776
+ }
777
+ }), "getLayout", {
778
+ value: function value() {
779
+ return this[LAYOUT];
780
+ }
781
+ }), "clone", {
782
+ value: function value(exclude_blocks) {
783
+ var filter = [LAYOUT, EXTEND, BUFFER];
784
+ if (exclude_blocks === true) {
785
+ filter.push(BLOCKS);
786
+ }
787
+ return omit(this, filter);
788
+ }
789
+ }), "extend", {
790
+ value: function value(layout) {
791
+ this.setExtend(true);
792
+ this.setLayout(layout);
793
+ }
794
+ }), "echo", {
795
+ value: function value(layout) {
796
+ var buffer = this.getBuffer();
797
+ var params = [].slice.call(arguments);
798
+ params.forEach(buffer);
799
+ }
800
+ }), "fn", {
801
+ value: function value(callback) {
802
+ var buffer = this.getBuffer();
803
+ var context = this;
804
+ return function () {
805
+ buffer.backup();
806
+ if (isFunction(callback)) {
807
+ callback.apply(context, arguments);
665
808
  }
666
- return omit(this, filter);
667
- },
668
- writable: false,
669
- configurable: false,
670
- enumerable: false
671
- }), "extend", {
672
- value: function value(layout) {
673
- this.setExtend(true);
674
- this.setLayout(layout);
675
- },
676
- writable: false,
677
- configurable: false,
678
- enumerable: false
679
- }), "echo", {
680
- value: function value(layout) {
681
- var buffer = this.getBuffer();
682
- var params = [].slice.call(arguments);
683
- params.forEach(buffer);
684
- },
685
- writable: false,
686
- configurable: false,
687
- enumerable: false
688
- }), "fn", {
689
- value: function value(callback) {
690
- var buffer = this.getBuffer();
691
- var context = this;
692
- return function () {
693
- buffer.backup();
694
- if (isFunction(callback)) {
695
- callback.apply(context, arguments);
696
- }
697
- return buffer.restore();
698
- };
699
- },
700
- writable: false,
701
- configurable: false,
702
- enumerable: false
703
- }), "get", {
704
- value: function value(name, defaults) {
705
- var path = getPath(this, name, true);
706
- var result = path.shift();
707
- var prop = path.pop();
708
- return hasProp(result, prop) ? result[prop] : defaults;
709
- },
710
- writable: true,
711
- configurable: true,
712
- enumerable: false
713
- }), "set", {
714
- value: function value(name, _value2) {
715
- var path = getPath(this, name, false);
716
- var result = path.shift();
717
- var prop = path.pop();
718
- if (this.getExtend() && hasProp(result, prop)) {
719
- return result[prop];
809
+ return buffer.restore();
810
+ };
811
+ }
812
+ }), "get", {
813
+ value: function value(name, defaults) {
814
+ var path = getPath(this, name, true);
815
+ var result = path.shift();
816
+ var prop = path.pop();
817
+ return hasProp(result, prop) ? result[prop] : defaults;
818
+ }
819
+ }), "set", {
820
+ value: function value(name, _value2) {
821
+ var path = getPath(this, name, false);
822
+ var result = path.shift();
823
+ var prop = path.pop();
824
+ if (this.getExtend() && hasProp(result, prop)) {
825
+ return result[prop];
826
+ }
827
+ return result[prop] = _value2;
828
+ }
829
+ }), "macro", {
830
+ value: function value(name, callback) {
831
+ var list = this.getMacro();
832
+ var macro = this.fn(callback);
833
+ var context = this;
834
+ list[name] = function () {
835
+ return context.echo(macro.apply(undefined, arguments));
836
+ };
837
+ }
838
+ }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "call", {
839
+ value: function value(name) {
840
+ var list = this.getMacro();
841
+ var macro = list[name];
842
+ var params = [].slice.call(arguments, 1);
843
+ if (isFunction(macro)) {
844
+ return macro.apply(macro, params);
845
+ }
846
+ }
847
+ }), "block", {
848
+ value: function value(name, callback) {
849
+ var _this = this;
850
+ var blocks = this.getBlocks();
851
+ blocks[name] = blocks[name] || [];
852
+ blocks[name].push(this.fn(callback));
853
+ if (this.getExtend()) return;
854
+ var list = Object.assign([], blocks[name]);
855
+ var current = function current() {
856
+ return list.shift();
857
+ };
858
+ var _next = function next() {
859
+ var parent = current();
860
+ if (parent) {
861
+ return function () {
862
+ _this.echo(parent(_next()));
863
+ };
864
+ } else {
865
+ return noop;
720
866
  }
721
- return result[prop] = _value2;
722
- },
723
- writable: false,
724
- configurable: false,
725
- enumerable: false
726
- }), "macro", {
727
- value: function value(name, callback) {
728
- var list = this.getMacro();
729
- var macro = this.fn(callback);
730
- var context = this;
731
- list[name] = function () {
732
- return context.echo(macro.apply(undefined, arguments));
733
- };
734
- },
735
- writable: false,
736
- configurable: false,
737
- enumerable: false
738
- }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "call", {
739
- value: function value(name) {
867
+ };
868
+ this.echo(current()(_next()));
869
+ }
870
+ }), "hasBlock", {
871
+ value: function value(name) {
872
+ return this.getBlocks().hasOwnProperty(name);
873
+ }
874
+ }), "include", {
875
+ value: function value(path, data, cx) {
876
+ var context = cx === false ? {} : this.clone(true);
877
+ var params = extend(context, data || {});
878
+ var promise = this.render(path, params);
879
+ this.echo(promise);
880
+ }
881
+ }), "promiseResolve", {
882
+ value: function value(_value3, callback) {
883
+ return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
884
+ }
885
+ }), "use", {
886
+ value: function value(path, namespace) {
887
+ this.echo(this.promiseResolve(this.require(path), function (exports) {
740
888
  var list = this.getMacro();
741
- var macro = list[name];
742
- var params = [].slice.call(arguments, 1);
743
- if (isFunction(macro)) {
744
- return macro.apply(macro, params);
745
- }
746
- },
747
- writable: false,
748
- configurable: false,
749
- enumerable: false
750
- }), "block", {
751
- value: function value(name, callback) {
752
- var _this = this;
753
- var blocks = this.getBlocks();
754
- blocks[name] = blocks[name] || [];
755
- blocks[name].push(this.fn(callback));
756
- if (this.getExtend()) return;
757
- var list = Object.assign([], blocks[name]);
758
- var current = function current() {
759
- return list.shift();
760
- };
761
- var _next = function next() {
762
- var parent = current();
763
- if (parent) {
764
- return function () {
765
- _this.echo(parent(_next()));
766
- };
767
- } else {
768
- return noop;
769
- }
770
- };
771
- this.echo(current()(_next()));
772
- },
773
- writable: false,
774
- configurable: false,
775
- enumerable: false
776
- }), "hasBlock", {
777
- value: function value(name) {
778
- return this.getBlocks().hasOwnProperty(name);
779
- },
780
- writable: false,
781
- configurable: false,
782
- enumerable: false
783
- }), "include", {
784
- value: function value(path, data, cx) {
785
- var context = cx === false ? {} : this.clone(true);
786
- var params = extend(context, data || {});
787
- var promise = this.render(path, params);
788
- this.echo(promise);
789
- },
790
- writable: false,
791
- configurable: false,
792
- enumerable: false
793
- }), "promiseResolve", {
794
- value: function value(_value3, callback) {
795
- return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
796
- },
797
- writable: false,
798
- configurable: false,
799
- enumerable: false
800
- }), "use", {
801
- value: function value(path, namespace) {
802
- this.echo(this.promiseResolve(this.require(path), function (exports) {
803
- var list = this.getMacro();
804
- each(exports, function (macro, name) {
805
- list[[namespace, name].join('.')] = macro;
806
- });
807
- }));
808
- },
809
- writable: false,
810
- configurable: false,
811
- enumerable: false
812
- }), "async", {
813
- value: function value(promise, callback) {
814
- this.echo(this.promiseResolve(promise, function (data) {
815
- return this.fn(callback)(data);
816
- }));
817
- },
818
- writable: false,
819
- configurable: false,
820
- enumerable: false
821
- }), "each", {
822
- value: function value(object, callback) {
823
- if (isString(object)) {
824
- object = this.get(object, []);
825
- }
826
- each(object, callback);
827
- },
828
- writable: false,
829
- configurable: false,
830
- enumerable: false
831
- }), "element", {
832
- value: function value(tag, attr, content) {
833
- return element(tag, attr, content);
834
- },
835
- writable: false,
836
- configurable: false,
837
- enumerable: false
838
- }), "el", {
839
- value: function value(tag, attr, content) {
840
- this.echo(this.promiseResolve(content, function (content) {
841
- return this.element(tag, attr, content);
842
- }));
843
- },
844
- writable: false,
845
- configurable: false,
846
- enumerable: false
847
- })));
848
- };
849
- this.configure(config);
850
- }
851
-
852
- function EJS(options) {
853
- if (instanceOf(this, EJS) === false) return new EJS(options);
854
- var scope = {};
855
- var config = {};
856
- configSchema(config, options || {});
857
- var context = new Context(config);
858
- var compiler = new Compiler(config);
859
- var cache = new Cache();
860
- var template = new Template(config, cache, compiler);
861
- var output = function output(path, scope) {
862
- var globalHelpers = config.globalHelpers;
863
- var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
864
- return isFunction(scope[name]);
865
- }).map(function (name) {
866
- return scope[name].bind(scope);
867
- }));
868
- return template.get(path).then(function (callback) {
869
- return callback.apply(scope, params);
870
- });
871
- };
872
- var require = function require(name) {
873
- var filepath = ext(name, config.extension);
874
- var scope = context.create({});
875
- return output(filepath, scope).then(function () {
876
- return scope.getMacro();
877
- });
878
- };
879
- var _render = function render(name, data) {
880
- var filepath = ext(name, config.extension);
881
- var scope = context.create(data);
882
- return output(filepath, scope).then(function (content) {
883
- if (scope.getExtend()) {
884
- scope.setExtend(false);
885
- var layout = scope.getLayout();
886
- var _data = scope.clone();
887
- return _render(layout, _data);
889
+ each(exports, function (macro, name) {
890
+ list[[namespace, name].join('.')] = macro;
891
+ });
892
+ }));
893
+ }
894
+ }), "async", {
895
+ value: function value(promise, callback) {
896
+ this.echo(this.promiseResolve(promise, function (data) {
897
+ return this.fn(callback)(data);
898
+ }));
899
+ }
900
+ }), "each", {
901
+ value: function value(object, callback) {
902
+ if (isString(object)) {
903
+ object = this.get(object, []);
888
904
  }
889
- return content;
905
+ each(object, callback);
906
+ }
907
+ }), "element", {
908
+ value: function value(tag, attr, content) {
909
+ return element(tag, attr, content);
910
+ }
911
+ }), "el", {
912
+ value: function value(tag, attr, content) {
913
+ this.echo(this.promiseResolve(content, function (content) {
914
+ return this.element(tag, attr, content);
915
+ }));
916
+ }
917
+ })));
918
+ return ContextScope;
919
+ };
920
+ var _scope = /*#__PURE__*/new WeakMap();
921
+ var Context = /*#__PURE__*/function () {
922
+ function Context(config, methods) {
923
+ _classCallCheck(this, Context);
924
+ _classPrivateFieldInitSpec(this, _scope, void 0);
925
+ bindContext(this, ['create', 'helpers', 'configure']);
926
+ this.configure(config, methods);
927
+ }
928
+ return _createClass(Context, [{
929
+ key: "create",
930
+ value: function create(data) {
931
+ return new (_classPrivateFieldGet2(_scope, this))(data);
932
+ }
933
+ }, {
934
+ key: "configure",
935
+ value: function configure(config, methods) {
936
+ _classPrivateFieldSet2(_scope, this, createScope(config, methods));
937
+ }
938
+ }, {
939
+ key: "helpers",
940
+ value: function helpers(methods) {
941
+ extend(_classPrivateFieldGet2(_scope, this).prototype, methods || {});
942
+ }
943
+ }]);
944
+ }();
945
+
946
+ var _config = /*#__PURE__*/new WeakMap();
947
+ var _extend = /*#__PURE__*/new WeakMap();
948
+ var _context = /*#__PURE__*/new WeakMap();
949
+ var _compiler = /*#__PURE__*/new WeakMap();
950
+ var _cache = /*#__PURE__*/new WeakMap();
951
+ var _template = /*#__PURE__*/new WeakMap();
952
+ var _EJS_brand = /*#__PURE__*/new WeakSet();
953
+ var EJS = /*#__PURE__*/function () {
954
+ function EJS(options) {
955
+ _classCallCheck(this, EJS);
956
+ _classPrivateMethodInitSpec(this, _EJS_brand);
957
+ _classPrivateFieldInitSpec(this, _config, {});
958
+ _classPrivateFieldInitSpec(this, _extend, {});
959
+ _classPrivateFieldInitSpec(this, _context, void 0);
960
+ _classPrivateFieldInitSpec(this, _compiler, void 0);
961
+ _classPrivateFieldInitSpec(this, _cache, void 0);
962
+ _classPrivateFieldInitSpec(this, _template, void 0);
963
+ configSchema(_classPrivateFieldGet2(_config, this), options || {});
964
+ _classPrivateFieldSet2(_context, this, new Context(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this)));
965
+ _classPrivateFieldSet2(_compiler, this, new Compiler(_classPrivateFieldGet2(_config, this)));
966
+ _classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
967
+ _classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
968
+ //
969
+ bindContext(this, ['configure', 'create', 'render', 'context', 'preload', 'compile', 'helpers']);
970
+ //
971
+ this.helpers({
972
+ require: _assertClassBrand(_EJS_brand, this, _require),
973
+ render: this.render
890
974
  });
891
- };
892
- this.configure = function (options) {
893
- options = options || {};
894
- configSchema(config, options);
895
- context.configure(config, scope);
896
- compiler.configure(config);
897
- cache.configure(config);
898
- template.configure(config);
899
- return config;
900
- };
901
- this.render = function (name, data) {
902
- return _render(name, data);
903
- };
904
- this.helpers = function (methods) {
905
- context.helpers(extend(scope, methods));
906
- };
907
- this.preload = function (list) {
908
- return cache.load(list || {});
909
- };
910
- this.create = function (options) {
911
- return new EJS(options);
912
- };
913
- this.compile = function (content, path) {
914
- return compiler.compile(content, path);
915
- };
916
- this.context = function (data) {
917
- return context.create(data);
918
- };
919
- this.helpers({
920
- require: require,
921
- render: _render
975
+ }
976
+ return _createClass(EJS, [{
977
+ key: "configure",
978
+ value: function configure(options) {
979
+ configSchema(_classPrivateFieldGet2(_config, this), options || {});
980
+ _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this));
981
+ _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
982
+ _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
983
+ _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
984
+ return _classPrivateFieldGet2(_config, this);
985
+ }
986
+ }, {
987
+ key: "render",
988
+ value: function render(name, data) {
989
+ var _this = this;
990
+ var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
991
+ var scope = this.context(data);
992
+ return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function (content) {
993
+ if (scope.getExtend()) {
994
+ scope.setExtend(false);
995
+ var layout = scope.getLayout();
996
+ var _data = scope.clone();
997
+ return _this.render(layout, _data);
998
+ }
999
+ return content;
1000
+ });
1001
+ }
1002
+ }, {
1003
+ key: "helpers",
1004
+ value: function helpers(methods) {
1005
+ _classPrivateFieldGet2(_context, this).helpers(extend(_classPrivateFieldGet2(_extend, this), methods));
1006
+ }
1007
+ }, {
1008
+ key: "context",
1009
+ value: function context(data) {
1010
+ return _classPrivateFieldGet2(_context, this).create(data);
1011
+ }
1012
+ }, {
1013
+ key: "compile",
1014
+ value: function compile(content, path) {
1015
+ return _classPrivateFieldGet2(_compiler, this).compile(content, path);
1016
+ }
1017
+ }, {
1018
+ key: "preload",
1019
+ value: function preload(list) {
1020
+ return _classPrivateFieldGet2(_cache, this).load(list || {});
1021
+ }
1022
+ }, {
1023
+ key: "create",
1024
+ value: function create(options) {
1025
+ return new this.constructor(options);
1026
+ }
1027
+ }]);
1028
+ }();
1029
+
1030
+ // export function EJS2(options) {
1031
+ // const self = {
1032
+ // config: {},
1033
+ // helpers: {},
1034
+ // /**
1035
+ // * @type {Context}
1036
+ // */
1037
+ // context: null,
1038
+ // /**
1039
+ // * @type {Compiler}
1040
+ // */
1041
+ // compiler: null,
1042
+ // /**
1043
+ // * @type {Template}
1044
+ // */
1045
+ // template: null,
1046
+ // /**
1047
+ // * @type {Cache}
1048
+ // */
1049
+ // cache: null,
1050
+ // }
1051
+ // /**
1052
+ // *
1053
+ // */
1054
+ // configSchema(self.config, options || {})
1055
+ // self.context = useContext(self.config, self.helpers)
1056
+ // self.compiler = useCompiler(self.config)
1057
+ // self.cache = useCache(self.config)
1058
+ // self.template = useTemplate(self.config, self.cache, self.compiler)
1059
+ // /**
1060
+ // *
1061
+ // * @param {string} path
1062
+ // * @param {ContextScope} scope
1063
+ // * @return {Promise<string>}
1064
+ // */
1065
+ // const output = (path, scope) => {
1066
+ // const { globalHelpers } = self.config
1067
+ // const params = [
1068
+ // scope,
1069
+ // scope.getComponent(),
1070
+ // scope.getBuffer(),
1071
+ // safeValue,
1072
+ // ].concat(
1073
+ // globalHelpers
1074
+ // .filter((name) => isFunction(scope[name]))
1075
+ // .map((name) => scope[name].bind(scope))
1076
+ // )
1077
+ // return self.template
1078
+ // .get(path)
1079
+ // .then((callback) => callback.apply(scope, params))
1080
+ // }
1081
+ // /**
1082
+ // *
1083
+ // * @param name
1084
+ // * @return {Promise<string>}
1085
+ // */
1086
+ // const require = (name) => {
1087
+ // const filepath = ext(name, self.config.extension)
1088
+ // const scope = context({})
1089
+ // return output(filepath, scope).then(() => scope.getMacro())
1090
+ // }
1091
+ // /**
1092
+ // *
1093
+ // * @param {string} name
1094
+ // * @param {{}} [data]
1095
+ // * @return {Promise<string>}
1096
+ // */
1097
+ // const render = (name, data) => {
1098
+ // const filepath = ext(name, self.config.extension)
1099
+ // const scope = context(data)
1100
+ // return output(filepath, scope).then((content) => {
1101
+ // if (scope.getExtend()) {
1102
+ // scope.setExtend(false)
1103
+ // const layout = scope.getLayout()
1104
+ // const data = scope.clone()
1105
+ // return render(layout, data)
1106
+ // }
1107
+ // return content
1108
+ // })
1109
+ // }
1110
+ // /**
1111
+ // *
1112
+ // * @param options
1113
+ // * @return {{}}
1114
+ // */
1115
+ // const configure = (options = {}) => {
1116
+ // configSchema(self.config, options || {})
1117
+ // self.context.configure(self.config, self.helpers)
1118
+ // self.compiler.configure(self.config)
1119
+ // self.cache.configure(self.config)
1120
+ // self.template.configure(self.config)
1121
+ // return self.config
1122
+ // }
1123
+ // /**
1124
+ // *
1125
+ // * @param methods
1126
+ // */
1127
+ // const helpers = (methods) => {
1128
+ // self.context.helpers(extend(self.helpers, methods))
1129
+ // }
1130
+ // /**
1131
+ // *
1132
+ // * @param list
1133
+ // * @return {*}
1134
+ // */
1135
+ // const preload = (list) => {
1136
+ // return self.cache.load(list || {})
1137
+ // }
1138
+ // /**
1139
+ // *
1140
+ // * @param options
1141
+ // * @return {any}
1142
+ // */
1143
+ // const create = (options) => {
1144
+ // return EJS(options)
1145
+ // }
1146
+ // /**
1147
+ // *
1148
+ // * @param content
1149
+ // * @param path
1150
+ // * @return {Function}
1151
+ // */
1152
+ // const compile = (content, path) => {
1153
+ // return self.compiler.compile(content, path)
1154
+ // }
1155
+ // /**
1156
+ // *
1157
+ // * @param data
1158
+ // * @return {ContextScope}
1159
+ // */
1160
+ // const context = (data = {}) => {
1161
+ // return self.context.create(data)
1162
+ // }
1163
+ // /**
1164
+ // *
1165
+ // */
1166
+ // helpers({ require, render })
1167
+ // /**
1168
+ // *
1169
+ // */
1170
+ // return {
1171
+ // configure,
1172
+ // helpers,
1173
+ // preload,
1174
+ // context,
1175
+ // compile,
1176
+ // create,
1177
+ // render,
1178
+ // }
1179
+ // }
1180
+ function _output(path, scope) {
1181
+ var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
1182
+ globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
1183
+ var params = [scope, scope.getComponent(), scope.getBuffer(), safeValue].concat(globalHelpers.filter(function (name) {
1184
+ return isFunction(scope[name]);
1185
+ }).map(function (name) {
1186
+ return scope[name].bind(scope);
1187
+ }));
1188
+ return _classPrivateFieldGet2(_template, this).get(path).then(function (callback) {
1189
+ return callback.apply(scope, params);
1190
+ });
1191
+ }
1192
+ function _require(name) {
1193
+ var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
1194
+ var scope = this.context({});
1195
+ return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
1196
+ return scope.getMacro();
922
1197
  });
923
- return this;
924
1198
  }
925
1199
 
926
1200
  var httpRequest = function httpRequest(path, template) {
@@ -931,16 +1205,16 @@ var httpRequest = function httpRequest(path, template) {
931
1205
  });
932
1206
  };
933
1207
 
934
- var ejs = new EJS({
935
- resolver: httpRequest
936
- });
937
- var render = ejs.render,
938
- context = ejs.context,
939
- compile = ejs.compile,
940
- helpers = ejs.helpers,
941
- preload = ejs.preload,
942
- configure = ejs.configure,
943
- create = ejs.create;
1208
+ var _EJS = new EJS({
1209
+ resolver: httpRequest
1210
+ }),
1211
+ render = _EJS.render,
1212
+ context = _EJS.context,
1213
+ compile = _EJS.compile,
1214
+ helpers = _EJS.helpers,
1215
+ preload = _EJS.preload,
1216
+ configure = _EJS.configure,
1217
+ create = _EJS.create;
944
1218
 
945
1219
  exports.TemplateError = TemplateError;
946
1220
  exports.TemplateNotFound = TemplateNotFound;