@kosatyi/ejs 0.0.61 → 0.0.63
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 +450 -665
- package/dist/esm/element.js +3 -2
- package/dist/esm/index.js +306 -315
- 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 +451 -666
- 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
|
@@ -13,120 +13,6 @@
|
|
|
13
13
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
14
14
|
}, _typeof(o);
|
|
15
15
|
}
|
|
16
|
-
function _classCallCheck(instance, Constructor) {
|
|
17
|
-
if (!(instance instanceof Constructor)) {
|
|
18
|
-
throw new TypeError("Cannot call a class as a function");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function _defineProperties(target, props) {
|
|
22
|
-
for (var i = 0; i < props.length; i++) {
|
|
23
|
-
var descriptor = props[i];
|
|
24
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
25
|
-
descriptor.configurable = true;
|
|
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
|
-
}
|
|
114
|
-
};
|
|
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
16
|
|
|
131
17
|
var typeProp = function typeProp() {
|
|
132
18
|
var args = [].slice.call(arguments);
|
|
@@ -185,39 +71,33 @@
|
|
|
185
71
|
return '\\' + symbolEntities[match];
|
|
186
72
|
});
|
|
187
73
|
};
|
|
188
|
-
var safeValue = function safeValue(value, escape
|
|
189
|
-
|
|
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;
|
|
190
80
|
};
|
|
191
81
|
var getPath = function getPath(context, name, strict) {
|
|
192
82
|
var data = context;
|
|
193
83
|
var chunks = String(name).split('.');
|
|
194
84
|
var prop = chunks.pop();
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
var part = _step.value;
|
|
200
|
-
if (strict && data.hasOwnProperty(part) === false) {
|
|
201
|
-
data = {};
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
data = data[part] = data[part] || {};
|
|
85
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
86
|
+
var part = chunks[i];
|
|
87
|
+
if (isFunction(data['toJSON'])) {
|
|
88
|
+
data = data.toJSON();
|
|
205
89
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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();
|
|
210
98
|
}
|
|
211
99
|
return [data, prop];
|
|
212
100
|
};
|
|
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);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
};
|
|
221
101
|
var ext = function ext(path, defaults) {
|
|
222
102
|
var ext = path.split('.').pop();
|
|
223
103
|
if (ext !== defaults) {
|
|
@@ -309,6 +189,33 @@
|
|
|
309
189
|
regex: '([\\s\\S]+?)'
|
|
310
190
|
};
|
|
311
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
|
+
|
|
312
219
|
var configSchema = function configSchema(config, options) {
|
|
313
220
|
extend(config, {
|
|
314
221
|
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
@@ -324,8 +231,6 @@
|
|
|
324
231
|
});
|
|
325
232
|
};
|
|
326
233
|
|
|
327
|
-
var path = {};
|
|
328
|
-
|
|
329
234
|
var resolvePath = function resolvePath(path, template) {
|
|
330
235
|
template = [path, template].join('/');
|
|
331
236
|
template = template.replace(/\/\//g, '/');
|
|
@@ -347,72 +252,54 @@
|
|
|
347
252
|
});
|
|
348
253
|
});
|
|
349
254
|
};
|
|
350
|
-
var
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.path = config.path;
|
|
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
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}, {
|
|
382
|
-
key: "resolve",
|
|
383
|
-
value: function resolve(template) {
|
|
384
|
-
return this.resolver(this.path, template);
|
|
385
|
-
}
|
|
386
|
-
}, {
|
|
387
|
-
key: "result",
|
|
388
|
-
value: function result(template, content) {
|
|
389
|
-
this.cache.set(template, content);
|
|
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;
|
|
264
|
+
};
|
|
265
|
+
var resolve = function resolve(path) {
|
|
266
|
+
return template.resolver(template.path, path);
|
|
267
|
+
};
|
|
268
|
+
var compile = function compile(content, template) {
|
|
269
|
+
if (isFunction(content)) {
|
|
390
270
|
return content;
|
|
271
|
+
} else {
|
|
272
|
+
return compiler.compile(content, template);
|
|
391
273
|
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return content;
|
|
397
|
-
} else {
|
|
398
|
-
return this.compiler.compile(content, template);
|
|
399
|
-
}
|
|
274
|
+
};
|
|
275
|
+
var watcher = function watcher(config) {
|
|
276
|
+
if (template.watcher) {
|
|
277
|
+
template.watcher.unwatch('.');
|
|
400
278
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
return this.cache.resolve(template);
|
|
407
|
-
}
|
|
408
|
-
var content = this.resolve(template).then(function (content) {
|
|
409
|
-
return _this2.result(template, _this2.compile(content, template));
|
|
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);
|
|
410
284
|
});
|
|
411
|
-
return this.result(template, content);
|
|
412
285
|
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
286
|
+
};
|
|
287
|
+
this.configure = function (config) {
|
|
288
|
+
template.path = config.path;
|
|
289
|
+
template.chokidar = config.chokidar;
|
|
290
|
+
template.resolver = fileResolver(config.resolver);
|
|
291
|
+
template.watcher = watcher(config);
|
|
292
|
+
};
|
|
293
|
+
this.get = function (template) {
|
|
294
|
+
if (cache.exist(template)) {
|
|
295
|
+
return cache.resolve(template);
|
|
296
|
+
}
|
|
297
|
+
return result(template, resolve(template).then(function (content) {
|
|
298
|
+
return result(template, compile(content, template));
|
|
299
|
+
}));
|
|
300
|
+
};
|
|
301
|
+
this.configure(config);
|
|
302
|
+
}
|
|
416
303
|
|
|
417
304
|
var tagList = [{
|
|
418
305
|
symbol: '-',
|
|
@@ -435,7 +322,7 @@
|
|
|
435
322
|
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
436
323
|
}
|
|
437
324
|
}];
|
|
438
|
-
|
|
325
|
+
function matchTokens(regex, text, callback) {
|
|
439
326
|
var index = 0;
|
|
440
327
|
text.replace(regex, function () {
|
|
441
328
|
var params = [].slice.call(arguments, 0, -1);
|
|
@@ -445,166 +332,109 @@
|
|
|
445
332
|
index = offset + match.length;
|
|
446
333
|
return match;
|
|
447
334
|
});
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
BUFFER = _this$vars.BUFFER,
|
|
490
|
-
COMPONENT = _this$vars.COMPONENT;
|
|
491
|
-
if (this.rmWhitespace) {
|
|
492
|
-
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
493
|
-
}
|
|
494
|
-
content = content.replace(this.slurpStart, this.token.start).replace(this.slurpEnd, this.token.end);
|
|
495
|
-
var source = "".concat(BUFFER, "('");
|
|
496
|
-
matchTokens(this.regex, content, function (params, index, offset) {
|
|
497
|
-
source += symbols(content.slice(index, offset));
|
|
498
|
-
params.forEach(function (value, index) {
|
|
499
|
-
if (value) {
|
|
500
|
-
source += _this2.formats[index](value);
|
|
501
|
-
}
|
|
502
|
-
});
|
|
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));
|
|
354
|
+
});
|
|
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
|
+
};
|
|
359
|
+
this.compile = function (content, path) {
|
|
360
|
+
var _compiler$vars = compiler.vars,
|
|
361
|
+
SCOPE = _compiler$vars.SCOPE,
|
|
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
|
+
}
|
|
503
376
|
});
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
}
|
|
377
|
+
});
|
|
378
|
+
source += "');";
|
|
379
|
+
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
380
|
+
if (compiler.withObject) {
|
|
381
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
382
|
+
}
|
|
383
|
+
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
384
|
+
source += "\n//# sourceURL=".concat(path);
|
|
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;
|
|
393
|
+
}
|
|
394
|
+
return result;
|
|
395
|
+
};
|
|
396
|
+
this.configure(config);
|
|
397
|
+
}
|
|
525
398
|
|
|
526
399
|
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
400
|
+
function Cache(config) {
|
|
401
|
+
if (instanceOf(this, Cache) === false) return new Cache();
|
|
402
|
+
var cache = {
|
|
403
|
+
list: {}
|
|
404
|
+
};
|
|
405
|
+
this.configure = function (config) {
|
|
406
|
+
cache.list = {};
|
|
532
407
|
if (isNode() === false) {
|
|
533
|
-
this.load(global[
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
_createClass(Cache, [{
|
|
537
|
-
key: "configure",
|
|
538
|
-
value: function configure(config) {
|
|
539
|
-
this.list = {};
|
|
540
|
-
this.namespace = config["export"];
|
|
541
|
-
}
|
|
542
|
-
}, {
|
|
543
|
-
key: "load",
|
|
544
|
-
value: function load(data) {
|
|
545
|
-
extend(this.list, data);
|
|
546
|
-
return this;
|
|
547
|
-
}
|
|
548
|
-
}, {
|
|
549
|
-
key: "exist",
|
|
550
|
-
value: function exist(key) {
|
|
551
|
-
return hasProp(this.list, key);
|
|
552
|
-
}
|
|
553
|
-
}, {
|
|
554
|
-
key: "get",
|
|
555
|
-
value: function get(key) {
|
|
556
|
-
return this.list[key];
|
|
557
|
-
}
|
|
558
|
-
}, {
|
|
559
|
-
key: "remove",
|
|
560
|
-
value: function remove(key) {
|
|
561
|
-
delete this.list[key];
|
|
562
|
-
}
|
|
563
|
-
}, {
|
|
564
|
-
key: "resolve",
|
|
565
|
-
value: function resolve(key) {
|
|
566
|
-
return Promise.resolve(this.get(key));
|
|
567
|
-
}
|
|
568
|
-
}, {
|
|
569
|
-
key: "set",
|
|
570
|
-
value: function set(key, value) {
|
|
571
|
-
this.list[key] = value;
|
|
572
|
-
return this;
|
|
573
|
-
}
|
|
574
|
-
}]);
|
|
575
|
-
return Cache;
|
|
576
|
-
}();
|
|
577
|
-
|
|
578
|
-
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
579
|
-
var space = ' ';
|
|
580
|
-
var quote = '"';
|
|
581
|
-
var equal = '=';
|
|
582
|
-
var slash = '/';
|
|
583
|
-
var lt = '<';
|
|
584
|
-
var gt = '>';
|
|
585
|
-
var element = function element(tag, attrs, content) {
|
|
586
|
-
var result = [];
|
|
587
|
-
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
588
|
-
var attributes = map(attrs, function (value, key) {
|
|
589
|
-
if (value !== null && value !== undefined) {
|
|
590
|
-
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
408
|
+
this.load(global[config["export"]]);
|
|
591
409
|
}
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
|
|
410
|
+
};
|
|
411
|
+
this.load = function (data) {
|
|
412
|
+
extend(cache.list, data || {});
|
|
413
|
+
return this;
|
|
414
|
+
};
|
|
415
|
+
this.get = function (key) {
|
|
416
|
+
return cache.list[key];
|
|
417
|
+
};
|
|
418
|
+
this.set = function (key, value) {
|
|
419
|
+
cache.list[key] = value;
|
|
420
|
+
return this;
|
|
421
|
+
};
|
|
422
|
+
this.resolve = function (key) {
|
|
423
|
+
return Promise.resolve(this.get(key));
|
|
424
|
+
};
|
|
425
|
+
this.remove = function (key) {
|
|
426
|
+
delete cache.list[key];
|
|
427
|
+
};
|
|
428
|
+
this.exist = function (key) {
|
|
429
|
+
return hasProp(cache.list, key);
|
|
430
|
+
};
|
|
431
|
+
}
|
|
602
432
|
|
|
603
|
-
|
|
604
|
-
return Promise.all(list).then(function (list) {
|
|
433
|
+
function resolve(list) {
|
|
434
|
+
return Promise.all(list || []).then(function (list) {
|
|
605
435
|
return list.join('');
|
|
606
436
|
});
|
|
607
|
-
}
|
|
437
|
+
}
|
|
608
438
|
var createBuffer = function createBuffer() {
|
|
609
439
|
var store = [],
|
|
610
440
|
array = [];
|
|
@@ -632,340 +462,295 @@
|
|
|
632
462
|
return buffer;
|
|
633
463
|
};
|
|
634
464
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
465
|
+
function Context(config) {
|
|
466
|
+
if (instanceOf(this, Context) === false) return new Context(config);
|
|
467
|
+
this.configure = function (config, methods) {
|
|
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);
|
|
477
|
+
};
|
|
478
|
+
this.helpers = function (methods) {
|
|
479
|
+
extend(Scope.prototype, methods || {});
|
|
480
|
+
};
|
|
481
|
+
function Scope(data) {
|
|
482
|
+
this[BLOCKS] = {};
|
|
483
|
+
this[MACRO] = {};
|
|
484
|
+
extend(this, data || {});
|
|
485
|
+
}
|
|
486
|
+
Scope.prototype = extend({}, methods || {});
|
|
487
|
+
Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
|
|
488
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
489
|
+
value: value,
|
|
490
|
+
writable: writable || false,
|
|
491
|
+
configurable: configurable || false,
|
|
492
|
+
enumerable: enumerable || false
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
Scope.define(BUFFER, createBuffer());
|
|
496
|
+
Scope.define(BLOCKS, {}, true);
|
|
497
|
+
Scope.define(MACRO, {}, true);
|
|
498
|
+
Scope.define(LAYOUT, false, true);
|
|
499
|
+
Scope.define(EXTEND, false, true);
|
|
500
|
+
Scope.method('getMacro', function () {
|
|
501
|
+
return this[MACRO];
|
|
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
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return function () {
|
|
514
|
+
console.log('%s function not defined', COMPONENT);
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
Scope.method('getBlocks', function () {
|
|
518
|
+
return this[BLOCKS];
|
|
519
|
+
});
|
|
520
|
+
Scope.method('setExtend', function (value) {
|
|
521
|
+
this[EXTEND] = value;
|
|
522
|
+
});
|
|
523
|
+
Scope.method('getExtend', function () {
|
|
524
|
+
return this[EXTEND];
|
|
525
|
+
});
|
|
526
|
+
Scope.method('setLayout', function (layout) {
|
|
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);
|
|
536
|
+
}
|
|
537
|
+
return omit(this, filter);
|
|
538
|
+
});
|
|
539
|
+
Scope.method('extend', function (layout) {
|
|
540
|
+
this.setExtend(true);
|
|
541
|
+
this.setLayout(layout);
|
|
542
|
+
});
|
|
543
|
+
Scope.method('echo', function () {
|
|
544
|
+
var buffer = this.getBuffer();
|
|
545
|
+
var params = [].slice.call(arguments);
|
|
546
|
+
params.forEach(buffer);
|
|
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();
|
|
652
557
|
};
|
|
653
|
-
|
|
654
|
-
|
|
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];
|
|
571
|
+
}
|
|
572
|
+
return result[prop] = value;
|
|
573
|
+
});
|
|
574
|
+
Scope.method('macro', function (name, callback) {
|
|
575
|
+
var list = this.getMacro();
|
|
576
|
+
var macro = this.fn(callback);
|
|
577
|
+
var context = this;
|
|
578
|
+
list[name] = function () {
|
|
579
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
655
580
|
};
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
581
|
+
});
|
|
582
|
+
Scope.method('call', function (name) {
|
|
583
|
+
var list = this.getMacro();
|
|
584
|
+
var macro = list[name];
|
|
585
|
+
var params = [].slice.call(arguments, 1);
|
|
586
|
+
if (isFunction(macro)) {
|
|
587
|
+
return macro.apply(macro, params);
|
|
661
588
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
return
|
|
672
|
-
value: value,
|
|
673
|
-
writable: writable || false,
|
|
674
|
-
configurable: configurable || false,
|
|
675
|
-
enumerable: enumerable || false
|
|
676
|
-
});
|
|
589
|
+
});
|
|
590
|
+
Scope.method('block', function (name, callback) {
|
|
591
|
+
var _this = this;
|
|
592
|
+
var blocks = this.getBlocks();
|
|
593
|
+
blocks[name] = blocks[name] || [];
|
|
594
|
+
blocks[name].push(this.fn(callback));
|
|
595
|
+
if (this.getExtend()) return;
|
|
596
|
+
var list = Object.assign([], blocks[name]);
|
|
597
|
+
var current = function current() {
|
|
598
|
+
return list.shift();
|
|
677
599
|
};
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
Scope.define(LAYOUT, false, true);
|
|
682
|
-
Scope.define(EXTEND, false, true);
|
|
683
|
-
Scope.method('initBlocks', function () {
|
|
684
|
-
this[BLOCKS] = {};
|
|
685
|
-
});
|
|
686
|
-
Scope.method('initMacro', function () {
|
|
687
|
-
this[MACRO] = {};
|
|
688
|
-
});
|
|
689
|
-
Scope.method('getMacro', function () {
|
|
690
|
-
return this[MACRO];
|
|
691
|
-
});
|
|
692
|
-
Scope.method('getBuffer', function () {
|
|
693
|
-
return this[BUFFER];
|
|
694
|
-
});
|
|
695
|
-
Scope.method('getComponent', function () {
|
|
696
|
-
var context = this;
|
|
697
|
-
if (COMPONENT in context) {
|
|
600
|
+
var next = function next() {
|
|
601
|
+
var parent = current();
|
|
602
|
+
if (parent) {
|
|
698
603
|
return function () {
|
|
699
|
-
|
|
604
|
+
_this.echo(parent(next()));
|
|
700
605
|
};
|
|
606
|
+
} else {
|
|
607
|
+
return noop;
|
|
701
608
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
});
|
|
715
|
-
Scope.method('setLayout', function (layout) {
|
|
716
|
-
this[LAYOUT] = layout;
|
|
717
|
-
});
|
|
718
|
-
Scope.method('getLayout', function () {
|
|
719
|
-
return this[LAYOUT];
|
|
720
|
-
});
|
|
721
|
-
Scope.method('clone', function (exclude_blocks) {
|
|
722
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
723
|
-
if (exclude_blocks === true) {
|
|
724
|
-
filter.push(BLOCKS);
|
|
725
|
-
}
|
|
726
|
-
return omit(this, filter);
|
|
727
|
-
});
|
|
728
|
-
Scope.method('extend', function (layout) {
|
|
729
|
-
this.setExtend(true);
|
|
730
|
-
this.setLayout(layout);
|
|
731
|
-
});
|
|
732
|
-
Scope.method('echo', function () {
|
|
733
|
-
var buffer = this.getBuffer();
|
|
734
|
-
var params = [].slice.call(arguments);
|
|
735
|
-
params.forEach(buffer);
|
|
736
|
-
});
|
|
737
|
-
Scope.method('fn', function (callback) {
|
|
738
|
-
var buffer = this.getBuffer();
|
|
739
|
-
var context = this;
|
|
740
|
-
return function () {
|
|
741
|
-
buffer.backup();
|
|
742
|
-
if (isFunction(callback)) {
|
|
743
|
-
callback.apply(context, arguments);
|
|
744
|
-
}
|
|
745
|
-
return buffer.restore();
|
|
746
|
-
};
|
|
747
|
-
});
|
|
748
|
-
Scope.method('get', function (name, defaults) {
|
|
749
|
-
var path = getPath(this, name, true);
|
|
750
|
-
var result = path.shift();
|
|
751
|
-
var prop = path.pop();
|
|
752
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
753
|
-
});
|
|
754
|
-
Scope.method('set', function (name, value) {
|
|
755
|
-
var path = getPath(this, name, false);
|
|
756
|
-
var result = path.shift();
|
|
757
|
-
var prop = path.pop();
|
|
758
|
-
if (this.getExtend() && hasProp(result, prop)) {
|
|
759
|
-
return result[prop];
|
|
760
|
-
}
|
|
761
|
-
return result[prop] = value;
|
|
762
|
-
});
|
|
763
|
-
Scope.method('macro', function (name, callback) {
|
|
764
|
-
var list = this.getMacro();
|
|
765
|
-
var macro = this.fn(callback);
|
|
766
|
-
var context = this;
|
|
767
|
-
list[name] = function () {
|
|
768
|
-
return context.echo(macro.apply(undefined, arguments));
|
|
769
|
-
};
|
|
770
|
-
});
|
|
771
|
-
Scope.method('call', function (name) {
|
|
609
|
+
};
|
|
610
|
+
this.echo(current()(next()));
|
|
611
|
+
});
|
|
612
|
+
Scope.method('include', function (path, data, cx) {
|
|
613
|
+
var context = cx === false ? {} : this.clone(true);
|
|
614
|
+
var params = extend(context, data || {});
|
|
615
|
+
var promise = this.render(path, params);
|
|
616
|
+
this.echo(promise);
|
|
617
|
+
});
|
|
618
|
+
Scope.method('use', function (path, namespace) {
|
|
619
|
+
var promise = this.require(path);
|
|
620
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
772
621
|
var list = this.getMacro();
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
if (parent) {
|
|
792
|
-
return function () {
|
|
793
|
-
_this.echo(parent(next()));
|
|
794
|
-
};
|
|
795
|
-
} else {
|
|
796
|
-
return noop;
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
this.echo(current()(next()));
|
|
800
|
-
});
|
|
801
|
-
Scope.method('include', function (path, data, cx) {
|
|
802
|
-
var context = cx === false ? {} : this.clone(true);
|
|
803
|
-
var params = extend(context, data || {});
|
|
804
|
-
var promise = this.render(path, params);
|
|
805
|
-
this.echo(promise);
|
|
806
|
-
});
|
|
807
|
-
Scope.method('use', function (path, namespace) {
|
|
808
|
-
var promise = this.require(path);
|
|
809
|
-
this.echo(resolve$1(promise, function (exports) {
|
|
810
|
-
var list = this.getMacro();
|
|
811
|
-
each(exports, function (macro, name) {
|
|
812
|
-
list[[namespace, name].join('.')] = macro;
|
|
813
|
-
});
|
|
814
|
-
}, this));
|
|
815
|
-
});
|
|
816
|
-
Scope.method('async', function (promise, callback) {
|
|
817
|
-
this.echo(resolve$1(promise, function (data) {
|
|
818
|
-
return this.fn(callback)(data);
|
|
819
|
-
}, this));
|
|
820
|
-
});
|
|
821
|
-
Scope.method('node', function (tag, attr, content) {
|
|
622
|
+
each(exports, function (macro, name) {
|
|
623
|
+
list[[namespace, name].join('.')] = macro;
|
|
624
|
+
});
|
|
625
|
+
}, this));
|
|
626
|
+
});
|
|
627
|
+
Scope.method('async', function (promise, callback) {
|
|
628
|
+
this.echo(resolve$1(promise, function (data) {
|
|
629
|
+
return this.fn(callback)(data);
|
|
630
|
+
}, this));
|
|
631
|
+
});
|
|
632
|
+
Scope.method('node', function (tag, attr, content) {
|
|
633
|
+
return element(tag, attr, content);
|
|
634
|
+
});
|
|
635
|
+
Scope.method('el', function (tag, attr, content) {
|
|
636
|
+
if (isFunction(content)) {
|
|
637
|
+
content = this.fn(content)();
|
|
638
|
+
}
|
|
639
|
+
this.echo(resolve$1(content, function (content) {
|
|
822
640
|
return element(tag, attr, content);
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
object = this.get(object, []);
|
|
835
|
-
}
|
|
836
|
-
each(object, callback);
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
}]);
|
|
840
|
-
return Context;
|
|
841
|
-
}();
|
|
641
|
+
}, this));
|
|
642
|
+
});
|
|
643
|
+
Scope.method('each', function (object, callback) {
|
|
644
|
+
if (isString(object)) {
|
|
645
|
+
object = this.get(object, []);
|
|
646
|
+
}
|
|
647
|
+
each(object, callback);
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
this.configure(config);
|
|
651
|
+
}
|
|
842
652
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
this.template = new Template(this.config, this.cache, this.compiler);
|
|
856
|
-
this.helpers({
|
|
857
|
-
require: this.require,
|
|
858
|
-
render: this.render
|
|
653
|
+
function EJS(options) {
|
|
654
|
+
if (instanceOf(this, EJS) === false) return new EJS(options);
|
|
655
|
+
var scope = {};
|
|
656
|
+
var config = {};
|
|
657
|
+
configSchema(config, options || {});
|
|
658
|
+
var context = new Context(config);
|
|
659
|
+
var compiler = new Compiler(config);
|
|
660
|
+
var cache = new Cache();
|
|
661
|
+
var template = new Template(config, cache, compiler);
|
|
662
|
+
var output = function output(path, scope) {
|
|
663
|
+
return template.get(path).then(function (callback) {
|
|
664
|
+
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
859
665
|
});
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
return
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
}, {
|
|
880
|
-
key: "render",
|
|
881
|
-
value: function render(name, data) {
|
|
882
|
-
var _this = this;
|
|
883
|
-
var filepath = ext(name, this.config.extension);
|
|
884
|
-
var scope = this.context.create(data);
|
|
885
|
-
return this.output(filepath, scope).then(function (content) {
|
|
886
|
-
if (scope.getExtend()) {
|
|
887
|
-
scope.setExtend(false);
|
|
888
|
-
var layout = scope.getLayout();
|
|
889
|
-
var _data = scope.clone();
|
|
890
|
-
return _this.render(layout, _data);
|
|
891
|
-
}
|
|
892
|
-
return content;
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
}, {
|
|
896
|
-
key: "require",
|
|
897
|
-
value: function require(name) {
|
|
898
|
-
var filepath = ext(name, this.config.extension);
|
|
899
|
-
var scope = this.context.create({});
|
|
900
|
-
return this.output(filepath, scope).then(function () {
|
|
901
|
-
return scope.getMacro();
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
}, {
|
|
905
|
-
key: "create",
|
|
906
|
-
value: function create() {
|
|
907
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
908
|
-
return new EJS(options);
|
|
909
|
-
}
|
|
910
|
-
}, {
|
|
911
|
-
key: "helpers",
|
|
912
|
-
value: function helpers() {
|
|
913
|
-
var methods = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
914
|
-
this.context.helpers(extend(this.scope, methods));
|
|
915
|
-
}
|
|
916
|
-
}, {
|
|
917
|
-
key: "preload",
|
|
918
|
-
value: function preload() {
|
|
919
|
-
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
920
|
-
return this.cache.load(list);
|
|
921
|
-
}
|
|
922
|
-
}, {
|
|
923
|
-
key: "compile",
|
|
924
|
-
value: function compile(content, path) {
|
|
925
|
-
return this.compiler.compile(content, path);
|
|
926
|
-
}
|
|
927
|
-
}, {
|
|
928
|
-
key: "__express",
|
|
929
|
-
value: function __express(name, options, callback) {
|
|
930
|
-
if (isFunction(options)) {
|
|
931
|
-
callback = options;
|
|
932
|
-
options = {};
|
|
666
|
+
};
|
|
667
|
+
var require = function require(name) {
|
|
668
|
+
var filepath = ext(name, config.extension);
|
|
669
|
+
var scope = context.create({});
|
|
670
|
+
return output(filepath, scope).then(function () {
|
|
671
|
+
return scope.getMacro();
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
var render = function render(name, data) {
|
|
675
|
+
var filepath = ext(name, config.extension);
|
|
676
|
+
var scope = context.create(data);
|
|
677
|
+
return output(filepath, scope).then(function (content) {
|
|
678
|
+
if (scope.getExtend()) {
|
|
679
|
+
scope.setExtend(false);
|
|
680
|
+
var layout = scope.getLayout();
|
|
681
|
+
var _data = scope.clone();
|
|
682
|
+
return render(layout, _data);
|
|
933
683
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
684
|
+
return content;
|
|
685
|
+
});
|
|
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
|
+
}
|
|
952
719
|
|
|
953
|
-
var ejs = new EJS(
|
|
954
|
-
|
|
955
|
-
});
|
|
956
|
-
var __express = ejs.__express,
|
|
957
|
-
render = ejs.render,
|
|
720
|
+
var ejs = new EJS();
|
|
721
|
+
var render = ejs.render,
|
|
958
722
|
context = ejs.context,
|
|
959
723
|
compile = ejs.compile,
|
|
960
724
|
helpers = ejs.helpers,
|
|
961
725
|
preload = ejs.preload,
|
|
962
|
-
configure = ejs.configure,
|
|
726
|
+
configure$1 = ejs.configure,
|
|
963
727
|
create = ejs.create;
|
|
964
728
|
|
|
729
|
+
function __express(name, options, callback) {
|
|
730
|
+
if (isFunction(options)) {
|
|
731
|
+
callback = options;
|
|
732
|
+
options = {};
|
|
733
|
+
}
|
|
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
|
+
|
|
965
750
|
exports.EJS = EJS;
|
|
966
751
|
exports.__express = __express;
|
|
967
752
|
exports.compile = compile;
|
|
968
|
-
exports.configure = configure;
|
|
753
|
+
exports.configure = configure$1;
|
|
969
754
|
exports.context = context;
|
|
970
755
|
exports.create = create;
|
|
971
756
|
exports.element = element;
|