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