@kosatyi/ejs 0.0.62 → 0.0.64
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/element.js +3 -2
- package/dist/cjs/index.js +445 -678
- package/dist/esm/element.js +3 -2
- package/dist/esm/index.js +299 -330
- package/dist/templates.js +1 -0
- package/dist/umd/element.js +3 -2
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +480 -713
- package/dist/umd/index.min.js +1 -1
- package/package.json +3 -2
- package/type/global.d.ts +0 -101
- package/type/index.d.ts +0 -5
package/dist/umd/index.js
CHANGED
|
@@ -1,509 +1,356 @@
|
|
|
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
|
-
"@babel/helpers - typeof";
|
|
7
|
+
var path = {};
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
27
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
31
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
32
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
33
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
34
|
-
writable: false
|
|
35
|
-
});
|
|
36
|
-
return Constructor;
|
|
37
|
-
}
|
|
38
|
-
function _defineProperty(obj, key, value) {
|
|
39
|
-
key = _toPropertyKey(key);
|
|
40
|
-
if (key in obj) {
|
|
41
|
-
Object.defineProperty(obj, key, {
|
|
42
|
-
value: value,
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
obj[key] = value;
|
|
49
|
-
}
|
|
50
|
-
return obj;
|
|
51
|
-
}
|
|
52
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
53
|
-
if (!o) return;
|
|
54
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
55
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
56
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
57
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
58
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
59
|
-
}
|
|
60
|
-
function _arrayLikeToArray(arr, len) {
|
|
61
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
62
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
63
|
-
return arr2;
|
|
64
|
-
}
|
|
65
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
66
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
67
|
-
if (!it) {
|
|
68
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
69
|
-
if (it) o = it;
|
|
70
|
-
var i = 0;
|
|
71
|
-
var F = function () {};
|
|
72
|
-
return {
|
|
73
|
-
s: F,
|
|
74
|
-
n: function () {
|
|
75
|
-
if (i >= o.length) return {
|
|
76
|
-
done: true
|
|
77
|
-
};
|
|
78
|
-
return {
|
|
79
|
-
done: false,
|
|
80
|
-
value: o[i++]
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
e: function (e) {
|
|
84
|
-
throw e;
|
|
85
|
-
},
|
|
86
|
-
f: F
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
90
|
-
}
|
|
91
|
-
var normalCompletion = true,
|
|
92
|
-
didErr = false,
|
|
93
|
-
err;
|
|
94
|
-
return {
|
|
95
|
-
s: function () {
|
|
96
|
-
it = it.call(o);
|
|
97
|
-
},
|
|
98
|
-
n: function () {
|
|
99
|
-
var step = it.next();
|
|
100
|
-
normalCompletion = step.done;
|
|
101
|
-
return step;
|
|
102
|
-
},
|
|
103
|
-
e: function (e) {
|
|
104
|
-
didErr = true;
|
|
105
|
-
err = e;
|
|
106
|
-
},
|
|
107
|
-
f: function () {
|
|
108
|
-
try {
|
|
109
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
110
|
-
} finally {
|
|
111
|
-
if (didErr) throw err;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
9
|
+
var typeProp = function typeProp() {
|
|
10
|
+
var args = [].slice.call(arguments);
|
|
11
|
+
var callback = args.shift();
|
|
12
|
+
return args.filter(callback).pop();
|
|
13
|
+
};
|
|
14
|
+
var isFunction = function isFunction(v) {
|
|
15
|
+
return typeof v === 'function';
|
|
16
|
+
};
|
|
17
|
+
var isString = function isString(v) {
|
|
18
|
+
return typeof v === 'string';
|
|
19
|
+
};
|
|
20
|
+
var isBoolean = function isBoolean(v) {
|
|
21
|
+
return typeof v === 'boolean';
|
|
22
|
+
};
|
|
23
|
+
var isUndefined = function isUndefined(v) {
|
|
24
|
+
return typeof v === 'undefined';
|
|
114
25
|
};
|
|
115
|
-
}
|
|
116
|
-
function _toPrimitive(input, hint) {
|
|
117
|
-
if (typeof input !== "object" || input === null) return input;
|
|
118
|
-
var prim = input[Symbol.toPrimitive];
|
|
119
|
-
if (prim !== undefined) {
|
|
120
|
-
var res = prim.call(input, hint || "default");
|
|
121
|
-
if (typeof res !== "object") return res;
|
|
122
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
123
|
-
}
|
|
124
|
-
return (hint === "string" ? String : Number)(input);
|
|
125
|
-
}
|
|
126
|
-
function _toPropertyKey(arg) {
|
|
127
|
-
var key = _toPrimitive(arg, "string");
|
|
128
|
-
return typeof key === "symbol" ? key : String(key);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
var typeProp = function typeProp() {
|
|
132
|
-
var args = [].slice.call(arguments);
|
|
133
|
-
var callback = args.shift();
|
|
134
|
-
return args.filter(callback).pop();
|
|
135
|
-
};
|
|
136
|
-
var isFunction = function isFunction(v) {
|
|
137
|
-
return typeof v === 'function';
|
|
138
|
-
};
|
|
139
|
-
var isString = function isString(v) {
|
|
140
|
-
return typeof v === 'string';
|
|
141
|
-
};
|
|
142
|
-
var isBoolean = function isBoolean(v) {
|
|
143
|
-
return typeof v === 'boolean';
|
|
144
|
-
};
|
|
145
|
-
var isObject = function isObject(v) {
|
|
146
|
-
return _typeof(v) === 'object';
|
|
147
|
-
};
|
|
148
|
-
var isUndefined = function isUndefined(v) {
|
|
149
|
-
return typeof v === 'undefined';
|
|
150
|
-
};
|
|
151
26
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
27
|
+
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
28
|
+
var isNode = function isNode() {
|
|
29
|
+
return isNodeEnv;
|
|
30
|
+
};
|
|
31
|
+
var symbolEntities = {
|
|
32
|
+
"'": "'",
|
|
33
|
+
'\\': '\\',
|
|
34
|
+
'\r': 'r',
|
|
35
|
+
'\n': 'n',
|
|
36
|
+
'\t': 't',
|
|
37
|
+
"\u2028": 'u2028',
|
|
38
|
+
"\u2029": 'u2029'
|
|
39
|
+
};
|
|
40
|
+
var htmlEntities = {
|
|
41
|
+
'&': '&',
|
|
42
|
+
'<': '<',
|
|
43
|
+
'>': '>',
|
|
44
|
+
'"': '"',
|
|
45
|
+
"'": '''
|
|
46
|
+
};
|
|
47
|
+
var regexKeys = function regexKeys(obj) {
|
|
48
|
+
return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
|
|
49
|
+
};
|
|
50
|
+
var htmlEntitiesMatch = regexKeys(htmlEntities);
|
|
51
|
+
var symbolEntitiesMatch = regexKeys(symbolEntities);
|
|
52
|
+
var entities = function entities() {
|
|
53
|
+
var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
54
|
+
return ('' + string).replace(htmlEntitiesMatch, function (match) {
|
|
55
|
+
return htmlEntities[match];
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var symbols = function symbols(string) {
|
|
59
|
+
return ('' + string).replace(symbolEntitiesMatch, function (match) {
|
|
60
|
+
return '\\' + symbolEntities[match];
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var safeValue = function safeValue(value, escape) {
|
|
64
|
+
var check = value;
|
|
65
|
+
return check == null ? '' : escape === true ? entities(check) : check;
|
|
66
|
+
};
|
|
67
|
+
var instanceOf = function instanceOf(object, instance) {
|
|
68
|
+
return object instanceof instance;
|
|
69
|
+
};
|
|
70
|
+
var getPath = function getPath(context, name, strict) {
|
|
71
|
+
var data = context;
|
|
72
|
+
var chunks = String(name).split('.');
|
|
73
|
+
var prop = chunks.pop();
|
|
74
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
75
|
+
var part = chunks[i];
|
|
76
|
+
if (isFunction(data['toJSON'])) {
|
|
77
|
+
data = data.toJSON();
|
|
78
|
+
}
|
|
200
79
|
if (strict && data.hasOwnProperty(part) === false) {
|
|
201
80
|
data = {};
|
|
202
81
|
break;
|
|
203
82
|
}
|
|
204
83
|
data = data[part] = data[part] || {};
|
|
205
84
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
} finally {
|
|
209
|
-
_iterator.f();
|
|
210
|
-
}
|
|
211
|
-
return [data, prop];
|
|
212
|
-
};
|
|
213
|
-
var bindContext = function bindContext(object, context) {
|
|
214
|
-
var methods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
215
|
-
methods.forEach(function (name) {
|
|
216
|
-
if (name in object) {
|
|
217
|
-
object[name] = object[name].bind(context);
|
|
85
|
+
if (isFunction(data['toJSON'])) {
|
|
86
|
+
data = data.toJSON();
|
|
218
87
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
return path;
|
|
227
|
-
};
|
|
228
|
-
var extend = function extend() {
|
|
229
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
230
|
-
args[_key] = arguments[_key];
|
|
231
|
-
}
|
|
232
|
-
var target = args.shift();
|
|
233
|
-
return args.filter(function (source) {
|
|
234
|
-
return source;
|
|
235
|
-
}).reduce(function (target, source) {
|
|
236
|
-
return Object.assign(target, source);
|
|
237
|
-
}, target);
|
|
238
|
-
};
|
|
239
|
-
var noop = function noop() {};
|
|
240
|
-
var each = function each(object, callback) {
|
|
241
|
-
var prop;
|
|
242
|
-
for (prop in object) {
|
|
243
|
-
if (hasProp(object, prop)) {
|
|
244
|
-
callback(object[prop], prop, object);
|
|
88
|
+
return [data, prop];
|
|
89
|
+
};
|
|
90
|
+
var ext = function ext(path, defaults) {
|
|
91
|
+
var ext = path.split('.').pop();
|
|
92
|
+
if (ext !== defaults) {
|
|
93
|
+
path = [path, defaults].join('.');
|
|
245
94
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
95
|
+
return path;
|
|
96
|
+
};
|
|
97
|
+
var extend = function extend() {
|
|
98
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
99
|
+
args[_key] = arguments[_key];
|
|
100
|
+
}
|
|
101
|
+
var target = args.shift();
|
|
102
|
+
return args.filter(function (source) {
|
|
103
|
+
return source;
|
|
104
|
+
}).reduce(function (target, source) {
|
|
105
|
+
return Object.assign(target, source);
|
|
106
|
+
}, target);
|
|
107
|
+
};
|
|
108
|
+
var noop = function noop() {};
|
|
109
|
+
var each = function each(object, callback) {
|
|
110
|
+
var prop;
|
|
111
|
+
for (prop in object) {
|
|
112
|
+
if (hasProp(object, prop)) {
|
|
113
|
+
callback(object[prop], prop, object);
|
|
114
|
+
}
|
|
254
115
|
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
each(object, function (value, key, object) {
|
|
262
|
-
var item = callback(value, key, object);
|
|
263
|
-
if (isUndefined(item) === false) {
|
|
264
|
-
if (isArray) {
|
|
116
|
+
};
|
|
117
|
+
var map = function map(object, callback, context) {
|
|
118
|
+
var result = [];
|
|
119
|
+
each(object, function (value, key, object) {
|
|
120
|
+
var item = callback(value, key, object);
|
|
121
|
+
if (isUndefined(item) === false) {
|
|
265
122
|
result.push(item);
|
|
266
|
-
} else {
|
|
267
|
-
result[key] = item;
|
|
268
123
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
124
|
+
});
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
var filter = function filter(object, callback, context) {
|
|
128
|
+
var isArray = object instanceof Array;
|
|
129
|
+
var result = isArray ? [] : {};
|
|
130
|
+
each(object, function (value, key, object) {
|
|
131
|
+
var item = callback(value, key, object);
|
|
132
|
+
if (isUndefined(item) === false) {
|
|
133
|
+
if (isArray) {
|
|
134
|
+
result.push(item);
|
|
135
|
+
} else {
|
|
136
|
+
result[key] = item;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
var omit = function omit(object, list) {
|
|
143
|
+
return filter(object, function (value, key) {
|
|
144
|
+
if (list.indexOf(key) === -1) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
var resolve$1 = function resolve(value, callback, context) {
|
|
150
|
+
return Promise.resolve(value).then(callback.bind(context));
|
|
151
|
+
};
|
|
152
|
+
var hasProp = function hasProp(object, prop) {
|
|
153
|
+
return object && object.hasOwnProperty(prop);
|
|
154
|
+
};
|
|
286
155
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
156
|
+
var defaults = {};
|
|
157
|
+
defaults["export"] = 'ejsPrecompiled';
|
|
158
|
+
defaults.cache = true;
|
|
159
|
+
defaults.chokidar = null;
|
|
160
|
+
defaults.path = 'views';
|
|
161
|
+
defaults.resolver = null;
|
|
162
|
+
defaults.extension = 'ejs';
|
|
163
|
+
defaults.rmWhitespace = true;
|
|
164
|
+
defaults.withObject = true;
|
|
165
|
+
defaults.vars = {
|
|
166
|
+
SCOPE: 'ejs',
|
|
167
|
+
COMPONENT: 'ui',
|
|
168
|
+
EXTEND: '$$e',
|
|
169
|
+
BUFFER: '$$a',
|
|
170
|
+
LAYOUT: '$$l',
|
|
171
|
+
BLOCKS: '$$b',
|
|
172
|
+
MACRO: '$$m',
|
|
173
|
+
SAFE: '$$v'
|
|
174
|
+
};
|
|
175
|
+
defaults.token = {
|
|
176
|
+
start: '<%',
|
|
177
|
+
end: '%>',
|
|
178
|
+
regex: '([\\s\\S]+?)'
|
|
179
|
+
};
|
|
311
180
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
181
|
+
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
182
|
+
var space = ' ';
|
|
183
|
+
var quote = '"';
|
|
184
|
+
var equal = '=';
|
|
185
|
+
var slash = '/';
|
|
186
|
+
var lt = '<';
|
|
187
|
+
var gt = '>';
|
|
188
|
+
var element = function element(tag, attrs, content) {
|
|
189
|
+
var result = [];
|
|
190
|
+
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
191
|
+
var attributes = map(attrs, function (value, key) {
|
|
192
|
+
if (value !== null && value !== undefined) {
|
|
193
|
+
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
194
|
+
}
|
|
195
|
+
}).join(space);
|
|
196
|
+
result.push([lt, tag, space, attributes, gt].join(''));
|
|
197
|
+
if (content) {
|
|
198
|
+
result.push(content instanceof Array ? content.join('') : content);
|
|
199
|
+
}
|
|
200
|
+
if (hasClosedTag) {
|
|
201
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
202
|
+
}
|
|
203
|
+
return result.join('');
|
|
204
|
+
};
|
|
326
205
|
|
|
327
|
-
|
|
206
|
+
var configSchema = function configSchema(config, options) {
|
|
207
|
+
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.watch, config.watch, options.watch),
|
|
215
|
+
token: extend({}, defaults.token, config.token, options.token),
|
|
216
|
+
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
217
|
+
});
|
|
218
|
+
};
|
|
328
219
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
220
|
+
var resolvePath = function resolvePath(path, template) {
|
|
221
|
+
template = [path, template].join('/');
|
|
222
|
+
template = template.replace(/\/\//g, '/');
|
|
223
|
+
return template;
|
|
224
|
+
};
|
|
225
|
+
var httpRequest = function httpRequest(path, template) {
|
|
226
|
+
return fetch(resolvePath(path, template)).then(function (response) {
|
|
227
|
+
return response.text();
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
var fileSystem = function fileSystem(path$1, template) {
|
|
231
|
+
return new Promise(function (resolve, reject) {
|
|
232
|
+
path.readFile(resolvePath(path$1, template), function (error, data) {
|
|
233
|
+
if (error) {
|
|
234
|
+
reject(error);
|
|
235
|
+
} else {
|
|
236
|
+
resolve(data.toString());
|
|
237
|
+
}
|
|
238
|
+
});
|
|
347
239
|
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
240
|
+
};
|
|
241
|
+
var fileResolver = function fileResolver(resolver) {
|
|
242
|
+
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
243
|
+
};
|
|
351
244
|
function Template(config, cache, compiler) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
245
|
+
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
246
|
+
var template = {};
|
|
247
|
+
var result = function result(template, content) {
|
|
248
|
+
cache.set(template, content);
|
|
249
|
+
return content;
|
|
250
|
+
};
|
|
251
|
+
var resolve = function resolve(path) {
|
|
252
|
+
return template.resolver(template.path, path);
|
|
253
|
+
};
|
|
254
|
+
var compile = function compile(content, template) {
|
|
255
|
+
if (isFunction(content)) {
|
|
256
|
+
return content;
|
|
257
|
+
} else {
|
|
258
|
+
return compiler.compile(content, template);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
this.configure = function (config) {
|
|
262
|
+
template.path = config.path;
|
|
263
|
+
template.cache = config.cache;
|
|
264
|
+
template.resolver = fileResolver(config.resolver);
|
|
265
|
+
};
|
|
266
|
+
this.get = function (template) {
|
|
267
|
+
if (cache.exist(template)) {
|
|
268
|
+
return cache.resolve(template);
|
|
269
|
+
}
|
|
270
|
+
return result(template, resolve(template).then(function (content) {
|
|
271
|
+
return result(template, compile(content, template));
|
|
272
|
+
}));
|
|
357
273
|
};
|
|
358
|
-
this.compiler = compiler;
|
|
359
274
|
this.configure(config);
|
|
360
275
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.
|
|
366
|
-
this.chokidar = config.chokidar;
|
|
367
|
-
this.resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
368
|
-
if (config.watch && isNode()) {
|
|
369
|
-
if (this.watcher) {
|
|
370
|
-
this.watcher.unwatch('.');
|
|
371
|
-
}
|
|
372
|
-
if (this.chokidar) {
|
|
373
|
-
this.watcher = this.chokidar.watch('.', {
|
|
374
|
-
cwd: this.path
|
|
375
|
-
}).on('change', function (name) {
|
|
376
|
-
_this.cache.remove(name);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
}
|
|
276
|
+
|
|
277
|
+
var tagList = [{
|
|
278
|
+
symbol: '-',
|
|
279
|
+
format: function format(value) {
|
|
280
|
+
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
|
|
380
281
|
}
|
|
381
282
|
}, {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return this.
|
|
283
|
+
symbol: '=',
|
|
284
|
+
format: function format(value) {
|
|
285
|
+
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
|
|
385
286
|
}
|
|
386
287
|
}, {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return content;
|
|
288
|
+
symbol: '#',
|
|
289
|
+
format: function format(value) {
|
|
290
|
+
return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
|
|
391
291
|
}
|
|
392
292
|
}, {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
var content = this.resolve(template).then(function (content) {
|
|
409
|
-
return _this2.result(template, _this2.compile(content, template));
|
|
410
|
-
});
|
|
411
|
-
return this.result(template, content);
|
|
412
|
-
}
|
|
413
|
-
}]);
|
|
414
|
-
return Template;
|
|
415
|
-
}();
|
|
416
|
-
|
|
417
|
-
var tagList = [{
|
|
418
|
-
symbol: '-',
|
|
419
|
-
format: function format(value) {
|
|
420
|
-
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
|
|
421
|
-
}
|
|
422
|
-
}, {
|
|
423
|
-
symbol: '=',
|
|
424
|
-
format: function format(value) {
|
|
425
|
-
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
|
|
426
|
-
}
|
|
427
|
-
}, {
|
|
428
|
-
symbol: '#',
|
|
429
|
-
format: function format(value) {
|
|
430
|
-
return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
|
|
431
|
-
}
|
|
432
|
-
}, {
|
|
433
|
-
symbol: '',
|
|
434
|
-
format: function format(value) {
|
|
435
|
-
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
293
|
+
symbol: '',
|
|
294
|
+
format: function format(value) {
|
|
295
|
+
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
296
|
+
}
|
|
297
|
+
}];
|
|
298
|
+
function matchTokens(regex, text, callback) {
|
|
299
|
+
var index = 0;
|
|
300
|
+
text.replace(regex, function () {
|
|
301
|
+
var params = [].slice.call(arguments, 0, -1);
|
|
302
|
+
var offset = params.pop();
|
|
303
|
+
var match = params.shift();
|
|
304
|
+
callback(params, index, offset);
|
|
305
|
+
index = offset + match.length;
|
|
306
|
+
return match;
|
|
307
|
+
});
|
|
436
308
|
}
|
|
437
|
-
}];
|
|
438
|
-
var matchTokens = function matchTokens(regex, text, callback) {
|
|
439
|
-
var index = 0;
|
|
440
|
-
text.replace(regex, function () {
|
|
441
|
-
var params = [].slice.call(arguments, 0, -1);
|
|
442
|
-
var offset = params.pop();
|
|
443
|
-
var match = params.shift();
|
|
444
|
-
callback(params, index, offset);
|
|
445
|
-
index = offset + match.length;
|
|
446
|
-
return match;
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
var Compiler = /*#__PURE__*/function () {
|
|
450
309
|
function Compiler(config) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
this.vars = config.vars;
|
|
462
|
-
this.matches = [];
|
|
463
|
-
this.formats = [];
|
|
464
|
-
this.slurp = {
|
|
310
|
+
if (instanceOf(this, Compiler) === false) return new Compiler(config);
|
|
311
|
+
var compiler = {};
|
|
312
|
+
this.configure = function (config) {
|
|
313
|
+
compiler.withObject = config.withObject;
|
|
314
|
+
compiler.rmWhitespace = config.rmWhitespace;
|
|
315
|
+
compiler.token = config.token;
|
|
316
|
+
compiler.vars = config.vars;
|
|
317
|
+
compiler.matches = [];
|
|
318
|
+
compiler.formats = [];
|
|
319
|
+
compiler.slurp = {
|
|
465
320
|
match: '[ \\t]*',
|
|
466
|
-
start: [
|
|
467
|
-
end: ['_',
|
|
321
|
+
start: [compiler.token.start, '_'],
|
|
322
|
+
end: ['_', compiler.token.end]
|
|
468
323
|
};
|
|
469
324
|
tagList.forEach(function (item) {
|
|
470
|
-
|
|
471
|
-
|
|
325
|
+
compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
|
|
326
|
+
compiler.formats.push(item.format.bind(compiler.vars));
|
|
472
327
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
value: function compile(content, path) {
|
|
485
|
-
var _this2 = this;
|
|
486
|
-
var _this$vars = this.vars,
|
|
487
|
-
SCOPE = _this$vars.SCOPE,
|
|
488
|
-
SAFE = _this$vars.SAFE,
|
|
489
|
-
BUFFER = _this$vars.BUFFER,
|
|
490
|
-
COMPONENT = _this$vars.COMPONENT;
|
|
491
|
-
if (this.rmWhitespace) {
|
|
328
|
+
compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
|
|
329
|
+
compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
|
|
330
|
+
compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
|
|
331
|
+
};
|
|
332
|
+
this.compile = function (content, path) {
|
|
333
|
+
var _compiler$vars = compiler.vars,
|
|
334
|
+
SCOPE = _compiler$vars.SCOPE,
|
|
335
|
+
SAFE = _compiler$vars.SAFE,
|
|
336
|
+
BUFFER = _compiler$vars.BUFFER,
|
|
337
|
+
COMPONENT = _compiler$vars.COMPONENT;
|
|
338
|
+
if (compiler.rmWhitespace) {
|
|
492
339
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
493
340
|
}
|
|
494
|
-
content = content.replace(
|
|
341
|
+
content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
|
|
495
342
|
var source = "".concat(BUFFER, "('");
|
|
496
|
-
matchTokens(
|
|
343
|
+
matchTokens(compiler.regex, content, function (params, index, offset) {
|
|
497
344
|
source += symbols(content.slice(index, offset));
|
|
498
345
|
params.forEach(function (value, index) {
|
|
499
346
|
if (value) {
|
|
500
|
-
source +=
|
|
347
|
+
source += compiler.formats[index](value);
|
|
501
348
|
}
|
|
502
349
|
});
|
|
503
350
|
});
|
|
504
351
|
source += "');";
|
|
505
352
|
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
506
|
-
if (
|
|
353
|
+
if (compiler.withObject) {
|
|
507
354
|
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
508
355
|
}
|
|
509
356
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
@@ -518,156 +365,108 @@
|
|
|
518
365
|
throw e;
|
|
519
366
|
}
|
|
520
367
|
return result;
|
|
521
|
-
}
|
|
522
|
-
}]);
|
|
523
|
-
return Compiler;
|
|
524
|
-
}();
|
|
525
|
-
|
|
526
|
-
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
527
|
-
var Cache = /*#__PURE__*/function () {
|
|
528
|
-
function Cache(config) {
|
|
529
|
-
_classCallCheck(this, Cache);
|
|
530
|
-
_defineProperty(this, "list", {});
|
|
368
|
+
};
|
|
531
369
|
this.configure(config);
|
|
532
370
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
371
|
+
|
|
372
|
+
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
373
|
+
function Cache(config) {
|
|
374
|
+
if (instanceOf(this, Cache) === false) return new Cache();
|
|
375
|
+
var cache = {
|
|
376
|
+
enabled: true,
|
|
377
|
+
list: {}
|
|
378
|
+
};
|
|
379
|
+
this.configure = function (config) {
|
|
380
|
+
cache.list = {};
|
|
381
|
+
cache.enabled = config.cache;
|
|
537
382
|
if (isNode() === false) {
|
|
538
383
|
this.load(global[config["export"]]);
|
|
539
384
|
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
385
|
+
};
|
|
386
|
+
this.load = function (data) {
|
|
387
|
+
if (cache.enabled) {
|
|
388
|
+
extend(cache.list, data || {});
|
|
389
|
+
}
|
|
545
390
|
return this;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
557
|
-
}, {
|
|
558
|
-
key: "remove",
|
|
559
|
-
value: function remove(key) {
|
|
560
|
-
delete this.list[key];
|
|
561
|
-
}
|
|
562
|
-
}, {
|
|
563
|
-
key: "resolve",
|
|
564
|
-
value: function resolve(key) {
|
|
565
|
-
return Promise.resolve(this.get(key));
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
key: "set",
|
|
569
|
-
value: function set(key, value) {
|
|
570
|
-
this.list[key] = value;
|
|
391
|
+
};
|
|
392
|
+
this.get = function (key) {
|
|
393
|
+
if (cache.enabled) {
|
|
394
|
+
return cache.list[key];
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
this.set = function (key, value) {
|
|
398
|
+
if (cache.enabled) {
|
|
399
|
+
cache.list[key] = value;
|
|
400
|
+
}
|
|
571
401
|
return this;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
var lt = '<';
|
|
583
|
-
var gt = '>';
|
|
584
|
-
var element = function element(tag, attrs, content) {
|
|
585
|
-
var result = [];
|
|
586
|
-
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
587
|
-
var attributes = map(attrs, function (value, key) {
|
|
588
|
-
if (value !== null && value !== undefined) {
|
|
589
|
-
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
590
|
-
}
|
|
591
|
-
}).join(space);
|
|
592
|
-
result.push([lt, tag, space, attributes, gt].join(''));
|
|
593
|
-
if (content) {
|
|
594
|
-
result.push(content instanceof Array ? content.join('') : content);
|
|
595
|
-
}
|
|
596
|
-
if (hasClosedTag) {
|
|
597
|
-
result.push([lt, slash, tag, gt].join(''));
|
|
402
|
+
};
|
|
403
|
+
this.resolve = function (key) {
|
|
404
|
+
return Promise.resolve(this.get(key));
|
|
405
|
+
};
|
|
406
|
+
this.remove = function (key) {
|
|
407
|
+
delete cache.list[key];
|
|
408
|
+
};
|
|
409
|
+
this.exist = function (key) {
|
|
410
|
+
return hasProp(cache.list, key);
|
|
411
|
+
};
|
|
598
412
|
}
|
|
599
|
-
return result.join('');
|
|
600
|
-
};
|
|
601
413
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
};
|
|
607
|
-
var createBuffer = function createBuffer() {
|
|
608
|
-
var store = [],
|
|
609
|
-
array = [];
|
|
610
|
-
function buffer(value) {
|
|
611
|
-
array.push(value);
|
|
414
|
+
function resolve(list) {
|
|
415
|
+
return Promise.all(list || []).then(function (list) {
|
|
416
|
+
return list.join('');
|
|
417
|
+
});
|
|
612
418
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
419
|
+
var createBuffer = function createBuffer() {
|
|
420
|
+
var store = [],
|
|
421
|
+
array = [];
|
|
422
|
+
function buffer(value) {
|
|
423
|
+
array.push(value);
|
|
424
|
+
}
|
|
425
|
+
buffer.start = function () {
|
|
426
|
+
array = [];
|
|
427
|
+
};
|
|
428
|
+
buffer.backup = function () {
|
|
429
|
+
store.push(array.concat());
|
|
430
|
+
array = [];
|
|
431
|
+
};
|
|
432
|
+
buffer.restore = function () {
|
|
433
|
+
var result = array.concat();
|
|
434
|
+
array = store.pop();
|
|
435
|
+
return resolve(result);
|
|
436
|
+
};
|
|
437
|
+
buffer.error = function (e) {
|
|
438
|
+
throw e;
|
|
439
|
+
};
|
|
440
|
+
buffer.end = function () {
|
|
441
|
+
return resolve(array);
|
|
442
|
+
};
|
|
443
|
+
return buffer;
|
|
630
444
|
};
|
|
631
|
-
return buffer;
|
|
632
|
-
};
|
|
633
445
|
|
|
634
|
-
var Context = /*#__PURE__*/function () {
|
|
635
446
|
function Context(config) {
|
|
636
|
-
|
|
637
|
-
this.configure(config)
|
|
638
|
-
}
|
|
639
|
-
_createClass(Context, [{
|
|
640
|
-
key: "configure",
|
|
641
|
-
value: function configure(config, methods) {
|
|
447
|
+
if (instanceOf(this, Context) === false) return new Context(config);
|
|
448
|
+
this.configure = function (config, methods) {
|
|
642
449
|
var _config$vars = config.vars,
|
|
450
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
451
|
+
MACRO = _config$vars.MACRO,
|
|
643
452
|
EXTEND = _config$vars.EXTEND,
|
|
644
453
|
LAYOUT = _config$vars.LAYOUT,
|
|
645
|
-
BLOCKS = _config$vars.BLOCKS,
|
|
646
454
|
BUFFER = _config$vars.BUFFER,
|
|
647
|
-
MACRO = _config$vars.MACRO,
|
|
648
455
|
COMPONENT = _config$vars.COMPONENT;
|
|
649
456
|
this.create = function (data) {
|
|
650
457
|
return new Scope(data);
|
|
651
458
|
};
|
|
652
459
|
this.helpers = function (methods) {
|
|
653
|
-
extend(Scope.prototype, methods);
|
|
460
|
+
extend(Scope.prototype, methods || {});
|
|
654
461
|
};
|
|
655
|
-
function Scope() {
|
|
656
|
-
|
|
657
|
-
this
|
|
658
|
-
this
|
|
659
|
-
extend(this, data);
|
|
462
|
+
function Scope(data) {
|
|
463
|
+
this[BLOCKS] = {};
|
|
464
|
+
this[MACRO] = {};
|
|
465
|
+
extend(this, data || {});
|
|
660
466
|
}
|
|
661
467
|
Scope.prototype = extend({}, methods || {});
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
* @param {*} value
|
|
665
|
-
* @param {boolean} [writable]
|
|
666
|
-
* @param {boolean} [configurable]
|
|
667
|
-
* @param {boolean} [enumerable]
|
|
668
|
-
*/
|
|
669
|
-
Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
|
|
670
|
-
return Object.defineProperty(Scope.prototype, name, {
|
|
468
|
+
Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
|
|
469
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
671
470
|
value: value,
|
|
672
471
|
writable: writable || false,
|
|
673
472
|
configurable: configurable || false,
|
|
@@ -679,12 +478,6 @@
|
|
|
679
478
|
Scope.define(MACRO, {}, true);
|
|
680
479
|
Scope.define(LAYOUT, false, true);
|
|
681
480
|
Scope.define(EXTEND, false, true);
|
|
682
|
-
Scope.method('initBlocks', function () {
|
|
683
|
-
this[BLOCKS] = {};
|
|
684
|
-
});
|
|
685
|
-
Scope.method('initMacro', function () {
|
|
686
|
-
this[MACRO] = {};
|
|
687
|
-
});
|
|
688
481
|
Scope.method('getMacro', function () {
|
|
689
482
|
return this[MACRO];
|
|
690
483
|
});
|
|
@@ -834,143 +627,117 @@
|
|
|
834
627
|
}
|
|
835
628
|
each(object, callback);
|
|
836
629
|
});
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
return Context;
|
|
840
|
-
}();
|
|
841
|
-
|
|
842
|
-
var EJS = /*#__PURE__*/function () {
|
|
843
|
-
function EJS() {
|
|
844
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
845
|
-
_classCallCheck(this, EJS);
|
|
846
|
-
_defineProperty(this, "export", ['cache', 'render', 'require', 'helpers', 'configure', 'preload', 'compile', 'create', '__express']);
|
|
847
|
-
this.config = {};
|
|
848
|
-
this.scope = {};
|
|
849
|
-
configSchema(this.config, options);
|
|
850
|
-
bindContext(this, this, this["export"]);
|
|
851
|
-
this.context = new Context(this.config);
|
|
852
|
-
this.compiler = new Compiler(this.config);
|
|
853
|
-
this.cache = new Cache(this.config);
|
|
854
|
-
this.template = new Template(this.config, this.cache, this.compiler);
|
|
855
|
-
this.helpers({
|
|
856
|
-
require: this.require,
|
|
857
|
-
render: this.render
|
|
858
|
-
});
|
|
630
|
+
};
|
|
631
|
+
this.configure(config);
|
|
859
632
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
key: "output",
|
|
873
|
-
value: function output(path, scope) {
|
|
874
|
-
return this.template.get(path).then(function (callback) {
|
|
633
|
+
|
|
634
|
+
function EJS(options) {
|
|
635
|
+
if (instanceOf(this, EJS) === false) return new EJS(options);
|
|
636
|
+
var scope = {};
|
|
637
|
+
var config = {};
|
|
638
|
+
configSchema(config, options || {});
|
|
639
|
+
var context = new Context(config);
|
|
640
|
+
var compiler = new Compiler(config);
|
|
641
|
+
var cache = new Cache();
|
|
642
|
+
var template = new Template(config, cache, compiler);
|
|
643
|
+
var output = function output(path, scope) {
|
|
644
|
+
return template.get(path).then(function (callback) {
|
|
875
645
|
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
876
646
|
});
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
647
|
+
};
|
|
648
|
+
var require = function require(name) {
|
|
649
|
+
var filepath = ext(name, config.extension);
|
|
650
|
+
var scope = context.create({});
|
|
651
|
+
return output(filepath, scope).then(function () {
|
|
652
|
+
return scope.getMacro();
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
var render = function render(name, data) {
|
|
656
|
+
var filepath = ext(name, config.extension);
|
|
657
|
+
var scope = context.create(data);
|
|
658
|
+
return output(filepath, scope).then(function (content) {
|
|
885
659
|
if (scope.getExtend()) {
|
|
886
660
|
scope.setExtend(false);
|
|
887
661
|
var layout = scope.getLayout();
|
|
888
662
|
var _data = scope.clone();
|
|
889
|
-
return
|
|
663
|
+
return render(layout, _data);
|
|
890
664
|
}
|
|
891
665
|
return content;
|
|
892
666
|
});
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
key: "require",
|
|
896
|
-
value: function require(name) {
|
|
897
|
-
var filepath = ext(name, this.config.extension);
|
|
898
|
-
var scope = this.context.create({});
|
|
899
|
-
return this.output(filepath, scope).then(function () {
|
|
900
|
-
return scope.getMacro();
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
}, {
|
|
904
|
-
key: "create",
|
|
905
|
-
value: function create() {
|
|
906
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
907
|
-
return new EJS(options);
|
|
908
|
-
}
|
|
909
|
-
}, {
|
|
910
|
-
key: "helpers",
|
|
911
|
-
value: function helpers() {
|
|
912
|
-
var methods = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
913
|
-
this.context.helpers(extend(this.scope, methods));
|
|
914
|
-
}
|
|
915
|
-
}, {
|
|
916
|
-
key: "preload",
|
|
917
|
-
value: function preload() {
|
|
918
|
-
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
919
|
-
return this.cache.load(list);
|
|
920
|
-
}
|
|
921
|
-
}, {
|
|
922
|
-
key: "compile",
|
|
923
|
-
value: function compile(content, path) {
|
|
924
|
-
return this.compiler.compile(content, path);
|
|
925
|
-
}
|
|
926
|
-
}, {
|
|
927
|
-
key: "__express",
|
|
928
|
-
value: function __express(name, options, callback) {
|
|
929
|
-
if (isFunction(options)) {
|
|
930
|
-
callback = options;
|
|
931
|
-
options = {};
|
|
932
|
-
}
|
|
667
|
+
};
|
|
668
|
+
this.configure = function (options) {
|
|
933
669
|
options = options || {};
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
return
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
670
|
+
configSchema(config, options);
|
|
671
|
+
context.configure(config, scope);
|
|
672
|
+
compiler.configure(config);
|
|
673
|
+
cache.configure(config);
|
|
674
|
+
template.configure(config);
|
|
675
|
+
return config;
|
|
676
|
+
};
|
|
677
|
+
this.render = function (name, data) {
|
|
678
|
+
return render(name, data);
|
|
679
|
+
};
|
|
680
|
+
this.helpers = function (methods) {
|
|
681
|
+
context.helpers(Object.assign(scope, methods || {}));
|
|
682
|
+
};
|
|
683
|
+
this.preload = function (list) {
|
|
684
|
+
return cache.load(list || {});
|
|
685
|
+
};
|
|
686
|
+
this.create = function (options) {
|
|
687
|
+
return new EJS(options);
|
|
688
|
+
};
|
|
689
|
+
this.compile = function (content, path) {
|
|
690
|
+
return compiler.compile(content, path);
|
|
691
|
+
};
|
|
692
|
+
this.context = function (data) {
|
|
693
|
+
return context.create(data);
|
|
694
|
+
};
|
|
695
|
+
this.helpers({
|
|
696
|
+
require: require,
|
|
697
|
+
render: render
|
|
698
|
+
});
|
|
699
|
+
}
|
|
951
700
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
701
|
+
var ejs = new EJS();
|
|
702
|
+
var render = ejs.render,
|
|
703
|
+
context = ejs.context,
|
|
704
|
+
compile = ejs.compile,
|
|
705
|
+
helpers = ejs.helpers,
|
|
706
|
+
preload = ejs.preload,
|
|
707
|
+
configure = ejs.configure,
|
|
708
|
+
create = ejs.create;
|
|
709
|
+
|
|
710
|
+
function __express(name, options, callback) {
|
|
711
|
+
if (isFunction(options)) {
|
|
712
|
+
callback = options;
|
|
713
|
+
options = {};
|
|
714
|
+
}
|
|
715
|
+
options = options || {};
|
|
716
|
+
var settings = extend({}, options.settings);
|
|
717
|
+
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
718
|
+
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
719
|
+
var viewOptions = extend({}, settings['view options']);
|
|
720
|
+
var filename = path.relative(viewPath, name);
|
|
721
|
+
viewOptions.path = viewPath;
|
|
722
|
+
viewOptions.cache = viewCache;
|
|
723
|
+
configure(viewOptions);
|
|
724
|
+
return this.render(filename, options).then(function (content) {
|
|
725
|
+
callback(null, content);
|
|
726
|
+
})["catch"](function (error) {
|
|
727
|
+
callback(error);
|
|
728
|
+
});
|
|
729
|
+
}
|
|
963
730
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
731
|
+
exports.EJS = EJS;
|
|
732
|
+
exports.__express = __express;
|
|
733
|
+
exports.compile = compile;
|
|
734
|
+
exports.configure = configure;
|
|
735
|
+
exports.context = context;
|
|
736
|
+
exports.create = create;
|
|
737
|
+
exports.element = element;
|
|
738
|
+
exports.helpers = helpers;
|
|
739
|
+
exports.preload = preload;
|
|
740
|
+
exports.render = render;
|
|
741
|
+
exports.safeValue = safeValue;
|
|
975
742
|
|
|
976
743
|
}));
|