@kosatyi/ejs 0.0.63 → 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/index.js +16 -35
- package/dist/esm/index.js +16 -39
- package/dist/umd/index.js +687 -706
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
package/dist/umd/index.js
CHANGED
|
@@ -1,762 +1,743 @@
|
|
|
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
|
-
}, _typeof(o);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var typeProp = function typeProp() {
|
|
18
|
-
var args = [].slice.call(arguments);
|
|
19
|
-
var callback = args.shift();
|
|
20
|
-
return args.filter(callback).pop();
|
|
21
|
-
};
|
|
22
|
-
var isFunction = function isFunction(v) {
|
|
23
|
-
return typeof v === 'function';
|
|
24
|
-
};
|
|
25
|
-
var isString = function isString(v) {
|
|
26
|
-
return typeof v === 'string';
|
|
27
|
-
};
|
|
28
|
-
var isBoolean = function isBoolean(v) {
|
|
29
|
-
return typeof v === 'boolean';
|
|
30
|
-
};
|
|
31
|
-
var isObject = function isObject(v) {
|
|
32
|
-
return _typeof(v) === 'object';
|
|
33
|
-
};
|
|
34
|
-
var isUndefined = function isUndefined(v) {
|
|
35
|
-
return typeof v === 'undefined';
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
39
|
-
var isNode = function isNode() {
|
|
40
|
-
return isNodeEnv;
|
|
41
|
-
};
|
|
42
|
-
var symbolEntities = {
|
|
43
|
-
"'": "'",
|
|
44
|
-
'\\': '\\',
|
|
45
|
-
'\r': 'r',
|
|
46
|
-
'\n': 'n',
|
|
47
|
-
'\t': 't',
|
|
48
|
-
"\u2028": 'u2028',
|
|
49
|
-
"\u2029": 'u2029'
|
|
50
|
-
};
|
|
51
|
-
var htmlEntities = {
|
|
52
|
-
'&': '&',
|
|
53
|
-
'<': '<',
|
|
54
|
-
'>': '>',
|
|
55
|
-
'"': '"',
|
|
56
|
-
"'": '''
|
|
57
|
-
};
|
|
58
|
-
var regexKeys = function regexKeys(obj) {
|
|
59
|
-
return new RegExp(['[', Object.keys(obj).join(''), ']'].join(''), 'g');
|
|
60
|
-
};
|
|
61
|
-
var htmlEntitiesMatch = regexKeys(htmlEntities);
|
|
62
|
-
var symbolEntitiesMatch = regexKeys(symbolEntities);
|
|
63
|
-
var entities = function entities() {
|
|
64
|
-
var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
65
|
-
return ('' + string).replace(htmlEntitiesMatch, function (match) {
|
|
66
|
-
return htmlEntities[match];
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
var symbols = function symbols(string) {
|
|
70
|
-
return ('' + string).replace(symbolEntitiesMatch, function (match) {
|
|
71
|
-
return '\\' + symbolEntities[match];
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
var safeValue = function safeValue(value, escape) {
|
|
75
|
-
var check = value;
|
|
76
|
-
return check == null ? '' : escape === true ? entities(check) : check;
|
|
77
|
-
};
|
|
78
|
-
var instanceOf = function instanceOf(object, instance) {
|
|
79
|
-
return object instanceof instance;
|
|
80
|
-
};
|
|
81
|
-
var getPath = function getPath(context, name, strict) {
|
|
82
|
-
var data = context;
|
|
83
|
-
var chunks = String(name).split('.');
|
|
84
|
-
var prop = chunks.pop();
|
|
85
|
-
for (var i = 0; i < chunks.length; i++) {
|
|
86
|
-
var part = chunks[i];
|
|
87
|
-
if (isFunction(data['toJSON'])) {
|
|
88
|
-
data = data.toJSON();
|
|
89
|
-
}
|
|
90
|
-
if (strict && data.hasOwnProperty(part) === false) {
|
|
91
|
-
data = {};
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
data = data[part] = data[part] || {};
|
|
95
|
-
}
|
|
96
|
-
if (isFunction(data['toJSON'])) {
|
|
97
|
-
data = data.toJSON();
|
|
98
|
-
}
|
|
99
|
-
return [data, prop];
|
|
100
|
-
};
|
|
101
|
-
var ext = function ext(path, defaults) {
|
|
102
|
-
var ext = path.split('.').pop();
|
|
103
|
-
if (ext !== defaults) {
|
|
104
|
-
path = [path, defaults].join('.');
|
|
105
|
-
}
|
|
106
|
-
return path;
|
|
107
|
-
};
|
|
108
|
-
var extend = function extend() {
|
|
109
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
110
|
-
args[_key] = arguments[_key];
|
|
111
|
-
}
|
|
112
|
-
var target = args.shift();
|
|
113
|
-
return args.filter(function (source) {
|
|
114
|
-
return source;
|
|
115
|
-
}).reduce(function (target, source) {
|
|
116
|
-
return Object.assign(target, source);
|
|
117
|
-
}, target);
|
|
118
|
-
};
|
|
119
|
-
var noop = function noop() {};
|
|
120
|
-
var each = function each(object, callback) {
|
|
121
|
-
var prop;
|
|
122
|
-
for (prop in object) {
|
|
123
|
-
if (hasProp(object, prop)) {
|
|
124
|
-
callback(object[prop], prop, object);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var map = function map(object, callback, context) {
|
|
129
|
-
var result = [];
|
|
130
|
-
each(object, function (value, key, object) {
|
|
131
|
-
var item = callback(value, key, object);
|
|
132
|
-
if (isUndefined(item) === false) {
|
|
133
|
-
result.push(item);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return result;
|
|
137
|
-
};
|
|
138
|
-
var filter = function filter(object, callback, context) {
|
|
139
|
-
var isArray = object instanceof Array;
|
|
140
|
-
var result = isArray ? [] : {};
|
|
141
|
-
each(object, function (value, key, object) {
|
|
142
|
-
var item = callback(value, key, object);
|
|
143
|
-
if (isUndefined(item) === false) {
|
|
144
|
-
if (isArray) {
|
|
145
|
-
result.push(item);
|
|
146
|
-
} else {
|
|
147
|
-
result[key] = item;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
return result;
|
|
152
|
-
};
|
|
153
|
-
var omit = function omit(object, list) {
|
|
154
|
-
return filter(object, function (value, key) {
|
|
155
|
-
if (list.indexOf(key) === -1) {
|
|
156
|
-
return value;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
var resolve$1 = function resolve(value, callback, context) {
|
|
161
|
-
return Promise.resolve(value).then(callback.bind(context));
|
|
162
|
-
};
|
|
163
|
-
var hasProp = function hasProp(object, prop) {
|
|
164
|
-
return object && object.hasOwnProperty(prop);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
var defaults = {};
|
|
168
|
-
defaults["export"] = 'ejsPrecompiled';
|
|
169
|
-
defaults.watch = false;
|
|
170
|
-
defaults.chokidar = null;
|
|
171
|
-
defaults.path = 'views';
|
|
172
|
-
defaults.resolver = null;
|
|
173
|
-
defaults.extension = 'ejs';
|
|
174
|
-
defaults.rmWhitespace = true;
|
|
175
|
-
defaults.withObject = true;
|
|
176
|
-
defaults.vars = {
|
|
177
|
-
SCOPE: 'ejs',
|
|
178
|
-
COMPONENT: 'ui',
|
|
179
|
-
EXTEND: '$$e',
|
|
180
|
-
BUFFER: '$$a',
|
|
181
|
-
LAYOUT: '$$l',
|
|
182
|
-
BLOCKS: '$$b',
|
|
183
|
-
MACRO: '$$m',
|
|
184
|
-
SAFE: '$$v'
|
|
185
|
-
};
|
|
186
|
-
defaults.token = {
|
|
187
|
-
start: '<%',
|
|
188
|
-
end: '%>',
|
|
189
|
-
regex: '([\\s\\S]+?)'
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
var path = {};
|
|
193
|
-
|
|
194
|
-
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
195
|
-
var space = ' ';
|
|
196
|
-
var quote = '"';
|
|
197
|
-
var equal = '=';
|
|
198
|
-
var slash = '/';
|
|
199
|
-
var lt = '<';
|
|
200
|
-
var gt = '>';
|
|
201
|
-
var element = function element(tag, attrs, content) {
|
|
202
|
-
var result = [];
|
|
203
|
-
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
204
|
-
var attributes = map(attrs, function (value, key) {
|
|
205
|
-
if (value !== null && value !== undefined) {
|
|
206
|
-
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
207
|
-
}
|
|
208
|
-
}).join(space);
|
|
209
|
-
result.push([lt, tag, space, attributes, gt].join(''));
|
|
210
|
-
if (content) {
|
|
211
|
-
result.push(content instanceof Array ? content.join('') : content);
|
|
212
|
-
}
|
|
213
|
-
if (hasClosedTag) {
|
|
214
|
-
result.push([lt, slash, tag, gt].join(''));
|
|
215
|
-
}
|
|
216
|
-
return result.join('');
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
var configSchema = function configSchema(config, options) {
|
|
220
|
-
extend(config, {
|
|
221
|
-
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
222
|
-
"export": typeProp(isString, defaults["export"], config["export"], options["export"]),
|
|
223
|
-
resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
|
|
224
|
-
extension: typeProp(isString, defaults.extension, config.extension, options.extension),
|
|
225
|
-
withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
|
|
226
|
-
rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
|
|
227
|
-
watch: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
|
|
228
|
-
chokidar: typeProp(isObject, defaults["export"], config["export"], options["export"]),
|
|
229
|
-
token: extend({}, defaults.token, config.token, options.token),
|
|
230
|
-
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
var resolvePath = function resolvePath(path, template) {
|
|
235
|
-
template = [path, template].join('/');
|
|
236
|
-
template = template.replace(/\/\//g, '/');
|
|
237
|
-
return template;
|
|
238
|
-
};
|
|
239
|
-
var httpRequest = function httpRequest(path, template) {
|
|
240
|
-
return fetch(resolvePath(path, template)).then(function (response) {
|
|
241
|
-
return response.text();
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
var fileSystem = function fileSystem(path$1, template) {
|
|
245
|
-
return new Promise(function (resolve, reject) {
|
|
246
|
-
path.readFile(resolvePath(path$1, template), function (error, data) {
|
|
247
|
-
if (error) {
|
|
248
|
-
reject(error);
|
|
249
|
-
} else {
|
|
250
|
-
resolve(data.toString());
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
var fileResolver = function fileResolver(resolver) {
|
|
256
|
-
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
257
|
-
};
|
|
258
|
-
function Template(config, cache, compiler) {
|
|
259
|
-
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
260
|
-
var template = {};
|
|
261
|
-
var result = function result(template, content) {
|
|
262
|
-
cache.set(template, content);
|
|
263
|
-
return content;
|
|
9
|
+
var typeProp = function typeProp() {
|
|
10
|
+
var args = [].slice.call(arguments);
|
|
11
|
+
var callback = args.shift();
|
|
12
|
+
return args.filter(callback).pop();
|
|
264
13
|
};
|
|
265
|
-
var
|
|
266
|
-
return
|
|
14
|
+
var isFunction = function isFunction(v) {
|
|
15
|
+
return typeof v === 'function';
|
|
267
16
|
};
|
|
268
|
-
var
|
|
269
|
-
|
|
270
|
-
return content;
|
|
271
|
-
} else {
|
|
272
|
-
return compiler.compile(content, template);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
var watcher = function watcher(config) {
|
|
276
|
-
if (template.watcher) {
|
|
277
|
-
template.watcher.unwatch('.');
|
|
278
|
-
}
|
|
279
|
-
if (config.watch && config.chokidar && isNode()) {
|
|
280
|
-
return config.chokidar.watch('.', {
|
|
281
|
-
cwd: template.path
|
|
282
|
-
}).on('change', function (name) {
|
|
283
|
-
cache.remove(name);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
17
|
+
var isString = function isString(v) {
|
|
18
|
+
return typeof v === 'string';
|
|
286
19
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
template.chokidar = config.chokidar;
|
|
290
|
-
template.resolver = fileResolver(config.resolver);
|
|
291
|
-
template.watcher = watcher(config);
|
|
20
|
+
var isBoolean = function isBoolean(v) {
|
|
21
|
+
return typeof v === 'boolean';
|
|
292
22
|
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return cache.resolve(template);
|
|
296
|
-
}
|
|
297
|
-
return result(template, resolve(template).then(function (content) {
|
|
298
|
-
return result(template, compile(content, template));
|
|
299
|
-
}));
|
|
23
|
+
var isUndefined = function isUndefined(v) {
|
|
24
|
+
return typeof v === 'undefined';
|
|
300
25
|
};
|
|
301
|
-
this.configure(config);
|
|
302
|
-
}
|
|
303
26
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return match;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
function Compiler(config) {
|
|
337
|
-
if (instanceOf(this, Compiler) === false) return new Compiler(config);
|
|
338
|
-
var compiler = {};
|
|
339
|
-
this.configure = function (config) {
|
|
340
|
-
compiler.withObject = config.withObject;
|
|
341
|
-
compiler.rmWhitespace = config.rmWhitespace;
|
|
342
|
-
compiler.token = config.token;
|
|
343
|
-
compiler.vars = config.vars;
|
|
344
|
-
compiler.matches = [];
|
|
345
|
-
compiler.formats = [];
|
|
346
|
-
compiler.slurp = {
|
|
347
|
-
match: '[ \\t]*',
|
|
348
|
-
start: [compiler.token.start, '_'],
|
|
349
|
-
end: ['_', compiler.token.end]
|
|
350
|
-
};
|
|
351
|
-
tagList.forEach(function (item) {
|
|
352
|
-
compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
|
|
353
|
-
compiler.formats.push(item.format.bind(compiler.vars));
|
|
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];
|
|
354
56
|
});
|
|
355
|
-
compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
|
|
356
|
-
compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
|
|
357
|
-
compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
|
|
358
57
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
SAFE = _compiler$vars.SAFE,
|
|
363
|
-
BUFFER = _compiler$vars.BUFFER,
|
|
364
|
-
COMPONENT = _compiler$vars.COMPONENT;
|
|
365
|
-
if (compiler.rmWhitespace) {
|
|
366
|
-
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
367
|
-
}
|
|
368
|
-
content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
|
|
369
|
-
var source = "".concat(BUFFER, "('");
|
|
370
|
-
matchTokens(compiler.regex, content, function (params, index, offset) {
|
|
371
|
-
source += symbols(content.slice(index, offset));
|
|
372
|
-
params.forEach(function (value, index) {
|
|
373
|
-
if (value) {
|
|
374
|
-
source += compiler.formats[index](value);
|
|
375
|
-
}
|
|
376
|
-
});
|
|
58
|
+
var symbols = function symbols(string) {
|
|
59
|
+
return ('' + string).replace(symbolEntitiesMatch, function (match) {
|
|
60
|
+
return '\\' + symbolEntities[match];
|
|
377
61
|
});
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
+
}
|
|
79
|
+
if (strict && data.hasOwnProperty(part) === false) {
|
|
80
|
+
data = {};
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
data = data[part] = data[part] || {};
|
|
382
84
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
var result = null;
|
|
386
|
-
try {
|
|
387
|
-
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
388
|
-
result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
389
|
-
} catch (e) {
|
|
390
|
-
e.filename = path;
|
|
391
|
-
e.source = source;
|
|
392
|
-
throw e;
|
|
85
|
+
if (isFunction(data['toJSON'])) {
|
|
86
|
+
data = data.toJSON();
|
|
393
87
|
}
|
|
394
|
-
return
|
|
88
|
+
return [data, prop];
|
|
395
89
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var cache = {
|
|
403
|
-
list: {}
|
|
90
|
+
var ext = function ext(path, defaults) {
|
|
91
|
+
var ext = path.split('.').pop();
|
|
92
|
+
if (ext !== defaults) {
|
|
93
|
+
path = [path, defaults].join('.');
|
|
94
|
+
}
|
|
95
|
+
return path;
|
|
404
96
|
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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
|
+
}
|
|
409
115
|
}
|
|
410
116
|
};
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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) {
|
|
122
|
+
result.push(item);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return result;
|
|
414
126
|
};
|
|
415
|
-
|
|
416
|
-
|
|
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;
|
|
417
141
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
+
});
|
|
421
148
|
};
|
|
422
|
-
|
|
423
|
-
return Promise.resolve(
|
|
149
|
+
var resolve$1 = function resolve(value, callback, context) {
|
|
150
|
+
return Promise.resolve(value).then(callback.bind(context));
|
|
424
151
|
};
|
|
425
|
-
|
|
426
|
-
|
|
152
|
+
var hasProp = function hasProp(object, prop) {
|
|
153
|
+
return object && object.hasOwnProperty(prop);
|
|
427
154
|
};
|
|
428
|
-
|
|
429
|
-
|
|
155
|
+
|
|
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]+?)'
|
|
430
179
|
};
|
|
431
|
-
}
|
|
432
180
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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('');
|
|
446
204
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
205
|
+
|
|
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
|
+
});
|
|
450
218
|
};
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
219
|
+
|
|
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
|
+
});
|
|
455
229
|
};
|
|
456
|
-
|
|
457
|
-
|
|
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
|
+
});
|
|
239
|
+
});
|
|
458
240
|
};
|
|
459
|
-
|
|
460
|
-
return
|
|
241
|
+
var fileResolver = function fileResolver(resolver) {
|
|
242
|
+
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
461
243
|
};
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var _config$vars = config.vars,
|
|
469
|
-
BLOCKS = _config$vars.BLOCKS,
|
|
470
|
-
MACRO = _config$vars.MACRO,
|
|
471
|
-
EXTEND = _config$vars.EXTEND,
|
|
472
|
-
LAYOUT = _config$vars.LAYOUT,
|
|
473
|
-
BUFFER = _config$vars.BUFFER,
|
|
474
|
-
COMPONENT = _config$vars.COMPONENT;
|
|
475
|
-
this.create = function (data) {
|
|
476
|
-
return new Scope(data);
|
|
244
|
+
function Template(config, cache, compiler) {
|
|
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;
|
|
477
250
|
};
|
|
478
|
-
|
|
479
|
-
|
|
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
|
+
}));
|
|
480
273
|
};
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
274
|
+
this.configure(config);
|
|
275
|
+
}
|
|
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, "('");
|
|
281
|
+
}
|
|
282
|
+
}, {
|
|
283
|
+
symbol: '=',
|
|
284
|
+
format: function format(value) {
|
|
285
|
+
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
|
|
485
286
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
287
|
+
}, {
|
|
288
|
+
symbol: '#',
|
|
289
|
+
format: function format(value) {
|
|
290
|
+
return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
|
|
291
|
+
}
|
|
292
|
+
}, {
|
|
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
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function Compiler(config) {
|
|
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 = {
|
|
320
|
+
match: '[ \\t]*',
|
|
321
|
+
start: [compiler.token.start, '_'],
|
|
322
|
+
end: ['_', compiler.token.end]
|
|
323
|
+
};
|
|
324
|
+
tagList.forEach(function (item) {
|
|
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));
|
|
493
327
|
});
|
|
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');
|
|
494
331
|
};
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
Scope.method('getBuffer', function () {
|
|
504
|
-
return this[BUFFER];
|
|
505
|
-
});
|
|
506
|
-
Scope.method('getComponent', function () {
|
|
507
|
-
var context = this;
|
|
508
|
-
if (COMPONENT in context) {
|
|
509
|
-
return function () {
|
|
510
|
-
return context[COMPONENT].apply(context, arguments);
|
|
511
|
-
};
|
|
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) {
|
|
339
|
+
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
512
340
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
this[LAYOUT] = layout;
|
|
528
|
-
});
|
|
529
|
-
Scope.method('getLayout', function () {
|
|
530
|
-
return this[LAYOUT];
|
|
531
|
-
});
|
|
532
|
-
Scope.method('clone', function (exclude_blocks) {
|
|
533
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
534
|
-
if (exclude_blocks === true) {
|
|
535
|
-
filter.push(BLOCKS);
|
|
341
|
+
content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
|
|
342
|
+
var source = "".concat(BUFFER, "('");
|
|
343
|
+
matchTokens(compiler.regex, content, function (params, index, offset) {
|
|
344
|
+
source += symbols(content.slice(index, offset));
|
|
345
|
+
params.forEach(function (value, index) {
|
|
346
|
+
if (value) {
|
|
347
|
+
source += compiler.formats[index](value);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
source += "');";
|
|
352
|
+
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
353
|
+
if (compiler.withObject) {
|
|
354
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
536
355
|
}
|
|
537
|
-
return
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
});
|
|
548
|
-
Scope.method('fn', function (callback) {
|
|
549
|
-
var buffer = this.getBuffer();
|
|
550
|
-
var context = this;
|
|
551
|
-
return function () {
|
|
552
|
-
buffer.backup();
|
|
553
|
-
if (isFunction(callback)) {
|
|
554
|
-
callback.apply(context, arguments);
|
|
555
|
-
}
|
|
556
|
-
return buffer.restore();
|
|
557
|
-
};
|
|
558
|
-
});
|
|
559
|
-
Scope.method('get', function (name, defaults) {
|
|
560
|
-
var path = getPath(this, name, true);
|
|
561
|
-
var result = path.shift();
|
|
562
|
-
var prop = path.pop();
|
|
563
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
564
|
-
});
|
|
565
|
-
Scope.method('set', function (name, value) {
|
|
566
|
-
var path = getPath(this, name, false);
|
|
567
|
-
var result = path.shift();
|
|
568
|
-
var prop = path.pop();
|
|
569
|
-
if (this.getExtend() && hasProp(result, prop)) {
|
|
570
|
-
return result[prop];
|
|
356
|
+
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
357
|
+
source += "\n//# sourceURL=".concat(path);
|
|
358
|
+
var result = null;
|
|
359
|
+
try {
|
|
360
|
+
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
361
|
+
result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
362
|
+
} catch (e) {
|
|
363
|
+
e.filename = path;
|
|
364
|
+
e.source = source;
|
|
365
|
+
throw e;
|
|
571
366
|
}
|
|
572
|
-
return result
|
|
367
|
+
return result;
|
|
368
|
+
};
|
|
369
|
+
this.configure(config);
|
|
370
|
+
}
|
|
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;
|
|
382
|
+
if (isNode() === false) {
|
|
383
|
+
this.load(global[config["export"]]);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
this.load = function (data) {
|
|
387
|
+
if (cache.enabled) {
|
|
388
|
+
extend(cache.list, data || {});
|
|
389
|
+
}
|
|
390
|
+
return this;
|
|
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
|
+
}
|
|
401
|
+
return this;
|
|
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
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function resolve(list) {
|
|
415
|
+
return Promise.all(list || []).then(function (list) {
|
|
416
|
+
return list.join('');
|
|
573
417
|
});
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
418
|
+
}
|
|
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;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
function Context(config) {
|
|
447
|
+
if (instanceOf(this, Context) === false) return new Context(config);
|
|
448
|
+
this.configure = function (config, methods) {
|
|
449
|
+
var _config$vars = config.vars,
|
|
450
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
451
|
+
MACRO = _config$vars.MACRO,
|
|
452
|
+
EXTEND = _config$vars.EXTEND,
|
|
453
|
+
LAYOUT = _config$vars.LAYOUT,
|
|
454
|
+
BUFFER = _config$vars.BUFFER,
|
|
455
|
+
COMPONENT = _config$vars.COMPONENT;
|
|
456
|
+
this.create = function (data) {
|
|
457
|
+
return new Scope(data);
|
|
580
458
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
459
|
+
this.helpers = function (methods) {
|
|
460
|
+
extend(Scope.prototype, methods || {});
|
|
461
|
+
};
|
|
462
|
+
function Scope(data) {
|
|
463
|
+
this[BLOCKS] = {};
|
|
464
|
+
this[MACRO] = {};
|
|
465
|
+
extend(this, data || {});
|
|
588
466
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
var current = function current() {
|
|
598
|
-
return list.shift();
|
|
467
|
+
Scope.prototype = extend({}, methods || {});
|
|
468
|
+
Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
|
|
469
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
470
|
+
value: value,
|
|
471
|
+
writable: writable || false,
|
|
472
|
+
configurable: configurable || false,
|
|
473
|
+
enumerable: enumerable || false
|
|
474
|
+
});
|
|
599
475
|
};
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
476
|
+
Scope.define(BUFFER, createBuffer());
|
|
477
|
+
Scope.define(BLOCKS, {}, true);
|
|
478
|
+
Scope.define(MACRO, {}, true);
|
|
479
|
+
Scope.define(LAYOUT, false, true);
|
|
480
|
+
Scope.define(EXTEND, false, true);
|
|
481
|
+
Scope.method('getMacro', function () {
|
|
482
|
+
return this[MACRO];
|
|
483
|
+
});
|
|
484
|
+
Scope.method('getBuffer', function () {
|
|
485
|
+
return this[BUFFER];
|
|
486
|
+
});
|
|
487
|
+
Scope.method('getComponent', function () {
|
|
488
|
+
var context = this;
|
|
489
|
+
if (COMPONENT in context) {
|
|
603
490
|
return function () {
|
|
604
|
-
|
|
491
|
+
return context[COMPONENT].apply(context, arguments);
|
|
605
492
|
};
|
|
606
|
-
} else {
|
|
607
|
-
return noop;
|
|
608
493
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
494
|
+
return function () {
|
|
495
|
+
console.log('%s function not defined', COMPONENT);
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
Scope.method('getBlocks', function () {
|
|
499
|
+
return this[BLOCKS];
|
|
500
|
+
});
|
|
501
|
+
Scope.method('setExtend', function (value) {
|
|
502
|
+
this[EXTEND] = value;
|
|
503
|
+
});
|
|
504
|
+
Scope.method('getExtend', function () {
|
|
505
|
+
return this[EXTEND];
|
|
506
|
+
});
|
|
507
|
+
Scope.method('setLayout', function (layout) {
|
|
508
|
+
this[LAYOUT] = layout;
|
|
509
|
+
});
|
|
510
|
+
Scope.method('getLayout', function () {
|
|
511
|
+
return this[LAYOUT];
|
|
512
|
+
});
|
|
513
|
+
Scope.method('clone', function (exclude_blocks) {
|
|
514
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
515
|
+
if (exclude_blocks === true) {
|
|
516
|
+
filter.push(BLOCKS);
|
|
517
|
+
}
|
|
518
|
+
return omit(this, filter);
|
|
519
|
+
});
|
|
520
|
+
Scope.method('extend', function (layout) {
|
|
521
|
+
this.setExtend(true);
|
|
522
|
+
this.setLayout(layout);
|
|
523
|
+
});
|
|
524
|
+
Scope.method('echo', function () {
|
|
525
|
+
var buffer = this.getBuffer();
|
|
526
|
+
var params = [].slice.call(arguments);
|
|
527
|
+
params.forEach(buffer);
|
|
528
|
+
});
|
|
529
|
+
Scope.method('fn', function (callback) {
|
|
530
|
+
var buffer = this.getBuffer();
|
|
531
|
+
var context = this;
|
|
532
|
+
return function () {
|
|
533
|
+
buffer.backup();
|
|
534
|
+
if (isFunction(callback)) {
|
|
535
|
+
callback.apply(context, arguments);
|
|
536
|
+
}
|
|
537
|
+
return buffer.restore();
|
|
538
|
+
};
|
|
539
|
+
});
|
|
540
|
+
Scope.method('get', function (name, defaults) {
|
|
541
|
+
var path = getPath(this, name, true);
|
|
542
|
+
var result = path.shift();
|
|
543
|
+
var prop = path.pop();
|
|
544
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
545
|
+
});
|
|
546
|
+
Scope.method('set', function (name, value) {
|
|
547
|
+
var path = getPath(this, name, false);
|
|
548
|
+
var result = path.shift();
|
|
549
|
+
var prop = path.pop();
|
|
550
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
551
|
+
return result[prop];
|
|
552
|
+
}
|
|
553
|
+
return result[prop] = value;
|
|
554
|
+
});
|
|
555
|
+
Scope.method('macro', function (name, callback) {
|
|
621
556
|
var list = this.getMacro();
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
557
|
+
var macro = this.fn(callback);
|
|
558
|
+
var context = this;
|
|
559
|
+
list[name] = function () {
|
|
560
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
561
|
+
};
|
|
562
|
+
});
|
|
563
|
+
Scope.method('call', function (name) {
|
|
564
|
+
var list = this.getMacro();
|
|
565
|
+
var macro = list[name];
|
|
566
|
+
var params = [].slice.call(arguments, 1);
|
|
567
|
+
if (isFunction(macro)) {
|
|
568
|
+
return macro.apply(macro, params);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
Scope.method('block', function (name, callback) {
|
|
572
|
+
var _this = this;
|
|
573
|
+
var blocks = this.getBlocks();
|
|
574
|
+
blocks[name] = blocks[name] || [];
|
|
575
|
+
blocks[name].push(this.fn(callback));
|
|
576
|
+
if (this.getExtend()) return;
|
|
577
|
+
var list = Object.assign([], blocks[name]);
|
|
578
|
+
var current = function current() {
|
|
579
|
+
return list.shift();
|
|
580
|
+
};
|
|
581
|
+
var next = function next() {
|
|
582
|
+
var parent = current();
|
|
583
|
+
if (parent) {
|
|
584
|
+
return function () {
|
|
585
|
+
_this.echo(parent(next()));
|
|
586
|
+
};
|
|
587
|
+
} else {
|
|
588
|
+
return noop;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
this.echo(current()(next()));
|
|
592
|
+
});
|
|
593
|
+
Scope.method('include', function (path, data, cx) {
|
|
594
|
+
var context = cx === false ? {} : this.clone(true);
|
|
595
|
+
var params = extend(context, data || {});
|
|
596
|
+
var promise = this.render(path, params);
|
|
597
|
+
this.echo(promise);
|
|
598
|
+
});
|
|
599
|
+
Scope.method('use', function (path, namespace) {
|
|
600
|
+
var promise = this.require(path);
|
|
601
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
602
|
+
var list = this.getMacro();
|
|
603
|
+
each(exports, function (macro, name) {
|
|
604
|
+
list[[namespace, name].join('.')] = macro;
|
|
605
|
+
});
|
|
606
|
+
}, this));
|
|
607
|
+
});
|
|
608
|
+
Scope.method('async', function (promise, callback) {
|
|
609
|
+
this.echo(resolve$1(promise, function (data) {
|
|
610
|
+
return this.fn(callback)(data);
|
|
611
|
+
}, this));
|
|
612
|
+
});
|
|
613
|
+
Scope.method('node', function (tag, attr, content) {
|
|
640
614
|
return element(tag, attr, content);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
615
|
+
});
|
|
616
|
+
Scope.method('el', function (tag, attr, content) {
|
|
617
|
+
if (isFunction(content)) {
|
|
618
|
+
content = this.fn(content)();
|
|
619
|
+
}
|
|
620
|
+
this.echo(resolve$1(content, function (content) {
|
|
621
|
+
return element(tag, attr, content);
|
|
622
|
+
}, this));
|
|
623
|
+
});
|
|
624
|
+
Scope.method('each', function (object, callback) {
|
|
625
|
+
if (isString(object)) {
|
|
626
|
+
object = this.get(object, []);
|
|
627
|
+
}
|
|
628
|
+
each(object, callback);
|
|
629
|
+
});
|
|
630
|
+
};
|
|
631
|
+
this.configure(config);
|
|
632
|
+
}
|
|
652
633
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
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) {
|
|
645
|
+
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
646
|
+
});
|
|
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) {
|
|
659
|
+
if (scope.getExtend()) {
|
|
660
|
+
scope.setExtend(false);
|
|
661
|
+
var layout = scope.getLayout();
|
|
662
|
+
var _data = scope.clone();
|
|
663
|
+
return render(layout, _data);
|
|
664
|
+
}
|
|
665
|
+
return content;
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
this.configure = function (options) {
|
|
669
|
+
options = options || {};
|
|
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
|
|
685
698
|
});
|
|
686
|
-
}
|
|
687
|
-
this.configure = function (options) {
|
|
688
|
-
options = options || {};
|
|
689
|
-
configSchema(config, options);
|
|
690
|
-
context.configure(config, scope);
|
|
691
|
-
compiler.configure(config);
|
|
692
|
-
cache.configure(config);
|
|
693
|
-
template.configure(config);
|
|
694
|
-
return config;
|
|
695
|
-
};
|
|
696
|
-
this.render = function (name, data) {
|
|
697
|
-
return render(name, data);
|
|
698
|
-
};
|
|
699
|
-
this.helpers = function (methods) {
|
|
700
|
-
context.helpers(Object.assign(scope, methods || {}));
|
|
701
|
-
};
|
|
702
|
-
this.preload = function (list) {
|
|
703
|
-
return cache.load(list || {});
|
|
704
|
-
};
|
|
705
|
-
this.create = function (options) {
|
|
706
|
-
return new EJS(options);
|
|
707
|
-
};
|
|
708
|
-
this.compile = function (content, path) {
|
|
709
|
-
return compiler.compile(content, path);
|
|
710
|
-
};
|
|
711
|
-
this.context = function (data) {
|
|
712
|
-
return context.create(data);
|
|
713
|
-
};
|
|
714
|
-
this.helpers({
|
|
715
|
-
require: require,
|
|
716
|
-
render: render
|
|
717
|
-
});
|
|
718
|
-
}
|
|
699
|
+
}
|
|
719
700
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
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;
|
|
728
709
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
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
|
+
});
|
|
733
729
|
}
|
|
734
|
-
options = options || {};
|
|
735
|
-
var settings = extend({}, options.settings);
|
|
736
|
-
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
737
|
-
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
738
|
-
var viewOptions = extend({}, settings['view options']);
|
|
739
|
-
var filename = path.relative(viewPath, name);
|
|
740
|
-
viewOptions.path = viewPath;
|
|
741
|
-
viewOptions.cache = viewCache;
|
|
742
|
-
configure(viewOptions);
|
|
743
|
-
return this.render(filename, options).then(function (content) {
|
|
744
|
-
callback(null, content);
|
|
745
|
-
})["catch"](function (error) {
|
|
746
|
-
callback(error);
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
730
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
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;
|
|
761
742
|
|
|
762
743
|
}));
|