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