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