@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/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fs = require('fs');
|
|
4
3
|
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
5
|
|
|
6
6
|
function _typeof(o) {
|
|
7
7
|
"@babel/helpers - typeof";
|
|
@@ -12,120 +12,6 @@ function _typeof(o) {
|
|
|
12
12
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
13
13
|
}, _typeof(o);
|
|
14
14
|
}
|
|
15
|
-
function _classCallCheck(instance, Constructor) {
|
|
16
|
-
if (!(instance instanceof Constructor)) {
|
|
17
|
-
throw new TypeError("Cannot call a class as a function");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function _defineProperties(target, props) {
|
|
21
|
-
for (var i = 0; i < props.length; i++) {
|
|
22
|
-
var descriptor = props[i];
|
|
23
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
24
|
-
descriptor.configurable = true;
|
|
25
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
26
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
30
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
31
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
32
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
33
|
-
writable: false
|
|
34
|
-
});
|
|
35
|
-
return Constructor;
|
|
36
|
-
}
|
|
37
|
-
function _defineProperty(obj, key, value) {
|
|
38
|
-
key = _toPropertyKey(key);
|
|
39
|
-
if (key in obj) {
|
|
40
|
-
Object.defineProperty(obj, key, {
|
|
41
|
-
value: value,
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
writable: true
|
|
45
|
-
});
|
|
46
|
-
} else {
|
|
47
|
-
obj[key] = value;
|
|
48
|
-
}
|
|
49
|
-
return obj;
|
|
50
|
-
}
|
|
51
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
52
|
-
if (!o) return;
|
|
53
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
54
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
56
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
57
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
58
|
-
}
|
|
59
|
-
function _arrayLikeToArray(arr, len) {
|
|
60
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
61
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
62
|
-
return arr2;
|
|
63
|
-
}
|
|
64
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
65
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
66
|
-
if (!it) {
|
|
67
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
68
|
-
if (it) o = it;
|
|
69
|
-
var i = 0;
|
|
70
|
-
var F = function () {};
|
|
71
|
-
return {
|
|
72
|
-
s: F,
|
|
73
|
-
n: function () {
|
|
74
|
-
if (i >= o.length) return {
|
|
75
|
-
done: true
|
|
76
|
-
};
|
|
77
|
-
return {
|
|
78
|
-
done: false,
|
|
79
|
-
value: o[i++]
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
e: function (e) {
|
|
83
|
-
throw e;
|
|
84
|
-
},
|
|
85
|
-
f: F
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
|
-
}
|
|
90
|
-
var normalCompletion = true,
|
|
91
|
-
didErr = false,
|
|
92
|
-
err;
|
|
93
|
-
return {
|
|
94
|
-
s: function () {
|
|
95
|
-
it = it.call(o);
|
|
96
|
-
},
|
|
97
|
-
n: function () {
|
|
98
|
-
var step = it.next();
|
|
99
|
-
normalCompletion = step.done;
|
|
100
|
-
return step;
|
|
101
|
-
},
|
|
102
|
-
e: function (e) {
|
|
103
|
-
didErr = true;
|
|
104
|
-
err = e;
|
|
105
|
-
},
|
|
106
|
-
f: function () {
|
|
107
|
-
try {
|
|
108
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
109
|
-
} finally {
|
|
110
|
-
if (didErr) throw err;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function _toPrimitive(input, hint) {
|
|
116
|
-
if (typeof input !== "object" || input === null) return input;
|
|
117
|
-
var prim = input[Symbol.toPrimitive];
|
|
118
|
-
if (prim !== undefined) {
|
|
119
|
-
var res = prim.call(input, hint || "default");
|
|
120
|
-
if (typeof res !== "object") return res;
|
|
121
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
122
|
-
}
|
|
123
|
-
return (hint === "string" ? String : Number)(input);
|
|
124
|
-
}
|
|
125
|
-
function _toPropertyKey(arg) {
|
|
126
|
-
var key = _toPrimitive(arg, "string");
|
|
127
|
-
return typeof key === "symbol" ? key : String(key);
|
|
128
|
-
}
|
|
129
15
|
|
|
130
16
|
var typeProp = function typeProp() {
|
|
131
17
|
var args = [].slice.call(arguments);
|
|
@@ -184,39 +70,33 @@ var symbols = function symbols(string) {
|
|
|
184
70
|
return '\\' + symbolEntities[match];
|
|
185
71
|
});
|
|
186
72
|
};
|
|
187
|
-
var safeValue = function safeValue(value, escape
|
|
188
|
-
|
|
73
|
+
var safeValue = function safeValue(value, escape) {
|
|
74
|
+
var check = value;
|
|
75
|
+
return check == null ? '' : escape === true ? entities(check) : check;
|
|
76
|
+
};
|
|
77
|
+
var instanceOf = function instanceOf(object, instance) {
|
|
78
|
+
return object instanceof instance;
|
|
189
79
|
};
|
|
190
80
|
var getPath = function getPath(context, name, strict) {
|
|
191
81
|
var data = context;
|
|
192
82
|
var chunks = String(name).split('.');
|
|
193
83
|
var prop = chunks.pop();
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var part = _step.value;
|
|
199
|
-
if (strict && data.hasOwnProperty(part) === false) {
|
|
200
|
-
data = {};
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
data = data[part] = data[part] || {};
|
|
84
|
+
for (var i = 0; i < chunks.length; i++) {
|
|
85
|
+
var part = chunks[i];
|
|
86
|
+
if (isFunction(data['toJSON'])) {
|
|
87
|
+
data = data.toJSON();
|
|
204
88
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
89
|
+
if (strict && data.hasOwnProperty(part) === false) {
|
|
90
|
+
data = {};
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
data = data[part] = data[part] || {};
|
|
94
|
+
}
|
|
95
|
+
if (isFunction(data['toJSON'])) {
|
|
96
|
+
data = data.toJSON();
|
|
209
97
|
}
|
|
210
98
|
return [data, prop];
|
|
211
99
|
};
|
|
212
|
-
var bindContext = function bindContext(object, context) {
|
|
213
|
-
var methods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
214
|
-
methods.forEach(function (name) {
|
|
215
|
-
if (name in object) {
|
|
216
|
-
object[name] = object[name].bind(context);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
};
|
|
220
100
|
var ext = function ext(path, defaults) {
|
|
221
101
|
var ext = path.split('.').pop();
|
|
222
102
|
if (ext !== defaults) {
|
|
@@ -308,6 +188,31 @@ defaults.token = {
|
|
|
308
188
|
regex: '([\\s\\S]+?)'
|
|
309
189
|
};
|
|
310
190
|
|
|
191
|
+
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
192
|
+
var space = ' ';
|
|
193
|
+
var quote = '"';
|
|
194
|
+
var equal = '=';
|
|
195
|
+
var slash = '/';
|
|
196
|
+
var lt = '<';
|
|
197
|
+
var gt = '>';
|
|
198
|
+
var element = function element(tag, attrs, content) {
|
|
199
|
+
var result = [];
|
|
200
|
+
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
201
|
+
var attributes = map(attrs, function (value, key) {
|
|
202
|
+
if (value !== null && value !== undefined) {
|
|
203
|
+
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
204
|
+
}
|
|
205
|
+
}).join(space);
|
|
206
|
+
result.push([lt, tag, space, attributes, gt].join(''));
|
|
207
|
+
if (content) {
|
|
208
|
+
result.push(content instanceof Array ? content.join('') : content);
|
|
209
|
+
}
|
|
210
|
+
if (hasClosedTag) {
|
|
211
|
+
result.push([lt, slash, tag, gt].join(''));
|
|
212
|
+
}
|
|
213
|
+
return result.join('');
|
|
214
|
+
};
|
|
215
|
+
|
|
311
216
|
var configSchema = function configSchema(config, options) {
|
|
312
217
|
extend(config, {
|
|
313
218
|
path: typeProp(isString, defaults.path, config.path, options.path),
|
|
@@ -344,72 +249,54 @@ var fileSystem = function fileSystem(path, template) {
|
|
|
344
249
|
});
|
|
345
250
|
});
|
|
346
251
|
};
|
|
347
|
-
var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.path = config.path;
|
|
363
|
-
this.chokidar = config.chokidar;
|
|
364
|
-
this.resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
365
|
-
if (config.watch && isNode()) {
|
|
366
|
-
if (this.watcher) {
|
|
367
|
-
this.watcher.unwatch('.');
|
|
368
|
-
}
|
|
369
|
-
if (this.chokidar) {
|
|
370
|
-
this.watcher = this.chokidar.watch('.', {
|
|
371
|
-
cwd: this.path
|
|
372
|
-
}).on('change', function (name) {
|
|
373
|
-
_this.cache.remove(name);
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}, {
|
|
379
|
-
key: "resolve",
|
|
380
|
-
value: function resolve(template) {
|
|
381
|
-
return this.resolver(this.path, template);
|
|
382
|
-
}
|
|
383
|
-
}, {
|
|
384
|
-
key: "result",
|
|
385
|
-
value: function result(template, content) {
|
|
386
|
-
this.cache.set(template, content);
|
|
252
|
+
var fileResolver = function fileResolver(resolver) {
|
|
253
|
+
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
254
|
+
};
|
|
255
|
+
function Template(config, cache, compiler) {
|
|
256
|
+
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
257
|
+
var template = {};
|
|
258
|
+
var result = function result(template, content) {
|
|
259
|
+
cache.set(template, content);
|
|
260
|
+
return content;
|
|
261
|
+
};
|
|
262
|
+
var resolve = function resolve(path) {
|
|
263
|
+
return template.resolver(template.path, path);
|
|
264
|
+
};
|
|
265
|
+
var compile = function compile(content, template) {
|
|
266
|
+
if (isFunction(content)) {
|
|
387
267
|
return content;
|
|
268
|
+
} else {
|
|
269
|
+
return compiler.compile(content, template);
|
|
388
270
|
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return content;
|
|
394
|
-
} else {
|
|
395
|
-
return this.compiler.compile(content, template);
|
|
396
|
-
}
|
|
271
|
+
};
|
|
272
|
+
var watcher = function watcher(config) {
|
|
273
|
+
if (template.watcher) {
|
|
274
|
+
template.watcher.unwatch('.');
|
|
397
275
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return this.cache.resolve(template);
|
|
404
|
-
}
|
|
405
|
-
var content = this.resolve(template).then(function (content) {
|
|
406
|
-
return _this2.result(template, _this2.compile(content, template));
|
|
276
|
+
if (config.watch && config.chokidar && isNode()) {
|
|
277
|
+
return config.chokidar.watch('.', {
|
|
278
|
+
cwd: template.path
|
|
279
|
+
}).on('change', function (name) {
|
|
280
|
+
cache.remove(name);
|
|
407
281
|
});
|
|
408
|
-
return this.result(template, content);
|
|
409
282
|
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
283
|
+
};
|
|
284
|
+
this.configure = function (config) {
|
|
285
|
+
template.path = config.path;
|
|
286
|
+
template.chokidar = config.chokidar;
|
|
287
|
+
template.resolver = fileResolver(config.resolver);
|
|
288
|
+
template.watcher = watcher(config);
|
|
289
|
+
};
|
|
290
|
+
this.get = function (template) {
|
|
291
|
+
if (cache.exist(template)) {
|
|
292
|
+
return cache.resolve(template);
|
|
293
|
+
}
|
|
294
|
+
return result(template, resolve(template).then(function (content) {
|
|
295
|
+
return result(template, compile(content, template));
|
|
296
|
+
}));
|
|
297
|
+
};
|
|
298
|
+
this.configure(config);
|
|
299
|
+
}
|
|
413
300
|
|
|
414
301
|
var tagList = [{
|
|
415
302
|
symbol: '-',
|
|
@@ -432,7 +319,7 @@ var tagList = [{
|
|
|
432
319
|
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
433
320
|
}
|
|
434
321
|
}];
|
|
435
|
-
|
|
322
|
+
function matchTokens(regex, text, callback) {
|
|
436
323
|
var index = 0;
|
|
437
324
|
text.replace(regex, function () {
|
|
438
325
|
var params = [].slice.call(arguments, 0, -1);
|
|
@@ -442,166 +329,109 @@ var matchTokens = function matchTokens(regex, text, callback) {
|
|
|
442
329
|
index = offset + match.length;
|
|
443
330
|
return match;
|
|
444
331
|
});
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
BUFFER = _this$vars.BUFFER,
|
|
487
|
-
COMPONENT = _this$vars.COMPONENT;
|
|
488
|
-
if (this.rmWhitespace) {
|
|
489
|
-
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
490
|
-
}
|
|
491
|
-
content = content.replace(this.slurpStart, this.token.start).replace(this.slurpEnd, this.token.end);
|
|
492
|
-
var source = "".concat(BUFFER, "('");
|
|
493
|
-
matchTokens(this.regex, content, function (params, index, offset) {
|
|
494
|
-
source += symbols(content.slice(index, offset));
|
|
495
|
-
params.forEach(function (value, index) {
|
|
496
|
-
if (value) {
|
|
497
|
-
source += _this2.formats[index](value);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
332
|
+
}
|
|
333
|
+
function Compiler(config) {
|
|
334
|
+
if (instanceOf(this, Compiler) === false) return new Compiler(config);
|
|
335
|
+
var compiler = {};
|
|
336
|
+
this.configure = function (config) {
|
|
337
|
+
compiler.withObject = config.withObject;
|
|
338
|
+
compiler.rmWhitespace = config.rmWhitespace;
|
|
339
|
+
compiler.token = config.token;
|
|
340
|
+
compiler.vars = config.vars;
|
|
341
|
+
compiler.matches = [];
|
|
342
|
+
compiler.formats = [];
|
|
343
|
+
compiler.slurp = {
|
|
344
|
+
match: '[ \\t]*',
|
|
345
|
+
start: [compiler.token.start, '_'],
|
|
346
|
+
end: ['_', compiler.token.end]
|
|
347
|
+
};
|
|
348
|
+
tagList.forEach(function (item) {
|
|
349
|
+
compiler.matches.push(compiler.token.start.concat(item.symbol).concat(compiler.token.regex).concat(compiler.token.end));
|
|
350
|
+
compiler.formats.push(item.format.bind(compiler.vars));
|
|
351
|
+
});
|
|
352
|
+
compiler.regex = new RegExp(compiler.matches.join('|').concat('|$'), 'g');
|
|
353
|
+
compiler.slurpStart = new RegExp([compiler.slurp.match, compiler.slurp.start.join('')].join(''), 'gm');
|
|
354
|
+
compiler.slurpEnd = new RegExp([compiler.slurp.end.join(''), compiler.slurp.match].join(''), 'gm');
|
|
355
|
+
};
|
|
356
|
+
this.compile = function (content, path) {
|
|
357
|
+
var _compiler$vars = compiler.vars,
|
|
358
|
+
SCOPE = _compiler$vars.SCOPE,
|
|
359
|
+
SAFE = _compiler$vars.SAFE,
|
|
360
|
+
BUFFER = _compiler$vars.BUFFER,
|
|
361
|
+
COMPONENT = _compiler$vars.COMPONENT;
|
|
362
|
+
if (compiler.rmWhitespace) {
|
|
363
|
+
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
364
|
+
}
|
|
365
|
+
content = content.replace(compiler.slurpStart, compiler.token.start).replace(compiler.slurpEnd, compiler.token.end);
|
|
366
|
+
var source = "".concat(BUFFER, "('");
|
|
367
|
+
matchTokens(compiler.regex, content, function (params, index, offset) {
|
|
368
|
+
source += symbols(content.slice(index, offset));
|
|
369
|
+
params.forEach(function (value, index) {
|
|
370
|
+
if (value) {
|
|
371
|
+
source += compiler.formats[index](value);
|
|
372
|
+
}
|
|
500
373
|
});
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
}
|
|
374
|
+
});
|
|
375
|
+
source += "');";
|
|
376
|
+
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
377
|
+
if (compiler.withObject) {
|
|
378
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
379
|
+
}
|
|
380
|
+
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
381
|
+
source += "\n//# sourceURL=".concat(path);
|
|
382
|
+
var result = null;
|
|
383
|
+
try {
|
|
384
|
+
result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
|
|
385
|
+
result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
386
|
+
} catch (e) {
|
|
387
|
+
e.filename = path;
|
|
388
|
+
e.source = source;
|
|
389
|
+
throw e;
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
};
|
|
393
|
+
this.configure(config);
|
|
394
|
+
}
|
|
522
395
|
|
|
523
396
|
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
397
|
+
function Cache(config) {
|
|
398
|
+
if (instanceOf(this, Cache) === false) return new Cache();
|
|
399
|
+
var cache = {
|
|
400
|
+
list: {}
|
|
401
|
+
};
|
|
402
|
+
this.configure = function (config) {
|
|
403
|
+
cache.list = {};
|
|
529
404
|
if (isNode() === false) {
|
|
530
|
-
this.load(global[
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
_createClass(Cache, [{
|
|
534
|
-
key: "configure",
|
|
535
|
-
value: function configure(config) {
|
|
536
|
-
this.list = {};
|
|
537
|
-
this.namespace = config["export"];
|
|
538
|
-
}
|
|
539
|
-
}, {
|
|
540
|
-
key: "load",
|
|
541
|
-
value: function load(data) {
|
|
542
|
-
extend(this.list, data);
|
|
543
|
-
return this;
|
|
544
|
-
}
|
|
545
|
-
}, {
|
|
546
|
-
key: "exist",
|
|
547
|
-
value: function exist(key) {
|
|
548
|
-
return hasProp(this.list, key);
|
|
549
|
-
}
|
|
550
|
-
}, {
|
|
551
|
-
key: "get",
|
|
552
|
-
value: function get(key) {
|
|
553
|
-
return this.list[key];
|
|
554
|
-
}
|
|
555
|
-
}, {
|
|
556
|
-
key: "remove",
|
|
557
|
-
value: function remove(key) {
|
|
558
|
-
delete this.list[key];
|
|
559
|
-
}
|
|
560
|
-
}, {
|
|
561
|
-
key: "resolve",
|
|
562
|
-
value: function resolve(key) {
|
|
563
|
-
return Promise.resolve(this.get(key));
|
|
564
|
-
}
|
|
565
|
-
}, {
|
|
566
|
-
key: "set",
|
|
567
|
-
value: function set(key, value) {
|
|
568
|
-
this.list[key] = value;
|
|
569
|
-
return this;
|
|
570
|
-
}
|
|
571
|
-
}]);
|
|
572
|
-
return Cache;
|
|
573
|
-
}();
|
|
574
|
-
|
|
575
|
-
var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
576
|
-
var space = ' ';
|
|
577
|
-
var quote = '"';
|
|
578
|
-
var equal = '=';
|
|
579
|
-
var slash = '/';
|
|
580
|
-
var lt = '<';
|
|
581
|
-
var gt = '>';
|
|
582
|
-
var element = function element(tag, attrs, content) {
|
|
583
|
-
var result = [];
|
|
584
|
-
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
585
|
-
var attributes = map(attrs, function (value, key) {
|
|
586
|
-
if (value !== null && value !== undefined) {
|
|
587
|
-
return [entities(key), [quote, entities(value), quote].join('')].join(equal);
|
|
405
|
+
this.load(global[config["export"]]);
|
|
588
406
|
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
407
|
+
};
|
|
408
|
+
this.load = function (data) {
|
|
409
|
+
extend(cache.list, data || {});
|
|
410
|
+
return this;
|
|
411
|
+
};
|
|
412
|
+
this.get = function (key) {
|
|
413
|
+
return cache.list[key];
|
|
414
|
+
};
|
|
415
|
+
this.set = function (key, value) {
|
|
416
|
+
cache.list[key] = value;
|
|
417
|
+
return this;
|
|
418
|
+
};
|
|
419
|
+
this.resolve = function (key) {
|
|
420
|
+
return Promise.resolve(this.get(key));
|
|
421
|
+
};
|
|
422
|
+
this.remove = function (key) {
|
|
423
|
+
delete cache.list[key];
|
|
424
|
+
};
|
|
425
|
+
this.exist = function (key) {
|
|
426
|
+
return hasProp(cache.list, key);
|
|
427
|
+
};
|
|
428
|
+
}
|
|
599
429
|
|
|
600
|
-
|
|
601
|
-
return Promise.all(list).then(function (list) {
|
|
430
|
+
function resolve(list) {
|
|
431
|
+
return Promise.all(list || []).then(function (list) {
|
|
602
432
|
return list.join('');
|
|
603
433
|
});
|
|
604
|
-
}
|
|
434
|
+
}
|
|
605
435
|
var createBuffer = function createBuffer() {
|
|
606
436
|
var store = [],
|
|
607
437
|
array = [];
|
|
@@ -629,340 +459,295 @@ var createBuffer = function createBuffer() {
|
|
|
629
459
|
return buffer;
|
|
630
460
|
};
|
|
631
461
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
462
|
+
function Context(config) {
|
|
463
|
+
if (instanceOf(this, Context) === false) return new Context(config);
|
|
464
|
+
this.configure = function (config, methods) {
|
|
465
|
+
var _config$vars = config.vars,
|
|
466
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
467
|
+
MACRO = _config$vars.MACRO,
|
|
468
|
+
EXTEND = _config$vars.EXTEND,
|
|
469
|
+
LAYOUT = _config$vars.LAYOUT,
|
|
470
|
+
BUFFER = _config$vars.BUFFER,
|
|
471
|
+
COMPONENT = _config$vars.COMPONENT;
|
|
472
|
+
this.create = function (data) {
|
|
473
|
+
return new Scope(data);
|
|
474
|
+
};
|
|
475
|
+
this.helpers = function (methods) {
|
|
476
|
+
extend(Scope.prototype, methods || {});
|
|
477
|
+
};
|
|
478
|
+
function Scope(data) {
|
|
479
|
+
this[BLOCKS] = {};
|
|
480
|
+
this[MACRO] = {};
|
|
481
|
+
extend(this, data || {});
|
|
482
|
+
}
|
|
483
|
+
Scope.prototype = extend({}, methods || {});
|
|
484
|
+
Scope.method = Scope.define = function (name, value, writable, configurable, enumerable) {
|
|
485
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
486
|
+
value: value,
|
|
487
|
+
writable: writable || false,
|
|
488
|
+
configurable: configurable || false,
|
|
489
|
+
enumerable: enumerable || false
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
Scope.define(BUFFER, createBuffer());
|
|
493
|
+
Scope.define(BLOCKS, {}, true);
|
|
494
|
+
Scope.define(MACRO, {}, true);
|
|
495
|
+
Scope.define(LAYOUT, false, true);
|
|
496
|
+
Scope.define(EXTEND, false, true);
|
|
497
|
+
Scope.method('getMacro', function () {
|
|
498
|
+
return this[MACRO];
|
|
499
|
+
});
|
|
500
|
+
Scope.method('getBuffer', function () {
|
|
501
|
+
return this[BUFFER];
|
|
502
|
+
});
|
|
503
|
+
Scope.method('getComponent', function () {
|
|
504
|
+
var context = this;
|
|
505
|
+
if (COMPONENT in context) {
|
|
506
|
+
return function () {
|
|
507
|
+
return context[COMPONENT].apply(context, arguments);
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
return function () {
|
|
511
|
+
console.log('%s function not defined', COMPONENT);
|
|
649
512
|
};
|
|
650
|
-
|
|
651
|
-
|
|
513
|
+
});
|
|
514
|
+
Scope.method('getBlocks', function () {
|
|
515
|
+
return this[BLOCKS];
|
|
516
|
+
});
|
|
517
|
+
Scope.method('setExtend', function (value) {
|
|
518
|
+
this[EXTEND] = value;
|
|
519
|
+
});
|
|
520
|
+
Scope.method('getExtend', function () {
|
|
521
|
+
return this[EXTEND];
|
|
522
|
+
});
|
|
523
|
+
Scope.method('setLayout', function (layout) {
|
|
524
|
+
this[LAYOUT] = layout;
|
|
525
|
+
});
|
|
526
|
+
Scope.method('getLayout', function () {
|
|
527
|
+
return this[LAYOUT];
|
|
528
|
+
});
|
|
529
|
+
Scope.method('clone', function (exclude_blocks) {
|
|
530
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
531
|
+
if (exclude_blocks === true) {
|
|
532
|
+
filter.push(BLOCKS);
|
|
533
|
+
}
|
|
534
|
+
return omit(this, filter);
|
|
535
|
+
});
|
|
536
|
+
Scope.method('extend', function (layout) {
|
|
537
|
+
this.setExtend(true);
|
|
538
|
+
this.setLayout(layout);
|
|
539
|
+
});
|
|
540
|
+
Scope.method('echo', function () {
|
|
541
|
+
var buffer = this.getBuffer();
|
|
542
|
+
var params = [].slice.call(arguments);
|
|
543
|
+
params.forEach(buffer);
|
|
544
|
+
});
|
|
545
|
+
Scope.method('fn', function (callback) {
|
|
546
|
+
var buffer = this.getBuffer();
|
|
547
|
+
var context = this;
|
|
548
|
+
return function () {
|
|
549
|
+
buffer.backup();
|
|
550
|
+
if (isFunction(callback)) {
|
|
551
|
+
callback.apply(context, arguments);
|
|
552
|
+
}
|
|
553
|
+
return buffer.restore();
|
|
652
554
|
};
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
555
|
+
});
|
|
556
|
+
Scope.method('get', function (name, defaults) {
|
|
557
|
+
var path = getPath(this, name, true);
|
|
558
|
+
var result = path.shift();
|
|
559
|
+
var prop = path.pop();
|
|
560
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
561
|
+
});
|
|
562
|
+
Scope.method('set', function (name, value) {
|
|
563
|
+
var path = getPath(this, name, false);
|
|
564
|
+
var result = path.shift();
|
|
565
|
+
var prop = path.pop();
|
|
566
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
567
|
+
return result[prop];
|
|
658
568
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
Scope.define = Scope.method = function (name, value, writable, configurable, enumerable) {
|
|
668
|
-
return Object.defineProperty(Scope.prototype, name, {
|
|
669
|
-
value: value,
|
|
670
|
-
writable: writable || false,
|
|
671
|
-
configurable: configurable || false,
|
|
672
|
-
enumerable: enumerable || false
|
|
673
|
-
});
|
|
569
|
+
return result[prop] = value;
|
|
570
|
+
});
|
|
571
|
+
Scope.method('macro', function (name, callback) {
|
|
572
|
+
var list = this.getMacro();
|
|
573
|
+
var macro = this.fn(callback);
|
|
574
|
+
var context = this;
|
|
575
|
+
list[name] = function () {
|
|
576
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
674
577
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
578
|
+
});
|
|
579
|
+
Scope.method('call', function (name) {
|
|
580
|
+
var list = this.getMacro();
|
|
581
|
+
var macro = list[name];
|
|
582
|
+
var params = [].slice.call(arguments, 1);
|
|
583
|
+
if (isFunction(macro)) {
|
|
584
|
+
return macro.apply(macro, params);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
Scope.method('block', function (name, callback) {
|
|
588
|
+
var _this = this;
|
|
589
|
+
var blocks = this.getBlocks();
|
|
590
|
+
blocks[name] = blocks[name] || [];
|
|
591
|
+
blocks[name].push(this.fn(callback));
|
|
592
|
+
if (this.getExtend()) return;
|
|
593
|
+
var list = Object.assign([], blocks[name]);
|
|
594
|
+
var current = function current() {
|
|
595
|
+
return list.shift();
|
|
596
|
+
};
|
|
597
|
+
var next = function next() {
|
|
598
|
+
var parent = current();
|
|
599
|
+
if (parent) {
|
|
695
600
|
return function () {
|
|
696
|
-
|
|
601
|
+
_this.echo(parent(next()));
|
|
697
602
|
};
|
|
603
|
+
} else {
|
|
604
|
+
return noop;
|
|
698
605
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
});
|
|
712
|
-
Scope.method('setLayout', function (layout) {
|
|
713
|
-
this[LAYOUT] = layout;
|
|
714
|
-
});
|
|
715
|
-
Scope.method('getLayout', function () {
|
|
716
|
-
return this[LAYOUT];
|
|
717
|
-
});
|
|
718
|
-
Scope.method('clone', function (exclude_blocks) {
|
|
719
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
720
|
-
if (exclude_blocks === true) {
|
|
721
|
-
filter.push(BLOCKS);
|
|
722
|
-
}
|
|
723
|
-
return omit(this, filter);
|
|
724
|
-
});
|
|
725
|
-
Scope.method('extend', function (layout) {
|
|
726
|
-
this.setExtend(true);
|
|
727
|
-
this.setLayout(layout);
|
|
728
|
-
});
|
|
729
|
-
Scope.method('echo', function () {
|
|
730
|
-
var buffer = this.getBuffer();
|
|
731
|
-
var params = [].slice.call(arguments);
|
|
732
|
-
params.forEach(buffer);
|
|
733
|
-
});
|
|
734
|
-
Scope.method('fn', function (callback) {
|
|
735
|
-
var buffer = this.getBuffer();
|
|
736
|
-
var context = this;
|
|
737
|
-
return function () {
|
|
738
|
-
buffer.backup();
|
|
739
|
-
if (isFunction(callback)) {
|
|
740
|
-
callback.apply(context, arguments);
|
|
741
|
-
}
|
|
742
|
-
return buffer.restore();
|
|
743
|
-
};
|
|
744
|
-
});
|
|
745
|
-
Scope.method('get', function (name, defaults) {
|
|
746
|
-
var path = getPath(this, name, true);
|
|
747
|
-
var result = path.shift();
|
|
748
|
-
var prop = path.pop();
|
|
749
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
750
|
-
});
|
|
751
|
-
Scope.method('set', function (name, value) {
|
|
752
|
-
var path = getPath(this, name, false);
|
|
753
|
-
var result = path.shift();
|
|
754
|
-
var prop = path.pop();
|
|
755
|
-
if (this.getExtend() && hasProp(result, prop)) {
|
|
756
|
-
return result[prop];
|
|
757
|
-
}
|
|
758
|
-
return result[prop] = value;
|
|
759
|
-
});
|
|
760
|
-
Scope.method('macro', function (name, callback) {
|
|
761
|
-
var list = this.getMacro();
|
|
762
|
-
var macro = this.fn(callback);
|
|
763
|
-
var context = this;
|
|
764
|
-
list[name] = function () {
|
|
765
|
-
return context.echo(macro.apply(undefined, arguments));
|
|
766
|
-
};
|
|
767
|
-
});
|
|
768
|
-
Scope.method('call', function (name) {
|
|
606
|
+
};
|
|
607
|
+
this.echo(current()(next()));
|
|
608
|
+
});
|
|
609
|
+
Scope.method('include', function (path, data, cx) {
|
|
610
|
+
var context = cx === false ? {} : this.clone(true);
|
|
611
|
+
var params = extend(context, data || {});
|
|
612
|
+
var promise = this.render(path, params);
|
|
613
|
+
this.echo(promise);
|
|
614
|
+
});
|
|
615
|
+
Scope.method('use', function (path, namespace) {
|
|
616
|
+
var promise = this.require(path);
|
|
617
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
769
618
|
var list = this.getMacro();
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
if (parent) {
|
|
789
|
-
return function () {
|
|
790
|
-
_this.echo(parent(next()));
|
|
791
|
-
};
|
|
792
|
-
} else {
|
|
793
|
-
return noop;
|
|
794
|
-
}
|
|
795
|
-
};
|
|
796
|
-
this.echo(current()(next()));
|
|
797
|
-
});
|
|
798
|
-
Scope.method('include', function (path, data, cx) {
|
|
799
|
-
var context = cx === false ? {} : this.clone(true);
|
|
800
|
-
var params = extend(context, data || {});
|
|
801
|
-
var promise = this.render(path, params);
|
|
802
|
-
this.echo(promise);
|
|
803
|
-
});
|
|
804
|
-
Scope.method('use', function (path, namespace) {
|
|
805
|
-
var promise = this.require(path);
|
|
806
|
-
this.echo(resolve$1(promise, function (exports) {
|
|
807
|
-
var list = this.getMacro();
|
|
808
|
-
each(exports, function (macro, name) {
|
|
809
|
-
list[[namespace, name].join('.')] = macro;
|
|
810
|
-
});
|
|
811
|
-
}, this));
|
|
812
|
-
});
|
|
813
|
-
Scope.method('async', function (promise, callback) {
|
|
814
|
-
this.echo(resolve$1(promise, function (data) {
|
|
815
|
-
return this.fn(callback)(data);
|
|
816
|
-
}, this));
|
|
817
|
-
});
|
|
818
|
-
Scope.method('node', function (tag, attr, content) {
|
|
619
|
+
each(exports, function (macro, name) {
|
|
620
|
+
list[[namespace, name].join('.')] = macro;
|
|
621
|
+
});
|
|
622
|
+
}, this));
|
|
623
|
+
});
|
|
624
|
+
Scope.method('async', function (promise, callback) {
|
|
625
|
+
this.echo(resolve$1(promise, function (data) {
|
|
626
|
+
return this.fn(callback)(data);
|
|
627
|
+
}, this));
|
|
628
|
+
});
|
|
629
|
+
Scope.method('node', function (tag, attr, content) {
|
|
630
|
+
return element(tag, attr, content);
|
|
631
|
+
});
|
|
632
|
+
Scope.method('el', function (tag, attr, content) {
|
|
633
|
+
if (isFunction(content)) {
|
|
634
|
+
content = this.fn(content)();
|
|
635
|
+
}
|
|
636
|
+
this.echo(resolve$1(content, function (content) {
|
|
819
637
|
return element(tag, attr, content);
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
object = this.get(object, []);
|
|
832
|
-
}
|
|
833
|
-
each(object, callback);
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
}]);
|
|
837
|
-
return Context;
|
|
838
|
-
}();
|
|
638
|
+
}, this));
|
|
639
|
+
});
|
|
640
|
+
Scope.method('each', function (object, callback) {
|
|
641
|
+
if (isString(object)) {
|
|
642
|
+
object = this.get(object, []);
|
|
643
|
+
}
|
|
644
|
+
each(object, callback);
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
this.configure(config);
|
|
648
|
+
}
|
|
839
649
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
this.template = new Template(this.config, this.cache, this.compiler);
|
|
853
|
-
this.helpers({
|
|
854
|
-
require: this.require,
|
|
855
|
-
render: this.render
|
|
650
|
+
function EJS(options) {
|
|
651
|
+
if (instanceOf(this, EJS) === false) return new EJS(options);
|
|
652
|
+
var scope = {};
|
|
653
|
+
var config = {};
|
|
654
|
+
configSchema(config, options || {});
|
|
655
|
+
var context = new Context(config);
|
|
656
|
+
var compiler = new Compiler(config);
|
|
657
|
+
var cache = new Cache();
|
|
658
|
+
var template = new Template(config, cache, compiler);
|
|
659
|
+
var output = function output(path, scope) {
|
|
660
|
+
return template.get(path).then(function (callback) {
|
|
661
|
+
return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
|
|
856
662
|
});
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
return
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
}, {
|
|
877
|
-
key: "render",
|
|
878
|
-
value: function render(name, data) {
|
|
879
|
-
var _this = this;
|
|
880
|
-
var filepath = ext(name, this.config.extension);
|
|
881
|
-
var scope = this.context.create(data);
|
|
882
|
-
return this.output(filepath, scope).then(function (content) {
|
|
883
|
-
if (scope.getExtend()) {
|
|
884
|
-
scope.setExtend(false);
|
|
885
|
-
var layout = scope.getLayout();
|
|
886
|
-
var _data = scope.clone();
|
|
887
|
-
return _this.render(layout, _data);
|
|
888
|
-
}
|
|
889
|
-
return content;
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
}, {
|
|
893
|
-
key: "require",
|
|
894
|
-
value: function require(name) {
|
|
895
|
-
var filepath = ext(name, this.config.extension);
|
|
896
|
-
var scope = this.context.create({});
|
|
897
|
-
return this.output(filepath, scope).then(function () {
|
|
898
|
-
return scope.getMacro();
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
}, {
|
|
902
|
-
key: "create",
|
|
903
|
-
value: function create() {
|
|
904
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
905
|
-
return new EJS(options);
|
|
906
|
-
}
|
|
907
|
-
}, {
|
|
908
|
-
key: "helpers",
|
|
909
|
-
value: function helpers() {
|
|
910
|
-
var methods = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
911
|
-
this.context.helpers(extend(this.scope, methods));
|
|
912
|
-
}
|
|
913
|
-
}, {
|
|
914
|
-
key: "preload",
|
|
915
|
-
value: function preload() {
|
|
916
|
-
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
917
|
-
return this.cache.load(list);
|
|
918
|
-
}
|
|
919
|
-
}, {
|
|
920
|
-
key: "compile",
|
|
921
|
-
value: function compile(content, path) {
|
|
922
|
-
return this.compiler.compile(content, path);
|
|
923
|
-
}
|
|
924
|
-
}, {
|
|
925
|
-
key: "__express",
|
|
926
|
-
value: function __express(name, options, callback) {
|
|
927
|
-
if (isFunction(options)) {
|
|
928
|
-
callback = options;
|
|
929
|
-
options = {};
|
|
663
|
+
};
|
|
664
|
+
var require = function require(name) {
|
|
665
|
+
var filepath = ext(name, config.extension);
|
|
666
|
+
var scope = context.create({});
|
|
667
|
+
return output(filepath, scope).then(function () {
|
|
668
|
+
return scope.getMacro();
|
|
669
|
+
});
|
|
670
|
+
};
|
|
671
|
+
var render = function render(name, data) {
|
|
672
|
+
var filepath = ext(name, config.extension);
|
|
673
|
+
var scope = context.create(data);
|
|
674
|
+
return output(filepath, scope).then(function (content) {
|
|
675
|
+
if (scope.getExtend()) {
|
|
676
|
+
scope.setExtend(false);
|
|
677
|
+
var layout = scope.getLayout();
|
|
678
|
+
var _data = scope.clone();
|
|
679
|
+
return render(layout, _data);
|
|
930
680
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
}
|
|
681
|
+
return content;
|
|
682
|
+
});
|
|
683
|
+
};
|
|
684
|
+
this.configure = function (options) {
|
|
685
|
+
options = options || {};
|
|
686
|
+
configSchema(config, options);
|
|
687
|
+
context.configure(config, scope);
|
|
688
|
+
compiler.configure(config);
|
|
689
|
+
cache.configure(config);
|
|
690
|
+
template.configure(config);
|
|
691
|
+
return config;
|
|
692
|
+
};
|
|
693
|
+
this.render = function (name, data) {
|
|
694
|
+
return render(name, data);
|
|
695
|
+
};
|
|
696
|
+
this.helpers = function (methods) {
|
|
697
|
+
context.helpers(Object.assign(scope, methods || {}));
|
|
698
|
+
};
|
|
699
|
+
this.preload = function (list) {
|
|
700
|
+
return cache.load(list || {});
|
|
701
|
+
};
|
|
702
|
+
this.create = function (options) {
|
|
703
|
+
return new EJS(options);
|
|
704
|
+
};
|
|
705
|
+
this.compile = function (content, path) {
|
|
706
|
+
return compiler.compile(content, path);
|
|
707
|
+
};
|
|
708
|
+
this.context = function (data) {
|
|
709
|
+
return context.create(data);
|
|
710
|
+
};
|
|
711
|
+
this.helpers({
|
|
712
|
+
require: require,
|
|
713
|
+
render: render
|
|
714
|
+
});
|
|
715
|
+
}
|
|
949
716
|
|
|
950
|
-
var ejs = new EJS(
|
|
951
|
-
|
|
952
|
-
});
|
|
953
|
-
var __express = ejs.__express,
|
|
954
|
-
render = ejs.render,
|
|
717
|
+
var ejs = new EJS();
|
|
718
|
+
var render = ejs.render,
|
|
955
719
|
context = ejs.context,
|
|
956
720
|
compile = ejs.compile,
|
|
957
721
|
helpers = ejs.helpers,
|
|
958
722
|
preload = ejs.preload,
|
|
959
|
-
configure = ejs.configure,
|
|
723
|
+
configure$1 = ejs.configure,
|
|
960
724
|
create = ejs.create;
|
|
961
725
|
|
|
726
|
+
function __express(name, options, callback) {
|
|
727
|
+
if (isFunction(options)) {
|
|
728
|
+
callback = options;
|
|
729
|
+
options = {};
|
|
730
|
+
}
|
|
731
|
+
options = options || {};
|
|
732
|
+
var settings = extend({}, options.settings);
|
|
733
|
+
var viewPath = typeProp(isString, defaults.path, settings['views']);
|
|
734
|
+
var viewCache = typeProp(isBoolean, defaults.cache, settings['view cache']);
|
|
735
|
+
var viewOptions = extend({}, settings['view options']);
|
|
736
|
+
var filename = path.relative(viewPath, name);
|
|
737
|
+
viewOptions.path = viewPath;
|
|
738
|
+
viewOptions.cache = viewCache;
|
|
739
|
+
configure(viewOptions);
|
|
740
|
+
return this.render(filename, options).then(function (content) {
|
|
741
|
+
callback(null, content);
|
|
742
|
+
})["catch"](function (error) {
|
|
743
|
+
callback(error);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
|
|
962
747
|
exports.EJS = EJS;
|
|
963
748
|
exports.__express = __express;
|
|
964
749
|
exports.compile = compile;
|
|
965
|
-
exports.configure = configure;
|
|
750
|
+
exports.configure = configure$1;
|
|
966
751
|
exports.context = context;
|
|
967
752
|
exports.create = create;
|
|
968
753
|
exports.element = element;
|