@kosatyi/ejs 0.0.110 → 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 +295 -200
- package/dist/cjs/bundler.js +9 -1
- package/dist/cjs/element.js +1 -1
- package/dist/cjs/index.js +361 -277
- package/dist/cjs/worker.js +302 -224
- package/dist/esm/browser.js +77 -62
- package/dist/esm/bundler.js +9 -1
- package/dist/esm/index.js +195 -191
- package/dist/esm/worker.js +81 -83
- package/dist/umd/browser.js +832 -737
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/element.js +1 -1
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +851 -767
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +302 -224
- package/dist/umd/worker.min.js +1 -1
- package/package.json +4 -4
- package/types/context.d.ts +19 -4
- package/types/ejs.d.ts +1 -1
- package/types/error.d.ts +5 -2
- package/types/worker.d.ts +0 -6
- package/dist/kosatyi-ejs-0.0.109.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,849 +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
|
-
|
|
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]+?)'
|
|
167
203
|
}
|
|
168
|
-
|
|
169
|
-
throw new EjsError(code, content);
|
|
170
|
-
};
|
|
204
|
+
};
|
|
171
205
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this.#cache.set(template, result);
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
#compile(content, template) {
|
|
198
|
-
const cached = this.#cache.get(template);
|
|
199
|
-
if (typeof cached === 'function') return cached;
|
|
200
|
-
if (typeof content === 'string') {
|
|
201
|
-
content = this.#compiler.compile(content, template);
|
|
202
|
-
}
|
|
203
|
-
if (typeof content === 'function') {
|
|
204
|
-
this.#cache.set(template, content);
|
|
205
|
-
return content;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
get(template) {
|
|
209
|
-
return this.#resolve(template).then(content => {
|
|
210
|
-
return this.#compile(content, template);
|
|
211
|
-
});
|
|
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;
|
|
212
228
|
}
|
|
213
229
|
}
|
|
230
|
+
}
|
|
231
|
+
const error = (code, content) => {
|
|
232
|
+
throw new EjsError(code, content);
|
|
233
|
+
};
|
|
214
234
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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);
|
|
233
256
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
this
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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, ";");
|
|
261
330
|
}
|
|
262
331
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
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
|
+
}
|
|
284
353
|
});
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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);
|
|
305
374
|
}
|
|
306
375
|
}
|
|
376
|
+
}
|
|
377
|
+
_defineProperty(EjsCompiler, "exports", ['configure', 'compile']);
|
|
307
378
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
set(key, value) {
|
|
323
|
-
if (this.#cache) {
|
|
324
|
-
this.#list[key] = value;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
exist(key) {
|
|
328
|
-
if (this.#cache) {
|
|
329
|
-
return this.#list.hasOwnProperty(key);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
clear() {
|
|
333
|
-
Object.keys(this.#list).forEach(this.remove);
|
|
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];
|
|
334
393
|
}
|
|
335
|
-
|
|
336
|
-
|
|
394
|
+
}
|
|
395
|
+
set(key, value) {
|
|
396
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
397
|
+
_classPrivateFieldGet2(_list, this)[key] = value;
|
|
337
398
|
}
|
|
338
|
-
|
|
339
|
-
|
|
399
|
+
}
|
|
400
|
+
exist(key) {
|
|
401
|
+
if (_classPrivateFieldGet2(_cache$1, this)) {
|
|
402
|
+
return _classPrivateFieldGet2(_list, this).hasOwnProperty(key);
|
|
340
403
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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 || {});
|
|
345
417
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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)]);
|
|
352
424
|
}
|
|
353
425
|
}
|
|
426
|
+
}
|
|
427
|
+
_defineProperty(EjsCache, "exports", ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve']);
|
|
354
428
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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);
|
|
440
|
+
}
|
|
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);
|
|
449
|
+
}
|
|
450
|
+
if (hasClosedTag) {
|
|
451
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
452
|
+
}
|
|
453
|
+
return result.join('');
|
|
454
|
+
};
|
|
455
|
+
|
|
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);
|
|
367
472
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
371
|
-
const attributes = Object.entries(attrs ?? {}).map(eachAttribute).filter(e => e).join(space);
|
|
372
|
-
result.push([lt, tag, space, attributes, gt].join(''));
|
|
373
|
-
if (content && hasClosedTag) {
|
|
374
|
-
result.push(Array.isArray(content) ? content.join('') : content);
|
|
375
|
-
}
|
|
376
|
-
if (hasClosedTag) {
|
|
377
|
-
result.push([lt, slash, tag, gt].join(''));
|
|
378
|
-
}
|
|
379
|
-
return result.join('');
|
|
473
|
+
EjsBuffer.start = () => {
|
|
474
|
+
array = [];
|
|
380
475
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return error(500, e);
|
|
385
|
-
});
|
|
476
|
+
EjsBuffer.backup = () => {
|
|
477
|
+
store.push(array.concat());
|
|
478
|
+
array = [];
|
|
386
479
|
};
|
|
387
|
-
|
|
388
|
-
|
|
480
|
+
EjsBuffer.restore = () => {
|
|
481
|
+
const result = array.concat();
|
|
482
|
+
array = store.pop();
|
|
483
|
+
return resolve(result);
|
|
389
484
|
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
* @param value
|
|
396
|
-
* @constructor
|
|
397
|
-
*/
|
|
398
|
-
const EjsBuffer = value => {
|
|
399
|
-
array.push(value);
|
|
400
|
-
};
|
|
401
|
-
EjsBuffer.start = () => {
|
|
402
|
-
array = [];
|
|
403
|
-
};
|
|
404
|
-
EjsBuffer.backup = () => {
|
|
405
|
-
store.push(array.concat());
|
|
406
|
-
array = [];
|
|
407
|
-
};
|
|
408
|
-
EjsBuffer.restore = () => {
|
|
409
|
-
const result = array.concat();
|
|
410
|
-
array = store.pop();
|
|
411
|
-
return resolve(result);
|
|
412
|
-
};
|
|
413
|
-
EjsBuffer.error = e => {
|
|
414
|
-
return reject(e);
|
|
415
|
-
};
|
|
416
|
-
EjsBuffer.end = () => {
|
|
417
|
-
return resolve(array);
|
|
418
|
-
};
|
|
419
|
-
return EjsBuffer;
|
|
485
|
+
EjsBuffer.error = e => {
|
|
486
|
+
return reject(e);
|
|
487
|
+
};
|
|
488
|
+
EjsBuffer.end = () => {
|
|
489
|
+
return resolve(array);
|
|
420
490
|
};
|
|
491
|
+
return EjsBuffer;
|
|
492
|
+
};
|
|
421
493
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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) {
|
|
437
510
|
this[PARENT] = null;
|
|
438
511
|
this[BLOCKS] = {};
|
|
439
512
|
this[MACRO] = {};
|
|
440
513
|
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
441
514
|
}
|
|
442
|
-
|
|
515
|
+
}
|
|
516
|
+
Object.defineProperties(Context.prototype, {
|
|
517
|
+
[BUFFER]: {
|
|
443
518
|
value: EjsBuffer()
|
|
444
|
-
}
|
|
445
|
-
|
|
519
|
+
},
|
|
520
|
+
[BLOCKS]: {
|
|
446
521
|
value: {},
|
|
447
522
|
writable: true
|
|
448
|
-
}
|
|
449
|
-
|
|
523
|
+
},
|
|
524
|
+
[MACRO]: {
|
|
450
525
|
value: {},
|
|
451
526
|
writable: true
|
|
452
|
-
}
|
|
453
|
-
|
|
527
|
+
},
|
|
528
|
+
[LAYOUT]: {
|
|
454
529
|
value: false,
|
|
455
530
|
writable: true
|
|
456
|
-
}
|
|
457
|
-
|
|
531
|
+
},
|
|
532
|
+
[EXTEND]: {
|
|
458
533
|
value: false,
|
|
459
534
|
writable: true
|
|
460
|
-
}
|
|
461
|
-
|
|
535
|
+
},
|
|
536
|
+
[PARENT]: {
|
|
462
537
|
value: null,
|
|
463
538
|
writable: true
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
value
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
throw new Error(`${COMPONENT} must be a function`);
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
},
|
|
491
|
-
useElement: {
|
|
492
|
-
get() {
|
|
493
|
-
if (isFunction(this[ELEMENT])) {
|
|
494
|
-
return this[ELEMENT].bind(this);
|
|
495
|
-
} else {
|
|
496
|
-
return () => {
|
|
497
|
-
throw new Error(`${ELEMENT} must be a function`);
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
},
|
|
502
|
-
useBuffer: {
|
|
503
|
-
get() {
|
|
504
|
-
return this[BUFFER];
|
|
505
|
-
}
|
|
506
|
-
},
|
|
507
|
-
getMacro: {
|
|
508
|
-
value() {
|
|
509
|
-
return this[MACRO];
|
|
510
|
-
}
|
|
511
|
-
},
|
|
512
|
-
getBlocks: {
|
|
513
|
-
value() {
|
|
514
|
-
return this[BLOCKS];
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
setExtend: {
|
|
518
|
-
value(value) {
|
|
519
|
-
this[EXTEND] = value;
|
|
520
|
-
return this;
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
getExtend: {
|
|
524
|
-
value() {
|
|
525
|
-
return this[EXTEND];
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
setLayout: {
|
|
529
|
-
value(layout) {
|
|
530
|
-
this[LAYOUT] = layout;
|
|
531
|
-
return this;
|
|
532
|
-
}
|
|
533
|
-
},
|
|
534
|
-
getLayout: {
|
|
535
|
-
value() {
|
|
536
|
-
return this[LAYOUT];
|
|
537
|
-
}
|
|
538
|
-
},
|
|
539
|
-
clone: {
|
|
540
|
-
value(exclude_blocks) {
|
|
541
|
-
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
542
|
-
if (exclude_blocks === true) {
|
|
543
|
-
filter.push(BLOCKS);
|
|
544
|
-
}
|
|
545
|
-
return omit(this, filter);
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
extend: {
|
|
549
|
-
value(layout) {
|
|
550
|
-
this.setExtend(true);
|
|
551
|
-
this.setLayout(layout);
|
|
552
|
-
}
|
|
553
|
-
},
|
|
554
|
-
echo: {
|
|
555
|
-
value() {
|
|
556
|
-
return [].slice.call(arguments).forEach(this.useBuffer);
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
fn: {
|
|
560
|
-
value(callback) {
|
|
561
|
-
const context = this;
|
|
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 {
|
|
562
561
|
return function () {
|
|
563
|
-
|
|
564
|
-
context.useBuffer.backup();
|
|
565
|
-
context.useBuffer(callback.apply(context, arguments));
|
|
566
|
-
return context.useBuffer.restore();
|
|
567
|
-
}
|
|
562
|
+
error(2, "".concat(COMPONENT, " must be a function"));
|
|
568
563
|
};
|
|
569
564
|
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
},
|
|
581
|
-
call: {
|
|
582
|
-
value(name) {
|
|
583
|
-
const list = this.getMacro();
|
|
584
|
-
const macro = list[name];
|
|
585
|
-
const params = [].slice.call(arguments, 1);
|
|
586
|
-
if (isFunction(macro)) {
|
|
587
|
-
return macro.apply(macro, params);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
},
|
|
591
|
-
block: {
|
|
592
|
-
value(name, callback) {
|
|
593
|
-
const blocks = this.getBlocks();
|
|
594
|
-
blocks[name] = blocks[name] || [];
|
|
595
|
-
blocks[name].push(this.fn(callback));
|
|
596
|
-
if (this.getExtend()) return;
|
|
597
|
-
const context = this;
|
|
598
|
-
const list = Object.assign([], blocks[name]);
|
|
599
|
-
const shift = function () {
|
|
600
|
-
return list.shift();
|
|
601
|
-
};
|
|
602
|
-
const next = function () {
|
|
603
|
-
const parent = shift();
|
|
604
|
-
if (parent) {
|
|
605
|
-
return function () {
|
|
606
|
-
context.echo(parent(next()));
|
|
607
|
-
};
|
|
608
|
-
} else {
|
|
609
|
-
return function () {};
|
|
610
|
-
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
useElement: {
|
|
568
|
+
value() {
|
|
569
|
+
if (isFunction(this[ELEMENT])) {
|
|
570
|
+
return this[ELEMENT].bind(this);
|
|
571
|
+
} else {
|
|
572
|
+
return () => {
|
|
573
|
+
error(2, "".concat(ELEMENT, " must be a function"));
|
|
611
574
|
};
|
|
612
|
-
this.echo(shift()(next()));
|
|
613
|
-
}
|
|
614
|
-
},
|
|
615
|
-
hasBlock: {
|
|
616
|
-
value(name) {
|
|
617
|
-
return this.getBlocks().hasOwnProperty(name);
|
|
618
|
-
}
|
|
619
|
-
},
|
|
620
|
-
include: {
|
|
621
|
-
value(path, data, cx) {
|
|
622
|
-
const context = cx === false ? {} : this.clone(true);
|
|
623
|
-
const params = Object.assign(context, data || {});
|
|
624
|
-
const promise = this.render(path, params);
|
|
625
|
-
this.echo(promise);
|
|
626
575
|
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
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);
|
|
644
620
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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();
|
|
653
644
|
}
|
|
654
|
-
|
|
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);
|
|
655
665
|
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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 () {};
|
|
661
687
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
writable: true
|
|
665
|
-
},
|
|
666
|
-
el: {
|
|
667
|
-
value(tag, attr, content) {
|
|
668
|
-
content = isFunction(content) ? this.fn(content)() : content;
|
|
669
|
-
this.echo(Promise.resolve(content).then(content => element(tag, attr, content)));
|
|
670
|
-
},
|
|
671
|
-
writable: true
|
|
672
|
-
},
|
|
673
|
-
ui: {
|
|
674
|
-
value() {},
|
|
675
|
-
writable: true
|
|
688
|
+
};
|
|
689
|
+
this.echo(shift()(next()));
|
|
676
690
|
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
value = value.bind(EjsContext.prototype);
|
|
691
|
+
},
|
|
692
|
+
hasBlock: {
|
|
693
|
+
value(name) {
|
|
694
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
682
695
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
constructor(options, methods) {
|
|
691
|
-
bindContext(this, this.constructor.exports);
|
|
692
|
-
this.configure(options, methods);
|
|
693
|
-
}
|
|
694
|
-
create(data) {
|
|
695
|
-
return new this.#context(data);
|
|
696
|
-
}
|
|
697
|
-
helpers(methods) {
|
|
698
|
-
Object.assign(this.#context.prototype, methods);
|
|
699
|
-
}
|
|
700
|
-
configure(options, methods) {
|
|
701
|
-
this.#context = createContext$1(options, methods);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
class EjsInstance {
|
|
706
|
-
#cache;
|
|
707
|
-
#context;
|
|
708
|
-
#compiler;
|
|
709
|
-
#template;
|
|
710
|
-
#config = {};
|
|
711
|
-
#methods = {};
|
|
712
|
-
static exports = ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers'];
|
|
713
|
-
constructor() {
|
|
714
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
715
|
-
bindContext(this, this.constructor.exports);
|
|
716
|
-
this.#methods = {};
|
|
717
|
-
this.#config = configSchema({}, options);
|
|
718
|
-
this.#context = new EjsContext(this.#config, this.#methods);
|
|
719
|
-
this.#compiler = new EjsCompiler(this.#config);
|
|
720
|
-
this.#cache = new EjsCache(this.#config);
|
|
721
|
-
this.#template = new EjsTemplate(this.#config, this.#cache, this.#compiler);
|
|
722
|
-
this.helpers({
|
|
723
|
-
render: this.render,
|
|
724
|
-
require: this.require
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
create(options) {
|
|
728
|
-
return new this.constructor(options);
|
|
729
|
-
}
|
|
730
|
-
configure(options) {
|
|
731
|
-
if (options) {
|
|
732
|
-
configSchema(this.#config, options);
|
|
733
|
-
this.#context.configure(this.#config, this.#methods);
|
|
734
|
-
this.#compiler.configure(this.#config);
|
|
735
|
-
this.#cache.configure(this.#config);
|
|
736
|
-
this.#template.configure(this.#config);
|
|
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);
|
|
737
703
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
return this.#compiler.compile(content, path);
|
|
748
|
-
}
|
|
749
|
-
helpers(methods) {
|
|
750
|
-
this.#context.helpers(Object.assign(this.#methods, methods));
|
|
751
|
-
}
|
|
752
|
-
async render(name, params) {
|
|
753
|
-
const data = this.createContext(params);
|
|
754
|
-
return this.#output(this.#path(name), data).then(this.#outputContent(name, data));
|
|
755
|
-
}
|
|
756
|
-
async require(name) {
|
|
757
|
-
const data = this.createContext({});
|
|
758
|
-
return this.#output(this.#path(name), data).then(() => data.getMacro());
|
|
759
|
-
}
|
|
760
|
-
#path(name) {
|
|
761
|
-
const ext = name.split('.').pop();
|
|
762
|
-
if (ext !== this.#config.extension) {
|
|
763
|
-
name = [name, this.#config.extension].join('.');
|
|
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
|
+
}));
|
|
764
713
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
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];
|
|
780
730
|
}
|
|
781
|
-
return
|
|
782
|
-
}
|
|
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);
|
|
740
|
+
},
|
|
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)));
|
|
747
|
+
},
|
|
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
|
|
783
761
|
}
|
|
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);
|
|
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);
|
|
784
778
|
}
|
|
779
|
+
create(data) {
|
|
780
|
+
return new (_classPrivateFieldGet2(_context$1, this))(data);
|
|
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']);
|
|
785
790
|
|
|
786
|
-
|
|
787
|
-
|
|
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 {
|
|
788
799
|
/**
|
|
789
800
|
*
|
|
790
|
-
* @param {
|
|
791
|
-
* @param {function(name: string, data?: object):Promise<string>} render
|
|
792
|
-
* @return {function(name:any, options:any, callback: any): Promise<void>}
|
|
801
|
+
* @param {EjsConfig} options
|
|
793
802
|
*/
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
});
|
|
814
|
-
};
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
const readFile = (path, template, error) => {
|
|
818
|
-
return fs.readFile(joinPath(path, template)).then(contents => contents.toString()).catch(reason => {
|
|
819
|
-
if (reason.code === 'ENOENT') {
|
|
820
|
-
error(404, `template ${template} not found`);
|
|
821
|
-
} else {
|
|
822
|
-
error(500, reason);
|
|
823
|
-
}
|
|
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
|
|
824
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;
|
|
825
880
|
};
|
|
881
|
+
}
|
|
882
|
+
_defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
|
|
826
883
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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);
|
|
837
921
|
});
|
|
838
|
-
|
|
922
|
+
};
|
|
839
923
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
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;
|
|
848
932
|
|
|
849
933
|
}));
|