@kosatyi/ejs 0.0.109 → 0.0.111
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 +338 -279
- package/dist/cjs/bundler.js +14 -6
- package/dist/cjs/element.js +3 -3
- package/dist/cjs/index.js +406 -350
- package/dist/cjs/worker.js +341 -298
- package/dist/esm/browser.js +138 -159
- package/dist/esm/bundler.js +14 -6
- package/dist/esm/element.js +2 -2
- package/dist/esm/index.js +258 -280
- package/dist/esm/worker.js +139 -174
- package/dist/umd/browser.js +832 -773
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/element.js +4 -4
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +853 -797
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +341 -298
- package/dist/umd/worker.min.js +1 -1
- package/package.json +4 -4
- package/types/browser.d.ts +0 -6
- package/types/context.d.ts +19 -10
- package/types/ejs.d.ts +2 -5
- package/types/element.d.ts +9 -1
- package/types/error.d.ts +11 -11
- package/types/index.d.ts +0 -2
- package/types/worker.d.ts +0 -12
- package/dist/kosatyi-ejs-0.0.107.tgz +0 -0
- package/dist/kosatyi-ejs-0.0.108.tgz +0 -0
- package/dist/umd/browser.js.map +0 -7
- package/dist/umd/browser.min.js.map +0 -7
package/dist/cjs/browser.js
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
function _assertClassBrand(e, t, n) {
|
|
4
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
5
|
+
throw new TypeError("Private element is not present on this object");
|
|
6
|
+
}
|
|
7
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
8
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
9
|
+
}
|
|
10
|
+
function _classPrivateFieldGet2(s, a) {
|
|
11
|
+
return s.get(_assertClassBrand(s, a));
|
|
12
|
+
}
|
|
13
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
14
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
15
|
+
}
|
|
16
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
17
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
18
|
+
}
|
|
19
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
20
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
21
|
+
}
|
|
22
|
+
function _defineProperty(e, r, t) {
|
|
23
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
24
|
+
value: t,
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true
|
|
28
|
+
}) : e[r] = t, e;
|
|
29
|
+
}
|
|
30
|
+
function ownKeys(e, r) {
|
|
31
|
+
var t = Object.keys(e);
|
|
32
|
+
if (Object.getOwnPropertySymbols) {
|
|
33
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
34
|
+
r && (o = o.filter(function (r) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
36
|
+
})), t.push.apply(t, o);
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
function _objectSpread2(e) {
|
|
41
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
42
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
43
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
44
|
+
_defineProperty(e, r, t[r]);
|
|
45
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
46
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return e;
|
|
50
|
+
}
|
|
51
|
+
function _toPrimitive(t, r) {
|
|
52
|
+
if ("object" != typeof t || !t) return t;
|
|
53
|
+
var e = t[Symbol.toPrimitive];
|
|
54
|
+
if (void 0 !== e) {
|
|
55
|
+
var i = e.call(t, r);
|
|
56
|
+
if ("object" != typeof i) return i;
|
|
57
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
58
|
+
}
|
|
59
|
+
return ("string" === r ? String : Number)(t);
|
|
60
|
+
}
|
|
61
|
+
function _toPropertyKey(t) {
|
|
62
|
+
var i = _toPrimitive(t, "string");
|
|
63
|
+
return "symbol" == typeof i ? i : i + "";
|
|
64
|
+
}
|
|
65
|
+
|
|
3
66
|
/**
|
|
4
67
|
* @type {EjsConfig}
|
|
5
68
|
*/
|
|
@@ -46,7 +109,7 @@ const isArrayOfVariables = value => {
|
|
|
46
109
|
if (!isArray(value)) return false;
|
|
47
110
|
return value.filter(name => {
|
|
48
111
|
const valid = jsVariableName.test(name);
|
|
49
|
-
if (valid === false) console.log(
|
|
112
|
+
if (valid === false) console.log("ejsConfig.globals: expected '".concat(name, "' to be valid variable name --> skipped"));
|
|
50
113
|
return valid;
|
|
51
114
|
});
|
|
52
115
|
};
|
|
@@ -92,7 +155,7 @@ const entities = function () {
|
|
|
92
155
|
const symbols = string => {
|
|
93
156
|
return ('' + string).replace(symbolEntitiesMatch, match => '\\' + symbolEntities[match]);
|
|
94
157
|
};
|
|
95
|
-
const
|
|
158
|
+
const escapeValue = (value, escape) => {
|
|
96
159
|
const check = value;
|
|
97
160
|
return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
|
|
98
161
|
};
|
|
@@ -125,9 +188,7 @@ const each = (object, callback) => {
|
|
|
125
188
|
}
|
|
126
189
|
};
|
|
127
190
|
const omit = (object, list) => {
|
|
128
|
-
const result = {
|
|
129
|
-
...object
|
|
130
|
-
};
|
|
191
|
+
const result = _objectSpread2({}, object);
|
|
131
192
|
for (const key of list) {
|
|
132
193
|
delete result[key];
|
|
133
194
|
}
|
|
@@ -151,48 +212,70 @@ const bindContext = function (object) {
|
|
|
151
212
|
}
|
|
152
213
|
};
|
|
153
214
|
|
|
154
|
-
class
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
215
|
+
class EjsError extends Error {
|
|
216
|
+
constructor(code, content) {
|
|
217
|
+
super(content);
|
|
218
|
+
this.code = code;
|
|
219
|
+
if (content instanceof Error) {
|
|
220
|
+
this.stack = content.stack;
|
|
221
|
+
this.message = content.message;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const error = (code, content) => {
|
|
226
|
+
throw new EjsError(code, content);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
var _path$1 = /*#__PURE__*/new WeakMap();
|
|
230
|
+
var _resolver = /*#__PURE__*/new WeakMap();
|
|
231
|
+
var _cache$2 = /*#__PURE__*/new WeakMap();
|
|
232
|
+
var _compiler$1 = /*#__PURE__*/new WeakMap();
|
|
233
|
+
var _EjsTemplate_brand = /*#__PURE__*/new WeakSet();
|
|
234
|
+
class EjsTemplate {
|
|
160
235
|
constructor(options, cache, compiler) {
|
|
236
|
+
_classPrivateMethodInitSpec(this, _EjsTemplate_brand);
|
|
237
|
+
_classPrivateFieldInitSpec(this, _path$1, void 0);
|
|
238
|
+
_classPrivateFieldInitSpec(this, _resolver, void 0);
|
|
239
|
+
_classPrivateFieldInitSpec(this, _cache$2, void 0);
|
|
240
|
+
_classPrivateFieldInitSpec(this, _compiler$1, void 0);
|
|
161
241
|
bindContext(this, this.constructor.exports);
|
|
162
|
-
this
|
|
163
|
-
this
|
|
164
|
-
this.configure(options
|
|
242
|
+
_classPrivateFieldSet2(_cache$2, this, cache);
|
|
243
|
+
_classPrivateFieldSet2(_compiler$1, this, compiler);
|
|
244
|
+
this.configure(options !== null && options !== void 0 ? options : {});
|
|
165
245
|
}
|
|
166
246
|
configure(options) {
|
|
167
|
-
this
|
|
247
|
+
_classPrivateFieldSet2(_path$1, this, options.path);
|
|
168
248
|
if (isFunction(options.resolver)) {
|
|
169
|
-
this
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
#resolve(template) {
|
|
173
|
-
const cached = this.#cache.get(template);
|
|
174
|
-
if (cached instanceof Promise) return cached;
|
|
175
|
-
const result = Promise.resolve(this.#resolver(this.#path, template));
|
|
176
|
-
this.#cache.set(template, result);
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
|
-
compile(content, template) {
|
|
180
|
-
const cached = this.#cache.get(template);
|
|
181
|
-
if (typeof cached === 'function') return cached;
|
|
182
|
-
if (typeof content === 'string') {
|
|
183
|
-
content = this.#compiler.compile(content, template);
|
|
184
|
-
}
|
|
185
|
-
if (typeof content === 'function') {
|
|
186
|
-
this.#cache.set(template, content);
|
|
187
|
-
return content;
|
|
249
|
+
_classPrivateFieldSet2(_resolver, this, options.resolver);
|
|
188
250
|
}
|
|
189
251
|
}
|
|
190
252
|
get(template) {
|
|
191
|
-
return this
|
|
253
|
+
return _assertClassBrand(_EjsTemplate_brand, this, _resolve).call(this, template).then(content => {
|
|
254
|
+
return _assertClassBrand(_EjsTemplate_brand, this, _compile).call(this, content, template);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function _resolve(template) {
|
|
259
|
+
const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
|
|
260
|
+
if (cached instanceof Promise) return cached;
|
|
261
|
+
const result = Promise.resolve(_classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path$1, this), template, error));
|
|
262
|
+
_classPrivateFieldGet2(_cache$2, this).set(template, result);
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
function _compile(content, template) {
|
|
266
|
+
const cached = _classPrivateFieldGet2(_cache$2, this).get(template);
|
|
267
|
+
if (typeof cached === 'function') return cached;
|
|
268
|
+
if (typeof content === 'string') {
|
|
269
|
+
content = _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
|
|
270
|
+
}
|
|
271
|
+
if (typeof content === 'function') {
|
|
272
|
+
_classPrivateFieldGet2(_cache$2, this).set(template, content);
|
|
273
|
+
return content;
|
|
192
274
|
}
|
|
193
275
|
}
|
|
276
|
+
_defineProperty(EjsTemplate, "exports", ['configure', 'get']);
|
|
194
277
|
|
|
195
|
-
const tokenList = [['-', (v, b, s) =>
|
|
278
|
+
const tokenList = [['-', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, ",1))\n").concat(b, "('")], ['=', (v, b, s) => "')\n".concat(b, "(").concat(s, "(").concat(v, "))\n").concat(b, "('")], ['#', (v, b) => "')\n/**".concat(v, "**/\n").concat(b, "('")], ['', (v, b) => "')\n".concat(v, "\n").concat(b, "('")]];
|
|
196
279
|
const tokensMatch = (regex, content, callback) => {
|
|
197
280
|
let index = 0;
|
|
198
281
|
content.replace(regex, function () {
|
|
@@ -204,133 +287,138 @@ const tokensMatch = (regex, content, callback) => {
|
|
|
204
287
|
return match;
|
|
205
288
|
});
|
|
206
289
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
static exports = ['compile'];
|
|
290
|
+
var _config$1 = /*#__PURE__*/new WeakMap();
|
|
291
|
+
class EjsCompiler {
|
|
210
292
|
constructor(options) {
|
|
293
|
+
_classPrivateFieldInitSpec(this, _config$1, {});
|
|
211
294
|
bindContext(this, this.constructor.exports);
|
|
212
295
|
this.configure(options);
|
|
213
296
|
}
|
|
214
297
|
configure(options) {
|
|
215
|
-
|
|
216
|
-
this
|
|
217
|
-
this
|
|
218
|
-
this
|
|
219
|
-
this
|
|
220
|
-
this
|
|
221
|
-
this
|
|
298
|
+
var _options$legacy;
|
|
299
|
+
_classPrivateFieldGet2(_config$1, this).strict = options.strict;
|
|
300
|
+
_classPrivateFieldGet2(_config$1, this).rmWhitespace = options.rmWhitespace;
|
|
301
|
+
_classPrivateFieldGet2(_config$1, this).token = options.token;
|
|
302
|
+
_classPrivateFieldGet2(_config$1, this).vars = options.vars;
|
|
303
|
+
_classPrivateFieldGet2(_config$1, this).globals = options.globals;
|
|
304
|
+
_classPrivateFieldGet2(_config$1, this).legacy = (_options$legacy = options.legacy) !== null && _options$legacy !== void 0 ? _options$legacy : true;
|
|
305
|
+
_classPrivateFieldGet2(_config$1, this).slurp = {
|
|
222
306
|
match: '[s\t\n]*',
|
|
223
|
-
start: [this
|
|
224
|
-
end: ['_', this
|
|
307
|
+
start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
|
|
308
|
+
end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
|
|
225
309
|
};
|
|
226
|
-
this
|
|
227
|
-
this
|
|
310
|
+
_classPrivateFieldGet2(_config$1, this).matches = [];
|
|
311
|
+
_classPrivateFieldGet2(_config$1, this).formats = [];
|
|
228
312
|
for (const [symbol, format] of tokenList) {
|
|
229
|
-
this
|
|
230
|
-
this
|
|
313
|
+
_classPrivateFieldGet2(_config$1, this).matches.push(_classPrivateFieldGet2(_config$1, this).token.start.concat(symbol).concat(_classPrivateFieldGet2(_config$1, this).token.regex).concat(_classPrivateFieldGet2(_config$1, this).token.end));
|
|
314
|
+
_classPrivateFieldGet2(_config$1, this).formats.push(format);
|
|
231
315
|
}
|
|
232
|
-
this
|
|
233
|
-
this
|
|
234
|
-
this
|
|
235
|
-
if (this
|
|
236
|
-
if (this
|
|
237
|
-
this
|
|
316
|
+
_classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
|
|
317
|
+
_classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
|
|
318
|
+
_classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
|
|
319
|
+
if (_classPrivateFieldGet2(_config$1, this).globals.length) {
|
|
320
|
+
if (_classPrivateFieldGet2(_config$1, this).legacy) {
|
|
321
|
+
_classPrivateFieldGet2(_config$1, this).globalVariables = "const ".concat(_classPrivateFieldGet2(_config$1, this).globals.map(name => "".concat(name, "=").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ".").concat(name)).join(','), ";");
|
|
238
322
|
} else {
|
|
239
|
-
this
|
|
323
|
+
_classPrivateFieldGet2(_config$1, this).globalVariables = "const {".concat(_classPrivateFieldGet2(_config$1, this).globals.join(','), "} = ").concat(_classPrivateFieldGet2(_config$1, this).vars.SCOPE, ";");
|
|
240
324
|
}
|
|
241
325
|
}
|
|
242
326
|
}
|
|
243
327
|
compile(content, path) {
|
|
244
|
-
const GLOBALS = this
|
|
328
|
+
const GLOBALS = _classPrivateFieldGet2(_config$1, this).globalVariables;
|
|
245
329
|
const {
|
|
246
330
|
SCOPE,
|
|
247
331
|
SAFE,
|
|
248
332
|
BUFFER,
|
|
249
333
|
COMPONENT,
|
|
250
334
|
ELEMENT
|
|
251
|
-
} = this
|
|
252
|
-
if (this
|
|
335
|
+
} = _classPrivateFieldGet2(_config$1, this).vars;
|
|
336
|
+
if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
|
|
253
337
|
content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
254
338
|
}
|
|
255
|
-
content = String(content).replace(this
|
|
256
|
-
let OUTPUT =
|
|
257
|
-
tokensMatch(this
|
|
339
|
+
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);
|
|
340
|
+
let OUTPUT = "".concat(BUFFER, "('");
|
|
341
|
+
tokensMatch(_classPrivateFieldGet2(_config$1, this).regex, content, (params, index, offset) => {
|
|
258
342
|
OUTPUT += symbols(content.slice(index, offset));
|
|
259
343
|
params.forEach((value, index) => {
|
|
260
344
|
if (value) {
|
|
261
|
-
OUTPUT += this
|
|
345
|
+
OUTPUT += _classPrivateFieldGet2(_config$1, this).formats[index](value.trim(), BUFFER, SAFE);
|
|
262
346
|
}
|
|
263
347
|
});
|
|
264
348
|
});
|
|
265
|
-
OUTPUT +=
|
|
266
|
-
OUTPUT =
|
|
267
|
-
if (this
|
|
268
|
-
OUTPUT =
|
|
349
|
+
OUTPUT += "');";
|
|
350
|
+
OUTPUT = "try{".concat(OUTPUT, "}catch(e){return ").concat(BUFFER, ".error(e)}");
|
|
351
|
+
if (_classPrivateFieldGet2(_config$1, this).strict === false) {
|
|
352
|
+
OUTPUT = "with(".concat(SCOPE, "){").concat(OUTPUT, "}");
|
|
269
353
|
}
|
|
270
|
-
OUTPUT =
|
|
271
|
-
OUTPUT +=
|
|
354
|
+
OUTPUT = "".concat(BUFFER, ".start();").concat(OUTPUT, "return ").concat(BUFFER, ".end();");
|
|
355
|
+
OUTPUT += "\n//# sourceURL=".concat(path);
|
|
272
356
|
if (GLOBALS) {
|
|
273
|
-
OUTPUT =
|
|
357
|
+
OUTPUT = "".concat(GLOBALS, "\n").concat(OUTPUT);
|
|
274
358
|
}
|
|
275
359
|
try {
|
|
276
360
|
const params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE];
|
|
277
361
|
const result = Function.apply(null, params.concat(OUTPUT));
|
|
278
|
-
result.source =
|
|
362
|
+
result.source = "(function(".concat(params.join(','), "){\n").concat(OUTPUT, "\n});");
|
|
279
363
|
return result;
|
|
280
|
-
} catch (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
364
|
+
} catch (e) {
|
|
365
|
+
e.filename = path;
|
|
366
|
+
e.source = OUTPUT;
|
|
367
|
+
error(0, e);
|
|
284
368
|
}
|
|
285
369
|
}
|
|
286
370
|
}
|
|
371
|
+
_defineProperty(EjsCompiler, "exports", ['configure', 'compile']);
|
|
287
372
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
#list = {};
|
|
373
|
+
var _cache$1 = /*#__PURE__*/new WeakMap();
|
|
374
|
+
var _precompiled = /*#__PURE__*/new WeakMap();
|
|
375
|
+
var _list = /*#__PURE__*/new WeakMap();
|
|
376
|
+
class EjsCache {
|
|
293
377
|
constructor(options) {
|
|
378
|
+
_classPrivateFieldInitSpec(this, _cache$1, true);
|
|
379
|
+
_classPrivateFieldInitSpec(this, _precompiled, void 0);
|
|
380
|
+
_classPrivateFieldInitSpec(this, _list, {});
|
|
294
381
|
bindContext(this, this.constructor.exports);
|
|
295
382
|
this.configure(options);
|
|
296
383
|
}
|
|
297
384
|
get(key) {
|
|
298
|
-
if (this
|
|
299
|
-
return this
|
|
385
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
386
|
+
return _classPrivateFieldGet2(_list, this)[key];
|
|
300
387
|
}
|
|
301
388
|
}
|
|
302
389
|
set(key, value) {
|
|
303
|
-
if (this
|
|
304
|
-
this
|
|
390
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
391
|
+
_classPrivateFieldGet2(_list, this)[key] = value;
|
|
305
392
|
}
|
|
306
393
|
}
|
|
307
394
|
exist(key) {
|
|
308
|
-
if (this
|
|
309
|
-
return this
|
|
395
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
396
|
+
return _classPrivateFieldGet2(_list, this).hasOwnProperty(key);
|
|
310
397
|
}
|
|
311
398
|
}
|
|
312
399
|
clear() {
|
|
313
|
-
Object.keys(this
|
|
400
|
+
Object.keys(_classPrivateFieldGet2(_list, this)).forEach(this.remove);
|
|
314
401
|
}
|
|
315
402
|
remove(key) {
|
|
316
|
-
delete this
|
|
403
|
+
delete _classPrivateFieldGet2(_list, this)[key];
|
|
317
404
|
}
|
|
318
405
|
resolve(key) {
|
|
319
406
|
return Promise.resolve(this.get(key));
|
|
320
407
|
}
|
|
321
408
|
load(data) {
|
|
322
|
-
if (this
|
|
323
|
-
Object.assign(this
|
|
409
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
410
|
+
Object.assign(_classPrivateFieldGet2(_list, this), data || {});
|
|
324
411
|
}
|
|
325
412
|
}
|
|
326
413
|
configure(options) {
|
|
327
|
-
this
|
|
328
|
-
this
|
|
414
|
+
_classPrivateFieldSet2(_cache$1, this, options.cache);
|
|
415
|
+
_classPrivateFieldSet2(_precompiled, this, options.precompiled);
|
|
329
416
|
if (typeof window === 'object') {
|
|
330
|
-
this.load(window[this
|
|
417
|
+
this.load(window[_classPrivateFieldGet2(_precompiled, this)]);
|
|
331
418
|
}
|
|
332
419
|
}
|
|
333
420
|
}
|
|
421
|
+
_defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
|
|
334
422
|
|
|
335
423
|
const selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
336
424
|
const space = ' ';
|
|
@@ -348,7 +436,7 @@ const eachAttribute = _ref => {
|
|
|
348
436
|
const element = (tag, attrs, content) => {
|
|
349
437
|
const result = [];
|
|
350
438
|
const hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
351
|
-
const attributes = Object.entries(attrs
|
|
439
|
+
const attributes = Object.entries(attrs !== null && attrs !== void 0 ? attrs : {}).map(eachAttribute).filter(e => e).join(space);
|
|
352
440
|
result.push([lt, tag, space, attributes, gt].join(''));
|
|
353
441
|
if (content && hasClosedTag) {
|
|
354
442
|
result.push(Array.isArray(content) ? content.join('') : content);
|
|
@@ -359,31 +447,11 @@ const element = (tag, attrs, content) => {
|
|
|
359
447
|
return result.join('');
|
|
360
448
|
};
|
|
361
449
|
|
|
362
|
-
class TemplateError extends Error {
|
|
363
|
-
name = 'TemplateError';
|
|
364
|
-
constructor(error) {
|
|
365
|
-
super(error);
|
|
366
|
-
if (error instanceof Error) {
|
|
367
|
-
this.stack = error.stack;
|
|
368
|
-
this.filename = error.filename;
|
|
369
|
-
this.lineno = error.lineno;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
class TemplateNotFound extends TemplateError {
|
|
374
|
-
name = 'TemplateNotFound';
|
|
375
|
-
code = 404;
|
|
376
|
-
}
|
|
377
|
-
class TemplateSyntaxError extends TemplateError {
|
|
378
|
-
name = 'TemplateSyntaxError';
|
|
379
|
-
code = 500;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
450
|
const resolve = list => {
|
|
383
|
-
return Promise.all(list || []).then(list => list.join('')).catch(e => e);
|
|
451
|
+
return Promise.all(list || []).then(list => list.join('')).catch(e => error(0, e));
|
|
384
452
|
};
|
|
385
|
-
const reject =
|
|
386
|
-
return Promise.reject(
|
|
453
|
+
const reject = e => {
|
|
454
|
+
return Promise.reject(error(0, e));
|
|
387
455
|
};
|
|
388
456
|
const EjsBuffer = () => {
|
|
389
457
|
let store = [];
|
|
@@ -408,7 +476,7 @@ const EjsBuffer = () => {
|
|
|
408
476
|
array = store.pop();
|
|
409
477
|
return resolve(result);
|
|
410
478
|
};
|
|
411
|
-
EjsBuffer.error =
|
|
479
|
+
EjsBuffer.error = e => {
|
|
412
480
|
return reject(e);
|
|
413
481
|
};
|
|
414
482
|
EjsBuffer.end = () => {
|
|
@@ -419,6 +487,7 @@ const EjsBuffer = () => {
|
|
|
419
487
|
|
|
420
488
|
const PARENT = Symbol('EjsContext.parentTemplate');
|
|
421
489
|
const createContext$1 = (config, methods) => {
|
|
490
|
+
const globals = config.globals || [];
|
|
422
491
|
const {
|
|
423
492
|
BLOCKS,
|
|
424
493
|
MACRO,
|
|
@@ -430,130 +499,113 @@ const createContext$1 = (config, methods) => {
|
|
|
430
499
|
COMPONENT,
|
|
431
500
|
ELEMENT
|
|
432
501
|
} = config.vars;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
Object.entries(methods).forEach(_ref => {
|
|
441
|
-
let [name, value] = _ref;
|
|
442
|
-
if (isFunction(value) && globals.includes(name)) {
|
|
443
|
-
value = value.bind(EjsContext.prototype);
|
|
502
|
+
class Context {
|
|
503
|
+
constructor(data) {
|
|
504
|
+
this[PARENT] = null;
|
|
505
|
+
this[BLOCKS] = {};
|
|
506
|
+
this[MACRO] = {};
|
|
507
|
+
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
444
508
|
}
|
|
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
|
-
Object.defineProperties(EjsContext.prototype, {
|
|
471
|
-
/** @type {function} */
|
|
509
|
+
}
|
|
510
|
+
Object.defineProperties(Context.prototype, {
|
|
511
|
+
[BUFFER]: {
|
|
512
|
+
value: EjsBuffer()
|
|
513
|
+
},
|
|
514
|
+
[BLOCKS]: {
|
|
515
|
+
value: {},
|
|
516
|
+
writable: true
|
|
517
|
+
},
|
|
518
|
+
[MACRO]: {
|
|
519
|
+
value: {},
|
|
520
|
+
writable: true
|
|
521
|
+
},
|
|
522
|
+
[LAYOUT]: {
|
|
523
|
+
value: false,
|
|
524
|
+
writable: true
|
|
525
|
+
},
|
|
526
|
+
[EXTEND]: {
|
|
527
|
+
value: false,
|
|
528
|
+
writable: true
|
|
529
|
+
},
|
|
530
|
+
[PARENT]: {
|
|
531
|
+
value: null,
|
|
532
|
+
writable: true
|
|
533
|
+
},
|
|
472
534
|
setParentTemplate: {
|
|
473
535
|
value(value) {
|
|
474
536
|
this[PARENT] = value;
|
|
475
537
|
return this;
|
|
476
538
|
}
|
|
477
539
|
},
|
|
478
|
-
/** @type {function} */
|
|
479
540
|
getParentTemplate: {
|
|
480
541
|
value() {
|
|
481
542
|
return this[PARENT];
|
|
482
543
|
}
|
|
483
544
|
},
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
545
|
+
useEscapeValue: {
|
|
546
|
+
value() {
|
|
547
|
+
return escapeValue;
|
|
548
|
+
}
|
|
487
549
|
},
|
|
488
|
-
/** @type {function} */
|
|
489
550
|
useComponent: {
|
|
490
|
-
|
|
551
|
+
value() {
|
|
491
552
|
if (isFunction(this[COMPONENT])) {
|
|
492
553
|
return this[COMPONENT].bind(this);
|
|
493
554
|
} else {
|
|
494
|
-
return ()
|
|
495
|
-
|
|
555
|
+
return function () {
|
|
556
|
+
error(2, "".concat(COMPONENT, " must be a function"));
|
|
496
557
|
};
|
|
497
558
|
}
|
|
498
559
|
}
|
|
499
560
|
},
|
|
500
|
-
/** @type {function} */
|
|
501
561
|
useElement: {
|
|
502
|
-
|
|
562
|
+
value() {
|
|
503
563
|
if (isFunction(this[ELEMENT])) {
|
|
504
564
|
return this[ELEMENT].bind(this);
|
|
505
565
|
} else {
|
|
506
566
|
return () => {
|
|
507
|
-
|
|
567
|
+
error(2, "".concat(ELEMENT, " must be a function"));
|
|
508
568
|
};
|
|
509
569
|
}
|
|
510
570
|
}
|
|
511
571
|
},
|
|
512
|
-
/** @type {function} */
|
|
513
572
|
useBuffer: {
|
|
514
|
-
|
|
573
|
+
value() {
|
|
515
574
|
return this[BUFFER];
|
|
516
575
|
}
|
|
517
576
|
},
|
|
518
|
-
/** @type {function} */
|
|
519
577
|
getMacro: {
|
|
520
578
|
value() {
|
|
521
579
|
return this[MACRO];
|
|
522
580
|
}
|
|
523
581
|
},
|
|
524
|
-
/** @type {function} */
|
|
525
582
|
getBlocks: {
|
|
526
583
|
value() {
|
|
527
584
|
return this[BLOCKS];
|
|
528
585
|
}
|
|
529
586
|
},
|
|
530
|
-
/** @type {function} */
|
|
531
587
|
setExtend: {
|
|
532
588
|
value(value) {
|
|
533
589
|
this[EXTEND] = value;
|
|
534
590
|
return this;
|
|
535
591
|
}
|
|
536
592
|
},
|
|
537
|
-
/** @type {function} */
|
|
538
593
|
getExtend: {
|
|
539
594
|
value() {
|
|
540
595
|
return this[EXTEND];
|
|
541
596
|
}
|
|
542
597
|
},
|
|
543
|
-
/** @type {function} */
|
|
544
598
|
setLayout: {
|
|
545
599
|
value(layout) {
|
|
546
600
|
this[LAYOUT] = layout;
|
|
547
601
|
return this;
|
|
548
602
|
}
|
|
549
603
|
},
|
|
550
|
-
/** @type {function} */
|
|
551
604
|
getLayout: {
|
|
552
605
|
value() {
|
|
553
606
|
return this[LAYOUT];
|
|
554
607
|
}
|
|
555
608
|
},
|
|
556
|
-
/** @type {function} */
|
|
557
609
|
clone: {
|
|
558
610
|
value(exclude_blocks) {
|
|
559
611
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
@@ -563,32 +615,30 @@ const createContext$1 = (config, methods) => {
|
|
|
563
615
|
return omit(this, filter);
|
|
564
616
|
}
|
|
565
617
|
},
|
|
566
|
-
/** @type {function} */
|
|
567
618
|
extend: {
|
|
568
619
|
value(layout) {
|
|
569
620
|
this.setExtend(true);
|
|
570
621
|
this.setLayout(layout);
|
|
571
622
|
}
|
|
572
623
|
},
|
|
573
|
-
/** @type {function} */
|
|
574
624
|
echo: {
|
|
575
625
|
value() {
|
|
576
|
-
return [].slice.call(arguments).forEach(this.useBuffer);
|
|
626
|
+
return [].slice.call(arguments).forEach(this.useBuffer());
|
|
577
627
|
}
|
|
578
628
|
},
|
|
579
|
-
/** @type {function} */
|
|
580
629
|
fn: {
|
|
581
630
|
value(callback) {
|
|
582
|
-
|
|
631
|
+
const buffer = this.useBuffer();
|
|
632
|
+
const context = this;
|
|
633
|
+
return function () {
|
|
583
634
|
if (isFunction(callback)) {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return
|
|
635
|
+
buffer.backup();
|
|
636
|
+
buffer(callback.apply(context, arguments));
|
|
637
|
+
return buffer.restore();
|
|
587
638
|
}
|
|
588
639
|
};
|
|
589
640
|
}
|
|
590
641
|
},
|
|
591
|
-
/** @type {function} */
|
|
592
642
|
macro: {
|
|
593
643
|
value(name, callback) {
|
|
594
644
|
const list = this.getMacro();
|
|
@@ -599,7 +649,6 @@ const createContext$1 = (config, methods) => {
|
|
|
599
649
|
};
|
|
600
650
|
}
|
|
601
651
|
},
|
|
602
|
-
/** @type {function} */
|
|
603
652
|
call: {
|
|
604
653
|
value(name) {
|
|
605
654
|
const list = this.getMacro();
|
|
@@ -610,35 +659,35 @@ const createContext$1 = (config, methods) => {
|
|
|
610
659
|
}
|
|
611
660
|
}
|
|
612
661
|
},
|
|
613
|
-
/** @type {function} */
|
|
614
662
|
block: {
|
|
615
663
|
value(name, callback) {
|
|
616
664
|
const blocks = this.getBlocks();
|
|
617
665
|
blocks[name] = blocks[name] || [];
|
|
618
666
|
blocks[name].push(this.fn(callback));
|
|
619
667
|
if (this.getExtend()) return;
|
|
668
|
+
const context = this;
|
|
620
669
|
const list = Object.assign([], blocks[name]);
|
|
621
|
-
const shift = ()
|
|
622
|
-
|
|
670
|
+
const shift = function () {
|
|
671
|
+
return list.shift();
|
|
672
|
+
};
|
|
673
|
+
const next = function () {
|
|
623
674
|
const parent = shift();
|
|
624
675
|
if (parent) {
|
|
625
|
-
return ()
|
|
626
|
-
|
|
676
|
+
return function () {
|
|
677
|
+
context.echo(parent(next()));
|
|
627
678
|
};
|
|
628
679
|
} else {
|
|
629
|
-
return ()
|
|
680
|
+
return function () {};
|
|
630
681
|
}
|
|
631
682
|
};
|
|
632
683
|
this.echo(shift()(next()));
|
|
633
684
|
}
|
|
634
685
|
},
|
|
635
|
-
/** @type {function} */
|
|
636
686
|
hasBlock: {
|
|
637
687
|
value(name) {
|
|
638
688
|
return this.getBlocks().hasOwnProperty(name);
|
|
639
689
|
}
|
|
640
690
|
},
|
|
641
|
-
/** @type {function} */
|
|
642
691
|
include: {
|
|
643
692
|
value(path, data, cx) {
|
|
644
693
|
const context = cx === false ? {} : this.clone(true);
|
|
@@ -647,7 +696,6 @@ const createContext$1 = (config, methods) => {
|
|
|
647
696
|
this.echo(promise);
|
|
648
697
|
}
|
|
649
698
|
},
|
|
650
|
-
/** @type {function} */
|
|
651
699
|
use: {
|
|
652
700
|
value(path, namespace) {
|
|
653
701
|
this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
|
|
@@ -658,13 +706,6 @@ const createContext$1 = (config, methods) => {
|
|
|
658
706
|
}));
|
|
659
707
|
}
|
|
660
708
|
},
|
|
661
|
-
/** @type {function} */
|
|
662
|
-
async: {
|
|
663
|
-
value(promise, callback) {
|
|
664
|
-
this.echo(Promise.resolve(promise).then(callback));
|
|
665
|
-
}
|
|
666
|
-
},
|
|
667
|
-
/** @type {function} */
|
|
668
709
|
get: {
|
|
669
710
|
value(name, defaults) {
|
|
670
711
|
const path = getPath(this, name, true);
|
|
@@ -673,7 +714,6 @@ const createContext$1 = (config, methods) => {
|
|
|
673
714
|
return hasProp(result, prop) ? result[prop] : defaults;
|
|
674
715
|
}
|
|
675
716
|
},
|
|
676
|
-
/** @type {function} */
|
|
677
717
|
set: {
|
|
678
718
|
value(name, value) {
|
|
679
719
|
const path = getPath(this, name, false);
|
|
@@ -685,7 +725,6 @@ const createContext$1 = (config, methods) => {
|
|
|
685
725
|
return result[prop] = value;
|
|
686
726
|
}
|
|
687
727
|
},
|
|
688
|
-
/** @type {function} */
|
|
689
728
|
each: {
|
|
690
729
|
value(object, callback) {
|
|
691
730
|
if (isString(object)) {
|
|
@@ -695,7 +734,6 @@ const createContext$1 = (config, methods) => {
|
|
|
695
734
|
},
|
|
696
735
|
writable: true
|
|
697
736
|
},
|
|
698
|
-
/** @type {function} */
|
|
699
737
|
el: {
|
|
700
738
|
value(tag, attr, content) {
|
|
701
739
|
content = isFunction(content) ? this.fn(content)() : content;
|
|
@@ -703,49 +741,75 @@ const createContext$1 = (config, methods) => {
|
|
|
703
741
|
},
|
|
704
742
|
writable: true
|
|
705
743
|
},
|
|
706
|
-
/** @type {function} */
|
|
707
744
|
ui: {
|
|
708
|
-
value(
|
|
745
|
+
value() {},
|
|
746
|
+
writable: true
|
|
747
|
+
},
|
|
748
|
+
require: {
|
|
749
|
+
value() {},
|
|
750
|
+
writable: true
|
|
751
|
+
},
|
|
752
|
+
render: {
|
|
753
|
+
value() {},
|
|
709
754
|
writable: true
|
|
710
755
|
}
|
|
711
756
|
});
|
|
712
|
-
|
|
757
|
+
Object.entries(methods).forEach(_ref => {
|
|
758
|
+
let [name, value] = _ref;
|
|
759
|
+
if (isFunction(value) && globals.includes(name)) {
|
|
760
|
+
value = value.bind(Context.prototype);
|
|
761
|
+
}
|
|
762
|
+
Context.prototype[name] = value;
|
|
763
|
+
});
|
|
764
|
+
return Context;
|
|
713
765
|
};
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
static exports = ['create', 'globals', 'helpers'];
|
|
766
|
+
var _context$1 = /*#__PURE__*/new WeakMap();
|
|
767
|
+
class EjsContext {
|
|
717
768
|
constructor(options, methods) {
|
|
769
|
+
_classPrivateFieldInitSpec(this, _context$1, void 0);
|
|
718
770
|
bindContext(this, this.constructor.exports);
|
|
719
771
|
this.configure(options, methods);
|
|
720
772
|
}
|
|
721
773
|
create(data) {
|
|
722
|
-
return new this
|
|
774
|
+
return new (_classPrivateFieldGet2(_context$1, this))(data);
|
|
723
775
|
}
|
|
724
776
|
helpers(methods) {
|
|
725
|
-
Object.assign(this
|
|
777
|
+
Object.assign(_classPrivateFieldGet2(_context$1, this).prototype, methods);
|
|
726
778
|
}
|
|
727
779
|
configure(options, methods) {
|
|
728
|
-
this
|
|
780
|
+
_classPrivateFieldSet2(_context$1, this, createContext$1(options, methods));
|
|
729
781
|
}
|
|
730
782
|
}
|
|
783
|
+
_defineProperty(EjsContext, "exports", ['create', 'globals', 'helpers']);
|
|
731
784
|
|
|
785
|
+
var _cache = /*#__PURE__*/new WeakMap();
|
|
786
|
+
var _context = /*#__PURE__*/new WeakMap();
|
|
787
|
+
var _compiler = /*#__PURE__*/new WeakMap();
|
|
788
|
+
var _template = /*#__PURE__*/new WeakMap();
|
|
789
|
+
var _config = /*#__PURE__*/new WeakMap();
|
|
790
|
+
var _methods = /*#__PURE__*/new WeakMap();
|
|
791
|
+
var _EjsInstance_brand = /*#__PURE__*/new WeakSet();
|
|
732
792
|
class EjsInstance {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
#config = {};
|
|
738
|
-
#methods = {};
|
|
739
|
-
static exports = ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers'];
|
|
793
|
+
/**
|
|
794
|
+
*
|
|
795
|
+
* @param {EjsConfig} options
|
|
796
|
+
*/
|
|
740
797
|
constructor() {
|
|
741
798
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
799
|
+
_classPrivateMethodInitSpec(this, _EjsInstance_brand);
|
|
800
|
+
_classPrivateFieldInitSpec(this, _cache, void 0);
|
|
801
|
+
_classPrivateFieldInitSpec(this, _context, void 0);
|
|
802
|
+
_classPrivateFieldInitSpec(this, _compiler, void 0);
|
|
803
|
+
_classPrivateFieldInitSpec(this, _template, void 0);
|
|
804
|
+
_classPrivateFieldInitSpec(this, _config, {});
|
|
805
|
+
_classPrivateFieldInitSpec(this, _methods, {});
|
|
742
806
|
bindContext(this, this.constructor.exports);
|
|
743
|
-
this
|
|
744
|
-
this
|
|
745
|
-
this
|
|
746
|
-
this
|
|
747
|
-
this
|
|
748
|
-
this
|
|
807
|
+
_classPrivateFieldSet2(_methods, this, {});
|
|
808
|
+
_classPrivateFieldSet2(_config, this, configSchema({}, options));
|
|
809
|
+
_classPrivateFieldSet2(_context, this, new EjsContext(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this)));
|
|
810
|
+
_classPrivateFieldSet2(_compiler, this, new EjsCompiler(_classPrivateFieldGet2(_config, this)));
|
|
811
|
+
_classPrivateFieldSet2(_cache, this, new EjsCache(_classPrivateFieldGet2(_config, this)));
|
|
812
|
+
_classPrivateFieldSet2(_template, this, new EjsTemplate(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
|
|
749
813
|
this.helpers({
|
|
750
814
|
render: this.render,
|
|
751
815
|
require: this.require
|
|
@@ -756,84 +820,79 @@ class EjsInstance {
|
|
|
756
820
|
}
|
|
757
821
|
configure(options) {
|
|
758
822
|
if (options) {
|
|
759
|
-
configSchema(this
|
|
760
|
-
this
|
|
761
|
-
this
|
|
762
|
-
this
|
|
763
|
-
this
|
|
823
|
+
configSchema(_classPrivateFieldGet2(_config, this), options);
|
|
824
|
+
_classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_methods, this));
|
|
825
|
+
_classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
|
|
826
|
+
_classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
|
|
827
|
+
_classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
|
|
764
828
|
}
|
|
765
|
-
return this
|
|
829
|
+
return _classPrivateFieldGet2(_config, this);
|
|
766
830
|
}
|
|
767
831
|
createContext(data) {
|
|
768
|
-
return this
|
|
832
|
+
return _classPrivateFieldGet2(_context, this).create(data);
|
|
769
833
|
}
|
|
770
834
|
preload(list) {
|
|
771
|
-
return this
|
|
835
|
+
return _classPrivateFieldGet2(_cache, this).load(list || {});
|
|
772
836
|
}
|
|
773
837
|
compile(content, path) {
|
|
774
|
-
return this
|
|
838
|
+
return _classPrivateFieldGet2(_compiler, this).compile(content, path);
|
|
775
839
|
}
|
|
776
840
|
helpers(methods) {
|
|
777
|
-
this
|
|
841
|
+
_classPrivateFieldGet2(_context, this).helpers(Object.assign(_classPrivateFieldGet2(_methods, this), methods));
|
|
778
842
|
}
|
|
779
843
|
async render(name, params) {
|
|
780
844
|
const data = this.createContext(params);
|
|
781
|
-
return this
|
|
845
|
+
return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
|
|
782
846
|
}
|
|
783
847
|
async require(name) {
|
|
784
848
|
const data = this.createContext({});
|
|
785
|
-
return this
|
|
786
|
-
}
|
|
787
|
-
#path(name) {
|
|
788
|
-
const ext = name.split('.').pop();
|
|
789
|
-
if (ext !== this.#config.extension) {
|
|
790
|
-
name = [name, this.#config.extension].join('.');
|
|
791
|
-
}
|
|
792
|
-
return name;
|
|
849
|
+
return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(() => data.getMacro());
|
|
793
850
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
if (parentTemplate) data.setParentTemplate(parentTemplate);
|
|
800
|
-
return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
|
|
801
|
-
}
|
|
802
|
-
#outputContent(name, data) {
|
|
803
|
-
return content => {
|
|
804
|
-
if (data.getExtend()) {
|
|
805
|
-
data.setExtend(false);
|
|
806
|
-
return this.#renderLayout(data.getLayout(), data, name);
|
|
807
|
-
}
|
|
808
|
-
return content;
|
|
809
|
-
};
|
|
851
|
+
}
|
|
852
|
+
function _path(name) {
|
|
853
|
+
const ext = name.split('.').pop();
|
|
854
|
+
if (ext !== _classPrivateFieldGet2(_config, this).extension) {
|
|
855
|
+
name = [name, _classPrivateFieldGet2(_config, this).extension].join('.');
|
|
810
856
|
}
|
|
857
|
+
return name;
|
|
858
|
+
}
|
|
859
|
+
function _output(path, data) {
|
|
860
|
+
return _classPrivateFieldGet2(_template, this).get(path).then(callback => callback.apply(data, [data, data.useComponent(), data.useElement(), data.useBuffer(), data.useEscapeValue()]));
|
|
861
|
+
}
|
|
862
|
+
function _renderLayout(name, params, parentTemplate) {
|
|
863
|
+
const data = this.createContext(params);
|
|
864
|
+
if (parentTemplate) data.setParentTemplate(parentTemplate);
|
|
865
|
+
return _assertClassBrand(_EjsInstance_brand, this, _output).call(this, _assertClassBrand(_EjsInstance_brand, this, _path).call(this, name), data).then(_assertClassBrand(_EjsInstance_brand, this, _outputContent).call(this, name, data));
|
|
866
|
+
}
|
|
867
|
+
function _outputContent(name, data) {
|
|
868
|
+
return content => {
|
|
869
|
+
if (data.getExtend()) {
|
|
870
|
+
data.setExtend(false);
|
|
871
|
+
return _assertClassBrand(_EjsInstance_brand, this, _renderLayout).call(this, data.getLayout(), data, name);
|
|
872
|
+
}
|
|
873
|
+
return content;
|
|
874
|
+
};
|
|
811
875
|
}
|
|
876
|
+
_defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
|
|
812
877
|
|
|
813
|
-
const
|
|
878
|
+
const resolver = async (path, template, error) => {
|
|
814
879
|
return fetch(joinPath(path, template)).then(response => {
|
|
815
880
|
if (response.ok) return response.text();
|
|
816
|
-
|
|
817
|
-
}, reason =>
|
|
818
|
-
return new TemplateError(reason);
|
|
819
|
-
});
|
|
881
|
+
return error(1, "template ".concat(template, " not found"));
|
|
882
|
+
}, reason => error(0, reason));
|
|
820
883
|
};
|
|
821
|
-
|
|
822
884
|
const {
|
|
823
885
|
render,
|
|
886
|
+
configure,
|
|
887
|
+
create,
|
|
888
|
+
helpers,
|
|
824
889
|
createContext,
|
|
825
890
|
compile,
|
|
826
|
-
|
|
827
|
-
preload,
|
|
828
|
-
configure,
|
|
829
|
-
create
|
|
891
|
+
preload
|
|
830
892
|
} = new EjsInstance({
|
|
831
|
-
resolver
|
|
893
|
+
resolver
|
|
832
894
|
});
|
|
833
895
|
|
|
834
|
-
exports.TemplateError = TemplateError;
|
|
835
|
-
exports.TemplateNotFound = TemplateNotFound;
|
|
836
|
-
exports.TemplateSyntaxError = TemplateSyntaxError;
|
|
837
896
|
exports.compile = compile;
|
|
838
897
|
exports.configure = configure;
|
|
839
898
|
exports.create = create;
|