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