@kosatyi/ejs 0.0.105 → 0.0.106

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