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