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