@kosatyi/ejs 0.0.24 → 0.0.25
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/ejs.cjs +76 -87
- package/dist/ejs.js +76 -87
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +140 -136
- package/package.json +1 -1
- package/dist/templates.js +0 -2
package/dist/ejs.cjs
CHANGED
|
@@ -47,7 +47,10 @@ var isBoolean = function isBoolean(v) {
|
|
|
47
47
|
return typeof v === 'boolean';
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
var
|
|
50
|
+
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
51
|
+
var isNode = function isNode() {
|
|
52
|
+
return isNodeEnv;
|
|
53
|
+
};
|
|
51
54
|
var symbolEntities = {
|
|
52
55
|
"'": "'",
|
|
53
56
|
'\\': '\\',
|
|
@@ -92,6 +95,13 @@ var getPath = function getPath(context, name) {
|
|
|
92
95
|
});
|
|
93
96
|
return [data, prop];
|
|
94
97
|
};
|
|
98
|
+
var ext = function ext(path, defaults) {
|
|
99
|
+
var ext = path.split('.').pop();
|
|
100
|
+
if (ext !== defaults) {
|
|
101
|
+
path = [path, defaults].join('.');
|
|
102
|
+
}
|
|
103
|
+
return path;
|
|
104
|
+
};
|
|
95
105
|
var extend = function extend() {
|
|
96
106
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
97
107
|
args[_key] = arguments[_key];
|
|
@@ -208,13 +218,7 @@ var match = function match(regex, text, callback) {
|
|
|
208
218
|
return match;
|
|
209
219
|
});
|
|
210
220
|
};
|
|
211
|
-
|
|
212
|
-
*
|
|
213
|
-
* @param {object} config
|
|
214
|
-
* @return {function(*, *): Function}
|
|
215
|
-
* @constructor
|
|
216
|
-
*/
|
|
217
|
-
var Compiler = function Compiler(config) {
|
|
221
|
+
var configureCompiler = function configureCompiler(ejs, config) {
|
|
218
222
|
var withObject = config.withObject;
|
|
219
223
|
var token = config.token;
|
|
220
224
|
var vars = config.vars;
|
|
@@ -232,11 +236,7 @@ var Compiler = function Compiler(config) {
|
|
|
232
236
|
var regex = new RegExp(matches.join('|').concat('|$'), 'g');
|
|
233
237
|
var slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
|
|
234
238
|
var slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
|
|
235
|
-
|
|
236
|
-
* @type function
|
|
237
|
-
* @name Compile
|
|
238
|
-
*/
|
|
239
|
-
return function (content, path) {
|
|
239
|
+
return function compiler(content, path) {
|
|
240
240
|
var SCOPE = vars.SCOPE,
|
|
241
241
|
SAFE = vars.SAFE,
|
|
242
242
|
BUFFER = vars.BUFFER;
|
|
@@ -269,24 +269,34 @@ var Compiler = function Compiler(config) {
|
|
|
269
269
|
};
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
-
var
|
|
272
|
+
var configureWrapper = function configureWrapper(config) {
|
|
273
273
|
var name = config["export"];
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
var useStrict = config.withObject !== true;
|
|
275
|
+
return function Wrapper(list) {
|
|
276
|
+
var out = '';
|
|
277
|
+
out += '(function(global,factory){';
|
|
278
|
+
out += 'typeof exports === "object" && typeof module !== "undefined" ?';
|
|
279
|
+
out += 'module.exports = factory():';
|
|
280
|
+
out += 'typeof define === "function" && define.amd ? define(factory):';
|
|
281
|
+
out += '(global = typeof globalThis !== "undefined" ? globalThis:';
|
|
282
|
+
out += 'global || self,global["' + name + '"] = factory())';
|
|
283
|
+
out += '})(this,(function(){';
|
|
284
|
+
if (useStrict) out += "'use strict';\n";
|
|
285
|
+
out += 'var list = {};\n';
|
|
276
286
|
list.forEach(function (item) {
|
|
277
|
-
out += '
|
|
287
|
+
out += 'list[' + JSON.stringify(item.name) + ']=' + String(item.content) + ';\n';
|
|
278
288
|
});
|
|
279
|
-
out += '
|
|
289
|
+
out += 'return list;}));\n';
|
|
280
290
|
return out;
|
|
281
291
|
};
|
|
282
292
|
};
|
|
283
293
|
|
|
284
|
-
var
|
|
285
|
-
return
|
|
294
|
+
var httpRequest = function httpRequest(template) {
|
|
295
|
+
return fetch(template).then(function (response) {
|
|
286
296
|
return response.text();
|
|
287
297
|
});
|
|
288
298
|
};
|
|
289
|
-
var
|
|
299
|
+
var fileSystem = function fileSystem(template) {
|
|
290
300
|
return new Promise(function (resolve, reject) {
|
|
291
301
|
fs__default["default"].readFile(template, function (error, data) {
|
|
292
302
|
if (error) {
|
|
@@ -297,7 +307,7 @@ var FileSystem = function FileSystem(template) {
|
|
|
297
307
|
});
|
|
298
308
|
});
|
|
299
309
|
};
|
|
300
|
-
var
|
|
310
|
+
var enableWatcher = function enableWatcher(path, cache) {
|
|
301
311
|
return chokidar__default["default"].watch('.', {
|
|
302
312
|
cwd: path
|
|
303
313
|
}).on('change', function (name) {
|
|
@@ -306,10 +316,11 @@ var Watcher = function Watcher(path, cache) {
|
|
|
306
316
|
console.log('watcher error: ' + error);
|
|
307
317
|
});
|
|
308
318
|
};
|
|
309
|
-
var
|
|
319
|
+
var configureTemplate = function configureTemplate(ejs, config) {
|
|
310
320
|
var path = config.path;
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
var cache = ejs.cache,
|
|
322
|
+
compile = ejs.compile;
|
|
323
|
+
var resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
313
324
|
var normalize = function normalize(template) {
|
|
314
325
|
template = [path, template].join('/');
|
|
315
326
|
template = template.replace(/\/\//g, '/');
|
|
@@ -322,19 +333,19 @@ var Template = function Template(config, cache, compile) {
|
|
|
322
333
|
cache.set(template, content);
|
|
323
334
|
return content;
|
|
324
335
|
};
|
|
325
|
-
var
|
|
326
|
-
if (cache.exist(
|
|
327
|
-
return cache.resolve(
|
|
336
|
+
var template = function template(_template) {
|
|
337
|
+
if (cache.exist(_template)) {
|
|
338
|
+
return cache.resolve(_template);
|
|
328
339
|
}
|
|
329
|
-
var content = resolve(
|
|
330
|
-
return result(compile(content,
|
|
340
|
+
var content = resolve(_template).then(function (content) {
|
|
341
|
+
return result(compile(content, _template), _template);
|
|
331
342
|
});
|
|
332
|
-
return result(content,
|
|
343
|
+
return result(content, _template);
|
|
333
344
|
};
|
|
334
345
|
if (config.watch && isNode()) {
|
|
335
|
-
|
|
346
|
+
enableWatcher(path, cache);
|
|
336
347
|
}
|
|
337
|
-
return
|
|
348
|
+
return template;
|
|
338
349
|
};
|
|
339
350
|
|
|
340
351
|
var resolve = function resolve(list) {
|
|
@@ -342,11 +353,7 @@ var resolve = function resolve(list) {
|
|
|
342
353
|
return list.join('');
|
|
343
354
|
});
|
|
344
355
|
};
|
|
345
|
-
|
|
346
|
-
*
|
|
347
|
-
* @return {function}
|
|
348
|
-
*/
|
|
349
|
-
var Buffer = function Buffer() {
|
|
356
|
+
var createBuffer = function createBuffer() {
|
|
350
357
|
var store = [],
|
|
351
358
|
array = [];
|
|
352
359
|
function buffer(value) {
|
|
@@ -373,7 +380,7 @@ var Buffer = function Buffer() {
|
|
|
373
380
|
return buffer;
|
|
374
381
|
};
|
|
375
382
|
|
|
376
|
-
var
|
|
383
|
+
var configureScope = function configureScope(ejs, config) {
|
|
377
384
|
var _config$vars = config.vars,
|
|
378
385
|
EXTEND = _config$vars.EXTEND,
|
|
379
386
|
LAYOUT = _config$vars.LAYOUT,
|
|
@@ -401,7 +408,7 @@ var configure = function configure(config, methods) {
|
|
|
401
408
|
});
|
|
402
409
|
};
|
|
403
410
|
Scope.property(BUFFER, {
|
|
404
|
-
value:
|
|
411
|
+
value: createBuffer(),
|
|
405
412
|
writable: false,
|
|
406
413
|
configurable: false,
|
|
407
414
|
enumerable: false
|
|
@@ -573,17 +580,17 @@ var configure = function configure(config, methods) {
|
|
|
573
580
|
}
|
|
574
581
|
each(object, callback);
|
|
575
582
|
});
|
|
576
|
-
Scope.helpers(methods);
|
|
577
583
|
return Scope;
|
|
578
584
|
};
|
|
579
585
|
|
|
580
|
-
|
|
586
|
+
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
587
|
+
function configureCache(config) {
|
|
581
588
|
var namespace = config["export"];
|
|
582
589
|
var list = {};
|
|
583
590
|
var cache = {
|
|
584
591
|
preload: function preload() {
|
|
585
592
|
if (isNode() === false) {
|
|
586
|
-
this.load(
|
|
593
|
+
this.load(global[namespace]);
|
|
587
594
|
}
|
|
588
595
|
return this;
|
|
589
596
|
},
|
|
@@ -611,53 +618,40 @@ function Cache(config) {
|
|
|
611
618
|
return cache.preload();
|
|
612
619
|
}
|
|
613
620
|
|
|
614
|
-
function
|
|
615
|
-
/**
|
|
616
|
-
* @type {Object}
|
|
617
|
-
*/
|
|
621
|
+
function create(options) {
|
|
618
622
|
var config = {};
|
|
619
|
-
var
|
|
620
|
-
var ext = function ext(path, defaults) {
|
|
621
|
-
var ext = path.split('.').pop();
|
|
622
|
-
if (ext !== defaults) {
|
|
623
|
-
path = [path, defaults].join('.');
|
|
624
|
-
}
|
|
625
|
-
return path;
|
|
626
|
-
};
|
|
627
|
-
var view = {
|
|
623
|
+
var ejs = {
|
|
628
624
|
safeValue: safeValue,
|
|
629
625
|
element: element,
|
|
630
626
|
output: function output(path, scope) {
|
|
631
|
-
return
|
|
627
|
+
return ejs.template(path).then(function (template) {
|
|
632
628
|
return template.call(scope, scope, scope.getBuffer(), safeValue);
|
|
633
629
|
});
|
|
634
630
|
},
|
|
635
631
|
render: function render(name, data) {
|
|
636
632
|
var filepath = ext(name, config.extension);
|
|
637
|
-
var scope = new
|
|
638
|
-
return
|
|
633
|
+
var scope = new ejs.scope(data);
|
|
634
|
+
return ejs.output(filepath, scope).then(function (content) {
|
|
639
635
|
if (scope.getExtend()) {
|
|
640
636
|
scope.setExtend(false);
|
|
641
637
|
var layout = scope.getLayout();
|
|
642
638
|
var _data = scope.clone();
|
|
643
|
-
return
|
|
639
|
+
return ejs.render(layout, _data);
|
|
644
640
|
}
|
|
645
641
|
return content;
|
|
646
642
|
});
|
|
647
643
|
},
|
|
648
644
|
require: function require(name) {
|
|
649
645
|
var filepath = ext(name, config.extension);
|
|
650
|
-
var scope = new
|
|
651
|
-
return
|
|
646
|
+
var scope = new ejs.scope({});
|
|
647
|
+
return ejs.output(filepath, scope).then(function () {
|
|
652
648
|
return scope.getMacro();
|
|
653
649
|
});
|
|
654
650
|
},
|
|
655
651
|
helpers: function helpers(methods) {
|
|
656
|
-
methods
|
|
657
|
-
extend(_helpers, methods);
|
|
658
|
-
view.scope.helpers(methods);
|
|
652
|
+
ejs.scope.helpers(methods);
|
|
659
653
|
},
|
|
660
|
-
configure: function configure
|
|
654
|
+
configure: function configure(options) {
|
|
661
655
|
config["export"] = typeProp(isString, defaults["export"], options["export"]);
|
|
662
656
|
config.path = typeProp(isString, defaults.path, options.path);
|
|
663
657
|
config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
|
|
@@ -665,12 +659,12 @@ function init(options) {
|
|
|
665
659
|
config.withObject = typeProp(isBoolean, defaults.withObject, options.withObject);
|
|
666
660
|
config.token = extend({}, defaults.token, options.token);
|
|
667
661
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
return
|
|
662
|
+
ejs.scope = configureScope(ejs, config);
|
|
663
|
+
ejs.compile = configureCompiler(ejs, config);
|
|
664
|
+
ejs.wrapper = configureWrapper(ejs);
|
|
665
|
+
ejs.cache = configureCache(ejs);
|
|
666
|
+
ejs.template = configureTemplate(ejs, config);
|
|
667
|
+
return ejs;
|
|
674
668
|
},
|
|
675
669
|
__express: function __express(name, options, callback) {
|
|
676
670
|
if (isFunction(options)) {
|
|
@@ -685,31 +679,26 @@ function init(options) {
|
|
|
685
679
|
var filename = path__default["default"].relative(viewPath, name);
|
|
686
680
|
viewOptions.path = viewPath;
|
|
687
681
|
viewOptions.cache = viewCache;
|
|
688
|
-
|
|
689
|
-
return
|
|
682
|
+
ejs.configure(viewOptions);
|
|
683
|
+
return ejs.render(filename, options).then(function (content) {
|
|
690
684
|
callback(null, content);
|
|
691
685
|
})["catch"](function (error) {
|
|
692
686
|
callback(error);
|
|
693
687
|
});
|
|
694
688
|
}
|
|
695
689
|
};
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
*/
|
|
699
|
-
view.configure(options || {});
|
|
700
|
-
/**
|
|
701
|
-
*
|
|
702
|
-
*/
|
|
703
|
-
view.helpers({
|
|
690
|
+
ejs.configure(options || {});
|
|
691
|
+
ejs.helpers({
|
|
704
692
|
require: function require(name) {
|
|
705
|
-
return
|
|
693
|
+
return ejs.require(name, this);
|
|
706
694
|
},
|
|
707
695
|
render: function render(name, data) {
|
|
708
|
-
return
|
|
696
|
+
return ejs.render(name, data);
|
|
709
697
|
}
|
|
710
698
|
});
|
|
711
|
-
return
|
|
699
|
+
return ejs;
|
|
712
700
|
}
|
|
713
|
-
var
|
|
701
|
+
var instance = create();
|
|
702
|
+
instance.create = create;
|
|
714
703
|
|
|
715
|
-
module.exports =
|
|
704
|
+
module.exports = instance;
|
package/dist/ejs.js
CHANGED
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
return typeof v === 'boolean';
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
var
|
|
46
|
+
var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
47
|
+
var isNode = function isNode() {
|
|
48
|
+
return isNodeEnv;
|
|
49
|
+
};
|
|
47
50
|
var symbolEntities = {
|
|
48
51
|
"'": "'",
|
|
49
52
|
'\\': '\\',
|
|
@@ -88,6 +91,13 @@
|
|
|
88
91
|
});
|
|
89
92
|
return [data, prop];
|
|
90
93
|
};
|
|
94
|
+
var ext = function ext(path, defaults) {
|
|
95
|
+
var ext = path.split('.').pop();
|
|
96
|
+
if (ext !== defaults) {
|
|
97
|
+
path = [path, defaults].join('.');
|
|
98
|
+
}
|
|
99
|
+
return path;
|
|
100
|
+
};
|
|
91
101
|
var extend = function extend() {
|
|
92
102
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
93
103
|
args[_key] = arguments[_key];
|
|
@@ -204,13 +214,7 @@
|
|
|
204
214
|
return match;
|
|
205
215
|
});
|
|
206
216
|
};
|
|
207
|
-
|
|
208
|
-
*
|
|
209
|
-
* @param {object} config
|
|
210
|
-
* @return {function(*, *): Function}
|
|
211
|
-
* @constructor
|
|
212
|
-
*/
|
|
213
|
-
var Compiler = function Compiler(config) {
|
|
217
|
+
var configureCompiler = function configureCompiler(ejs, config) {
|
|
214
218
|
var withObject = config.withObject;
|
|
215
219
|
var token = config.token;
|
|
216
220
|
var vars = config.vars;
|
|
@@ -228,11 +232,7 @@
|
|
|
228
232
|
var regex = new RegExp(matches.join('|').concat('|$'), 'g');
|
|
229
233
|
var slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
|
|
230
234
|
var slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
|
|
231
|
-
|
|
232
|
-
* @type function
|
|
233
|
-
* @name Compile
|
|
234
|
-
*/
|
|
235
|
-
return function (content, path) {
|
|
235
|
+
return function compiler(content, path) {
|
|
236
236
|
var SCOPE = vars.SCOPE,
|
|
237
237
|
SAFE = vars.SAFE,
|
|
238
238
|
BUFFER = vars.BUFFER;
|
|
@@ -265,24 +265,34 @@
|
|
|
265
265
|
};
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
-
var
|
|
268
|
+
var configureWrapper = function configureWrapper(config) {
|
|
269
269
|
var name = config["export"];
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
var useStrict = config.withObject !== true;
|
|
271
|
+
return function Wrapper(list) {
|
|
272
|
+
var out = '';
|
|
273
|
+
out += '(function(global,factory){';
|
|
274
|
+
out += 'typeof exports === "object" && typeof module !== "undefined" ?';
|
|
275
|
+
out += 'module.exports = factory():';
|
|
276
|
+
out += 'typeof define === "function" && define.amd ? define(factory):';
|
|
277
|
+
out += '(global = typeof globalThis !== "undefined" ? globalThis:';
|
|
278
|
+
out += 'global || self,global["' + name + '"] = factory())';
|
|
279
|
+
out += '})(this,(function(){';
|
|
280
|
+
if (useStrict) out += "'use strict';\n";
|
|
281
|
+
out += 'var list = {};\n';
|
|
272
282
|
list.forEach(function (item) {
|
|
273
|
-
out += '
|
|
283
|
+
out += 'list[' + JSON.stringify(item.name) + ']=' + String(item.content) + ';\n';
|
|
274
284
|
});
|
|
275
|
-
out += '
|
|
285
|
+
out += 'return list;}));\n';
|
|
276
286
|
return out;
|
|
277
287
|
};
|
|
278
288
|
};
|
|
279
289
|
|
|
280
|
-
var
|
|
281
|
-
return
|
|
290
|
+
var httpRequest = function httpRequest(template) {
|
|
291
|
+
return fetch(template).then(function (response) {
|
|
282
292
|
return response.text();
|
|
283
293
|
});
|
|
284
294
|
};
|
|
285
|
-
var
|
|
295
|
+
var fileSystem = function fileSystem(template) {
|
|
286
296
|
return new Promise(function (resolve, reject) {
|
|
287
297
|
path.readFile(template, function (error, data) {
|
|
288
298
|
if (error) {
|
|
@@ -293,7 +303,7 @@
|
|
|
293
303
|
});
|
|
294
304
|
});
|
|
295
305
|
};
|
|
296
|
-
var
|
|
306
|
+
var enableWatcher = function enableWatcher(path$1, cache) {
|
|
297
307
|
return path.watch('.', {
|
|
298
308
|
cwd: path$1
|
|
299
309
|
}).on('change', function (name) {
|
|
@@ -302,10 +312,11 @@
|
|
|
302
312
|
console.log('watcher error: ' + error);
|
|
303
313
|
});
|
|
304
314
|
};
|
|
305
|
-
var
|
|
315
|
+
var configureTemplate = function configureTemplate(ejs, config) {
|
|
306
316
|
var path = config.path;
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
var cache = ejs.cache,
|
|
318
|
+
compile = ejs.compile;
|
|
319
|
+
var resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
309
320
|
var normalize = function normalize(template) {
|
|
310
321
|
template = [path, template].join('/');
|
|
311
322
|
template = template.replace(/\/\//g, '/');
|
|
@@ -318,19 +329,19 @@
|
|
|
318
329
|
cache.set(template, content);
|
|
319
330
|
return content;
|
|
320
331
|
};
|
|
321
|
-
var
|
|
322
|
-
if (cache.exist(
|
|
323
|
-
return cache.resolve(
|
|
332
|
+
var template = function template(_template) {
|
|
333
|
+
if (cache.exist(_template)) {
|
|
334
|
+
return cache.resolve(_template);
|
|
324
335
|
}
|
|
325
|
-
var content = resolve(
|
|
326
|
-
return result(compile(content,
|
|
336
|
+
var content = resolve(_template).then(function (content) {
|
|
337
|
+
return result(compile(content, _template), _template);
|
|
327
338
|
});
|
|
328
|
-
return result(content,
|
|
339
|
+
return result(content, _template);
|
|
329
340
|
};
|
|
330
341
|
if (config.watch && isNode()) {
|
|
331
|
-
|
|
342
|
+
enableWatcher(path, cache);
|
|
332
343
|
}
|
|
333
|
-
return
|
|
344
|
+
return template;
|
|
334
345
|
};
|
|
335
346
|
|
|
336
347
|
var resolve = function resolve(list) {
|
|
@@ -338,11 +349,7 @@
|
|
|
338
349
|
return list.join('');
|
|
339
350
|
});
|
|
340
351
|
};
|
|
341
|
-
|
|
342
|
-
*
|
|
343
|
-
* @return {function}
|
|
344
|
-
*/
|
|
345
|
-
var Buffer = function Buffer() {
|
|
352
|
+
var createBuffer = function createBuffer() {
|
|
346
353
|
var store = [],
|
|
347
354
|
array = [];
|
|
348
355
|
function buffer(value) {
|
|
@@ -369,7 +376,7 @@
|
|
|
369
376
|
return buffer;
|
|
370
377
|
};
|
|
371
378
|
|
|
372
|
-
var
|
|
379
|
+
var configureScope = function configureScope(ejs, config) {
|
|
373
380
|
var _config$vars = config.vars,
|
|
374
381
|
EXTEND = _config$vars.EXTEND,
|
|
375
382
|
LAYOUT = _config$vars.LAYOUT,
|
|
@@ -397,7 +404,7 @@
|
|
|
397
404
|
});
|
|
398
405
|
};
|
|
399
406
|
Scope.property(BUFFER, {
|
|
400
|
-
value:
|
|
407
|
+
value: createBuffer(),
|
|
401
408
|
writable: false,
|
|
402
409
|
configurable: false,
|
|
403
410
|
enumerable: false
|
|
@@ -569,17 +576,17 @@
|
|
|
569
576
|
}
|
|
570
577
|
each(object, callback);
|
|
571
578
|
});
|
|
572
|
-
Scope.helpers(methods);
|
|
573
579
|
return Scope;
|
|
574
580
|
};
|
|
575
581
|
|
|
576
|
-
|
|
582
|
+
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
583
|
+
function configureCache(config) {
|
|
577
584
|
var namespace = config["export"];
|
|
578
585
|
var list = {};
|
|
579
586
|
var cache = {
|
|
580
587
|
preload: function preload() {
|
|
581
588
|
if (isNode() === false) {
|
|
582
|
-
this.load(
|
|
589
|
+
this.load(global[namespace]);
|
|
583
590
|
}
|
|
584
591
|
return this;
|
|
585
592
|
},
|
|
@@ -607,53 +614,40 @@
|
|
|
607
614
|
return cache.preload();
|
|
608
615
|
}
|
|
609
616
|
|
|
610
|
-
function
|
|
611
|
-
/**
|
|
612
|
-
* @type {Object}
|
|
613
|
-
*/
|
|
617
|
+
function create(options) {
|
|
614
618
|
var config = {};
|
|
615
|
-
var
|
|
616
|
-
var ext = function ext(path, defaults) {
|
|
617
|
-
var ext = path.split('.').pop();
|
|
618
|
-
if (ext !== defaults) {
|
|
619
|
-
path = [path, defaults].join('.');
|
|
620
|
-
}
|
|
621
|
-
return path;
|
|
622
|
-
};
|
|
623
|
-
var view = {
|
|
619
|
+
var ejs = {
|
|
624
620
|
safeValue: safeValue,
|
|
625
621
|
element: element,
|
|
626
622
|
output: function output(path, scope) {
|
|
627
|
-
return
|
|
623
|
+
return ejs.template(path).then(function (template) {
|
|
628
624
|
return template.call(scope, scope, scope.getBuffer(), safeValue);
|
|
629
625
|
});
|
|
630
626
|
},
|
|
631
627
|
render: function render(name, data) {
|
|
632
628
|
var filepath = ext(name, config.extension);
|
|
633
|
-
var scope = new
|
|
634
|
-
return
|
|
629
|
+
var scope = new ejs.scope(data);
|
|
630
|
+
return ejs.output(filepath, scope).then(function (content) {
|
|
635
631
|
if (scope.getExtend()) {
|
|
636
632
|
scope.setExtend(false);
|
|
637
633
|
var layout = scope.getLayout();
|
|
638
634
|
var _data = scope.clone();
|
|
639
|
-
return
|
|
635
|
+
return ejs.render(layout, _data);
|
|
640
636
|
}
|
|
641
637
|
return content;
|
|
642
638
|
});
|
|
643
639
|
},
|
|
644
640
|
require: function require(name) {
|
|
645
641
|
var filepath = ext(name, config.extension);
|
|
646
|
-
var scope = new
|
|
647
|
-
return
|
|
642
|
+
var scope = new ejs.scope({});
|
|
643
|
+
return ejs.output(filepath, scope).then(function () {
|
|
648
644
|
return scope.getMacro();
|
|
649
645
|
});
|
|
650
646
|
},
|
|
651
647
|
helpers: function helpers(methods) {
|
|
652
|
-
methods
|
|
653
|
-
extend(_helpers, methods);
|
|
654
|
-
view.scope.helpers(methods);
|
|
648
|
+
ejs.scope.helpers(methods);
|
|
655
649
|
},
|
|
656
|
-
configure: function configure
|
|
650
|
+
configure: function configure(options) {
|
|
657
651
|
config["export"] = typeProp(isString, defaults["export"], options["export"]);
|
|
658
652
|
config.path = typeProp(isString, defaults.path, options.path);
|
|
659
653
|
config.resolver = typeProp(isFunction, defaults.resolver, options.resolver);
|
|
@@ -661,12 +655,12 @@
|
|
|
661
655
|
config.withObject = typeProp(isBoolean, defaults.withObject, options.withObject);
|
|
662
656
|
config.token = extend({}, defaults.token, options.token);
|
|
663
657
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
return
|
|
658
|
+
ejs.scope = configureScope(ejs, config);
|
|
659
|
+
ejs.compile = configureCompiler(ejs, config);
|
|
660
|
+
ejs.wrapper = configureWrapper(ejs);
|
|
661
|
+
ejs.cache = configureCache(ejs);
|
|
662
|
+
ejs.template = configureTemplate(ejs, config);
|
|
663
|
+
return ejs;
|
|
670
664
|
},
|
|
671
665
|
__express: function __express(name, options, callback) {
|
|
672
666
|
if (isFunction(options)) {
|
|
@@ -681,33 +675,28 @@
|
|
|
681
675
|
var filename = path.relative(viewPath, name);
|
|
682
676
|
viewOptions.path = viewPath;
|
|
683
677
|
viewOptions.cache = viewCache;
|
|
684
|
-
|
|
685
|
-
return
|
|
678
|
+
ejs.configure(viewOptions);
|
|
679
|
+
return ejs.render(filename, options).then(function (content) {
|
|
686
680
|
callback(null, content);
|
|
687
681
|
})["catch"](function (error) {
|
|
688
682
|
callback(error);
|
|
689
683
|
});
|
|
690
684
|
}
|
|
691
685
|
};
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
*/
|
|
695
|
-
view.configure(options || {});
|
|
696
|
-
/**
|
|
697
|
-
*
|
|
698
|
-
*/
|
|
699
|
-
view.helpers({
|
|
686
|
+
ejs.configure(options || {});
|
|
687
|
+
ejs.helpers({
|
|
700
688
|
require: function require(name) {
|
|
701
|
-
return
|
|
689
|
+
return ejs.require(name, this);
|
|
702
690
|
},
|
|
703
691
|
render: function render(name, data) {
|
|
704
|
-
return
|
|
692
|
+
return ejs.render(name, data);
|
|
705
693
|
}
|
|
706
694
|
});
|
|
707
|
-
return
|
|
695
|
+
return ejs;
|
|
708
696
|
}
|
|
709
|
-
var
|
|
697
|
+
var instance = create();
|
|
698
|
+
instance.create = create;
|
|
710
699
|
|
|
711
|
-
return
|
|
700
|
+
return instance;
|
|
712
701
|
|
|
713
702
|
}));
|
package/dist/ejs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).ejs=t()}(this,(function(){"use strict";var n={},t={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!0,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var n=[].slice.call(arguments),t=n.shift();return n.filter(t).pop()},r=function(n){return"function"==typeof n},o=function(n){return"string"==typeof n},i=function(n){return"boolean"==typeof n},c=new Function("try {return this===global;}catch(e){return false;}"),u={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},a={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(n){return new RegExp(["[",Object.keys(n).join(""),"]"].join(""),"g")},s=f(a),h=f(u),l=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+n).replace(s,(function(n){return a[n]}))},p=function(n,t,e){return null==(e=n)?"":t?l(e):e},v=function(n,t){var e=n,r=t.split("."),o=r.pop();return r.forEach((function(n){e=e[n]=e[n]||{}})),[e,o]},d=function(){for(var n=arguments.length,t=new Array(n),e=0;e<n;e++)t[e]=arguments[e];var r=t.shift();return t.filter((function(n){return n})).reduce((function(n,t){return Object.assign(n,t)}),r)},m=function(){},g=function(n,t){var e;for(e in n)y(n,e)&&t(n[e],e,n)},b=function(n,t){return function(n,t,e){var r=n instanceof Array,o=r?[]:{};return g(n,(function(n,e,i){var c=t(n,e,i);void 0!==c&&(r?o.push(c):o[e]=c)})),o}(n,(function(n,e){if(-1===t.indexOf(e))return n}))},w=function(n,t,e){return Promise.resolve(n).then(t.bind(e))},y=function(n,t){return n&&n.hasOwnProperty(t)},x=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],E=" ",j='"',F="/",O="<",B=">";function k(n,t,e){var r=[],o=-1===x.indexOf(n),i=function(n,t,e){var r=[];return g(n,(function(n,e,o){var i=t(n,e,o);void 0!==i&&r.push(i)})),r}(t,(function(n,t){if(null!=n)return[l(t),[j,l(n),j].join("")].join("=")})).join(E);return r.push([O,n,E,i,B].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([O,F,n,B].join("")),r.join("")}var R=[{symbol:"-",format:function(n){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(n,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(n){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(n,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(n){return"')\n/**".concat(n,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(n){return"')\n".concat(n.trim(),"\n").concat(this.BUFFER,"('")}}],$=function(n){var t=n.withObject,e=n.token,r=n.vars,o=[],i=[],c={match:"[ \\t]*",start:[e.start,"_"],end:["_",e.end]};R.forEach((function(n){o.push(e.start.concat(n.symbol).concat(e.regex).concat(e.end)),i.push(n.format.bind(r))}));var a=new RegExp(o.join("|").concat("|$"),"g"),f=new RegExp([c.match,c.start].join(""),"gm"),s=new RegExp([c.end,c.match].join(""),"gm");return function(n,e){var o=r.SCOPE,l=r.SAFE,p=r.BUFFER;n=(n=n.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(f,c.start).replace(s,c.end);var v="".concat(p,"('");!function(n,t,e){var r=0;t.replace(n,(function(){var n=[].slice.call(arguments,0,-1),t=n.pop(),o=n.shift();return e(n,r,t),r=t+o.length,o}))}(a,n,(function(t,e,r){v+=(""+n.slice(e,r)).replace(h,(function(n){return"\\"+u[n]})),t.forEach((function(n,t){n&&(v+=i[t](n))}))})),v="try{".concat(v+="');","}catch(e){console.info(e)}"),t&&(v="with(".concat(o,"){").concat(v,"}")),v="".concat(p,".start();").concat(v,"return ").concat(p,".end();"),v+="\n//# sourceURL=".concat(e);var d=null;try{(d=new Function(o,p,l,v)).source="(function(".concat(o,",").concat(p,",").concat(l,"){\n").concat(v,"\n})")}catch(n){throw n.filename=e,n.source=v,n}return d}},S=function(n){return window.fetch(n).then((function(n){return n.text()}))},U=function(t){return new Promise((function(e,r){n.readFile(t,(function(n,t){n?r(n):e(t.toString())}))}))},A=function(t,e){return n.watch(".",{cwd:t}).on("change",(function(n){e.remove(n)})).on("error",(function(n){console.log("watcher error: "+n)}))},L=function(n,t,e){var o=n.path;n.token;var i=r(n.resolver)?n.resolver:c()?U:S,u=function(n){return i(function(n){return(n=[o,n].join("/")).replace(/\/\//g,"/")}(n))},a=function(n,e){return t.set(e,n),n};return n.watch&&c()&&A(o,t),function(n){if(t.exist(n))return t.resolve(n);var r=u(n).then((function(t){return a(e(t,n),n)}));return a(r,n)}},M=function(n){return Promise.all(n).then((function(n){return n.join("")}))},P=function(){var n=[],t=[];function e(n){t.push(n)}return e.start=function(){t=[]},e.backup=function(){n.push(t.concat()),t=[]},e.restore=function(){var e=t.concat();return t=n.pop(),M(e)},e.error=function(n){throw n},e.end=function(){return M(t)},e};var C,T,q,_,N,D=(T={},q={},_=function(n,t){var e=n.split(".").pop();return e!==t&&(n=[n,t].join(".")),n},N={safeValue:p,element:k,output:function(n,t){return N.template(n).then((function(n){return n.call(t,t,t.getBuffer(),p)}))},render:function(n,t){var e=_(n,T.extension),r=new N.scope(t);return N.output(e,r).then((function(n){if(r.getExtend()){r.setExtend(!1);var t=r.getLayout(),e=r.clone();return N.render(t,e)}return n}))},require:function(n){var t=_(n,T.extension),e=new N.scope({});return N.output(t,e).then((function(){return e.getMacro()}))},helpers:function(n){d(q,n=n||{}),N.scope.helpers(n)},configure:function(n){return T.export=e(o,t.export,n.export),T.path=e(o,t.path,n.path),T.resolver=e(r,t.resolver,n.resolver),T.extension=e(o,t.extension,n.extension),T.withObject=e(i,t.withObject,n.withObject),T.token=d({},t.token,n.token),T.vars=d({},t.vars,n.vars),N.scope=function(n,t){var e=n.vars,i=e.EXTEND,c=e.LAYOUT,u=e.BLOCKS,a=e.BUFFER,f=e.MACRO;function s(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),d(this,n)}return s.helpers=function(n){d(s.prototype,n)},s.property=function(n,t){Object.defineProperty(s.prototype,n,t)},s.method=function(n,t){Object.defineProperty(s.prototype,n,{value:t,writable:!1,configurable:!1,enumerable:!1})},s.property(a,{value:P(),writable:!1,configurable:!1,enumerable:!1}),s.property(u,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(f,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(c,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.property(i,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.method("initBlocks",(function(){this[u]={}})),s.method("initMacro",(function(){this[f]={}})),s.method("getMacro",(function(){return this[f]})),s.method("getBuffer",(function(){return this[a]})),s.method("getBlocks",(function(){return this[u]})),s.method("setExtend",(function(n){this[i]=n})),s.method("getExtend",(function(){return this[i]})),s.method("setLayout",(function(n){this[c]=n})),s.method("getLayout",(function(){return this[c]})),s.method("clone",(function(n){var t=[c,i,a];return!0===n&&t.push(u),b(this,t)})),s.method("extend",(function(n){this.setExtend(!0),this.setLayout(n)})),s.method("echo",(function(){var n=this.getBuffer();[].slice.call(arguments).forEach((function(t){n(t)}))})),s.method("fn",(function(n){var t=this.getBuffer(),e=this;return function(){return t.backup(),r(n)&&n.apply(e,arguments),t.restore()}})),s.method("get",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return y(r,o)?r[o]:t})),s.method("set",(function(n,t){var e=v(this,n),r=e.shift(),o=e.pop();return this.getExtend()&&y(r,o)?r[o]:r[o]=t})),s.method("macro",(function(n,t){var e=this.getMacro(),r=this.fn(t),o=this;e[n]=function(){return o.echo(r.apply(void 0,arguments))}})),s.method("call",(function(n){var t=this.getMacro()[n],e=[].slice.call(arguments,1);if(r(t))return t.apply(t,e)})),s.method("block",(function(n,t){var e=this,r=this.getBlocks();if(r[n]=r[n]||[],r[n].push(this.fn(t)),!this.getExtend()){var o=Object.assign([],r[n]),i=function(){return o.shift()};this.echo(i()(function n(){var t=i();return t?function(){e.echo(t(n()))}:m}()))}})),s.method("include",(function(n,t,e){var r=!1===e?{}:this.clone(!0),o=d(r,t||{}),i=this.render(n,o);this.echo(i)})),s.method("use",(function(n,t){var e=this.require(n);this.echo(w(e,(function(n){var e=this.getMacro();g(n,(function(n,r){e[[t,r].join(".")]=n}))}),this))})),s.method("async",(function(n,t){this.echo(w(n,(function(n){return this.fn(t)(n)}),this))})),s.method("el",(function(n,t,e){r(e)&&(e=this.fn(e)()),this.echo(w(e,(function(e){return k(n,t,e)}),this))})),s.method("each",(function(n,t){o(n)&&(n=this.get(n,[])),g(n,t)})),s.helpers(t),s}(T,q),N.compile=$(T),N.wrapper=function(n){var t=n.export;return function(n){var e="(function(o){\n";return n.forEach((function(n){e+="o["+JSON.stringify(n.name)+"]="+String(n.content)+"\n"})),e+='})(window["'+t+'"] = window["'+t+'"] || {});\n'}}(T),N.cache=function(n){var t=n.export,e={};return{preload:function(){return!1===c()&&this.load(window[t]),this},exist:function(n){return y(e,n)},get:function(n){return e[n]},remove:function(n){delete e[n]},resolve:function(n){return Promise.resolve(this.get(n))},set:function(n,t){return e[n]=t,this},load:function(n){return d(e,n),this}}.preload()}(T),N.template=L(T,N.cache,N.compile),N},__express:function(c,u,a){r(u)&&(a=u,u={});var f=d({},(u=u||{}).settings),s=e(o,f.views,t.path),h=e(i,f["view cache"],t.cache),l=d({},f["view options"]),p=n.relative(s,c);return l.path=s,l.cache=h,N.configure(l),N.render(p,u).then((function(n){a(null,n)})).catch((function(n){a(n)}))}},N.configure(C||{}),N.helpers({require:function(n){return N.require(n,this)},render:function(n,t){return N.render(n,t)}}),N);return D}));
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).ejs=n()}(this,(function(){"use strict";var t={},n={export:"ejs.precompiled",cache:!0,path:"views",resolver:null,extension:"ejs",withObject:!0,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},e=function(){var t=[].slice.call(arguments),n=t.shift();return t.filter(n).pop()},r=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},i=function(t){return"boolean"==typeof t},c="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),u=function(){return c},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},f={"&":"&","<":"<",">":">",'"':""","'":"'"},s=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},h=s(f),l=s(a),p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(h,(function(t){return f[t]}))},d=function(t,n,e){return null==(e=t)?"":n?p(e):e},v=function(t,n){var e=t,r=n.split("."),o=r.pop();return r.forEach((function(t){e=e[t]=e[t]||{}})),[e,o]},m=function(t,n){var e=t.split(".").pop();return e!==n&&(t=[t,n].join(".")),t},g=function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];var r=n.shift();return n.filter((function(t){return t})).reduce((function(t,n){return Object.assign(t,n)}),r)},b=function(){},y=function(t,n){var e;for(e in t)j(t,e)&&n(t[e],e,t)},w=function(t,n){return function(t,n,e){var r=t instanceof Array,o=r?[]:{};return y(t,(function(t,e,i){var c=n(t,e,i);void 0!==c&&(r?o.push(c):o[e]=c)})),o}(t,(function(t,e){if(-1===n.indexOf(e))return t}))},x=function(t,n,e){return Promise.resolve(t).then(n.bind(e))},j=function(t,n){return t&&t.hasOwnProperty(n)},E=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",O='"',B="/",R="<",k=">";function $(t,n,e){var r=[],o=-1===E.indexOf(t),i=function(t,n,e){var r=[];return y(t,(function(t,e,o){var i=n(t,e,o);void 0!==i&&r.push(i)})),r}(n,(function(t,n){if(null!=t)return[p(n),[O,p(t),O].join("")].join("=")})).join(F);return r.push([R,t,F,i,k].join("")),e&&r.push(e instanceof Array?e.join(""):e),o&&r.push([R,B,t,k].join("")),r.join("")}var S=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],U=function(t,n){var e=n.withObject,r=n.token,o=n.vars,i=[],c=[],u={match:"[ \\t]*",start:[r.start,"_"],end:["_",r.end]};S.forEach((function(t){i.push(r.start.concat(t.symbol).concat(r.regex).concat(r.end)),c.push(t.format.bind(o))}));var f=new RegExp(i.join("|").concat("|$"),"g"),s=new RegExp([u.match,u.start].join(""),"gm"),h=new RegExp([u.end,u.match].join(""),"gm");return function(t,n){var r=o.SCOPE,i=o.SAFE,p=o.BUFFER;t=(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")).replace(s,u.start).replace(h,u.end);var d="".concat(p,"('");!function(t,n,e){var r=0;n.replace(t,(function(){var t=[].slice.call(arguments,0,-1),n=t.pop(),o=t.shift();return e(t,r,n),r=n+o.length,o}))}(f,t,(function(n,e,r){d+=(""+t.slice(e,r)).replace(l,(function(t){return"\\"+a[t]})),n.forEach((function(t,n){t&&(d+=c[n](t))}))})),d="try{".concat(d+="');","}catch(e){console.info(e)}"),e&&(d="with(".concat(r,"){").concat(d,"}")),d="".concat(p,".start();").concat(d,"return ").concat(p,".end();"),d+="\n//# sourceURL=".concat(n);var v=null;try{(v=new Function(r,p,i,d)).source="(function(".concat(r,",").concat(p,",").concat(i,"){\n").concat(d,"\n})")}catch(t){throw t.filename=n,t.source=d,t}return v}},A=function(t){return fetch(t).then((function(t){return t.text()}))},T=function(n){return new Promise((function(e,r){t.readFile(n,(function(t,n){t?r(t):e(n.toString())}))}))},L=function(n,e){return t.watch(".",{cwd:n}).on("change",(function(t){e.remove(t)})).on("error",(function(t){console.log("watcher error: "+t)}))},M=function(t,n){var e=n.path,o=t.cache,i=t.compile,c=r(n.resolver)?n.resolver:u()?T:A,a=function(t){return c(function(t){return(t=[e,t].join("/")).replace(/\/\//g,"/")}(t))},f=function(t,n){return o.set(n,t),t};return n.watch&&u()&&L(e,o),function(t){if(o.exist(t))return o.resolve(t);var n=a(t).then((function(n){return f(i(n,t),t)}));return f(n,t)}},P=function(t){return Promise.all(t).then((function(t){return t.join("")}))},C=function(){var t=[],n=[];function e(t){n.push(t)}return e.start=function(){n=[]},e.backup=function(){t.push(n.concat()),n=[]},e.restore=function(){var e=n.concat();return n=t.pop(),P(e)},e.error=function(t){throw t},e.end=function(){return P(n)},e},q="undefined"!=typeof globalThis?globalThis:window||self;function _(c){var a={},f={safeValue:d,element:$,output:function(t,n){return f.template(t).then((function(t){return t.call(n,n,n.getBuffer(),d)}))},render:function(t,n){var e=m(t,a.extension),r=new f.scope(n);return f.output(e,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var n=r.getLayout(),e=r.clone();return f.render(n,e)}return t}))},require:function(t){var n=m(t,a.extension),e=new f.scope({});return f.output(n,e).then((function(){return e.getMacro()}))},helpers:function(t){f.scope.helpers(t)},configure:function(t){return a.export=e(o,n.export,t.export),a.path=e(o,n.path,t.path),a.resolver=e(r,n.resolver,t.resolver),a.extension=e(o,n.extension,t.extension),a.withObject=e(i,n.withObject,t.withObject),a.token=g({},n.token,t.token),a.vars=g({},n.vars,t.vars),f.scope=function(t,n){var e=n.vars,i=e.EXTEND,c=e.LAYOUT,u=e.BLOCKS,a=e.BUFFER,f=e.MACRO;function s(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),g(this,t)}return s.helpers=function(t){g(s.prototype,t)},s.property=function(t,n){Object.defineProperty(s.prototype,t,n)},s.method=function(t,n){Object.defineProperty(s.prototype,t,{value:n,writable:!1,configurable:!1,enumerable:!1})},s.property(a,{value:C(),writable:!1,configurable:!1,enumerable:!1}),s.property(u,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(f,{value:{},writable:!0,configurable:!1,enumerable:!1}),s.property(c,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.property(i,{value:!1,writable:!0,configurable:!1,enumerable:!1}),s.method("initBlocks",(function(){this[u]={}})),s.method("initMacro",(function(){this[f]={}})),s.method("getMacro",(function(){return this[f]})),s.method("getBuffer",(function(){return this[a]})),s.method("getBlocks",(function(){return this[u]})),s.method("setExtend",(function(t){this[i]=t})),s.method("getExtend",(function(){return this[i]})),s.method("setLayout",(function(t){this[c]=t})),s.method("getLayout",(function(){return this[c]})),s.method("clone",(function(t){var n=[c,i,a];return!0===t&&n.push(u),w(this,n)})),s.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),s.method("echo",(function(){var t=this.getBuffer();[].slice.call(arguments).forEach((function(n){t(n)}))})),s.method("fn",(function(t){var n=this.getBuffer(),e=this;return function(){return n.backup(),r(t)&&t.apply(e,arguments),n.restore()}})),s.method("get",(function(t,n){var e=v(this,t),r=e.shift(),o=e.pop();return j(r,o)?r[o]:n})),s.method("set",(function(t,n){var e=v(this,t),r=e.shift(),o=e.pop();return this.getExtend()&&j(r,o)?r[o]:r[o]=n})),s.method("macro",(function(t,n){var e=this.getMacro(),r=this.fn(n),o=this;e[t]=function(){return o.echo(r.apply(void 0,arguments))}})),s.method("call",(function(t){var n=this.getMacro()[t],e=[].slice.call(arguments,1);if(r(n))return n.apply(n,e)})),s.method("block",(function(t,n){var e=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(n)),!this.getExtend()){var o=Object.assign([],r[t]),i=function(){return o.shift()};this.echo(i()(function t(){var n=i();return n?function(){e.echo(n(t()))}:b}()))}})),s.method("include",(function(t,n,e){var r=!1===e?{}:this.clone(!0),o=g(r,n||{}),i=this.render(t,o);this.echo(i)})),s.method("use",(function(t,n){var e=this.require(t);this.echo(x(e,(function(t){var e=this.getMacro();y(t,(function(t,r){e[[n,r].join(".")]=t}))}),this))})),s.method("async",(function(t,n){this.echo(x(t,(function(t){return this.fn(n)(t)}),this))})),s.method("el",(function(t,n,e){r(e)&&(e=this.fn(e)()),this.echo(x(e,(function(e){return $(t,n,e)}),this))})),s.method("each",(function(t,n){o(t)&&(t=this.get(t,[])),y(t,n)})),s}(0,a),f.compile=U(0,a),f.wrapper=function(t){var n=t.export,e=!0!==t.withObject;return function(t){var r="";return r+="(function(global,factory){",r+='typeof exports === "object" && typeof module !== "undefined" ?',r+="module.exports = factory():",r+='typeof define === "function" && define.amd ? define(factory):',r+='(global = typeof globalThis !== "undefined" ? globalThis:',r+='global || self,global["'+n+'"] = factory())',r+="})(this,(function(){",e&&(r+="'use strict';\n"),r+="var list = {};\n",t.forEach((function(t){r+="list["+JSON.stringify(t.name)+"]="+String(t.content)+";\n"})),r+="return list;}));\n"}}(f),f.cache=function(t){var n=t.export,e={};return{preload:function(){return!1===u()&&this.load(q[n]),this},exist:function(t){return j(e,t)},get:function(t){return e[t]},remove:function(t){delete e[t]},resolve:function(t){return Promise.resolve(this.get(t))},set:function(t,n){return e[t]=n,this},load:function(t){return g(e,t),this}}.preload()}(f),f.template=M(f,a),f},__express:function(c,u,a){r(u)&&(a=u,u={});var s=g({},(u=u||{}).settings),h=e(o,s.views,n.path),l=e(i,s["view cache"],n.cache),p=g({},s["view options"]),d=t.relative(h,c);return p.path=h,p.cache=l,f.configure(p),f.render(d,u).then((function(t){a(null,t)})).catch((function(t){a(t)}))}};return f.configure(c||{}),f.helpers({require:function(t){return f.require(t,this)},render:function(t,n){return f.render(t,n)}}),f}var N=_();return N.create=_,N}));
|
package/dist/ejs.mjs
CHANGED
|
@@ -41,9 +41,9 @@ const isFunction = (v) => typeof v === 'function';
|
|
|
41
41
|
const isString = (v) => typeof v === 'string';
|
|
42
42
|
const isBoolean = (v) => typeof v === 'boolean';
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
);
|
|
44
|
+
const isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
45
|
+
|
|
46
|
+
const isNode = () => isNodeEnv;
|
|
47
47
|
|
|
48
48
|
const symbolEntities = {
|
|
49
49
|
"'": "'",
|
|
@@ -98,6 +98,14 @@ const getPath = (context, name) => {
|
|
|
98
98
|
return [data, prop]
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
const ext = (path, defaults) => {
|
|
102
|
+
const ext = path.split('.').pop();
|
|
103
|
+
if (ext !== defaults) {
|
|
104
|
+
path = [path, defaults].join('.');
|
|
105
|
+
}
|
|
106
|
+
return path
|
|
107
|
+
};
|
|
108
|
+
|
|
101
109
|
const extend = (...args) => {
|
|
102
110
|
const target = args.shift();
|
|
103
111
|
return args
|
|
@@ -247,13 +255,8 @@ const match = (regex, text, callback) => {
|
|
|
247
255
|
return match
|
|
248
256
|
});
|
|
249
257
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
* @param {object} config
|
|
253
|
-
* @return {function(*, *): Function}
|
|
254
|
-
* @constructor
|
|
255
|
-
*/
|
|
256
|
-
const Compiler = (config) => {
|
|
258
|
+
|
|
259
|
+
const configureCompiler = (ejs, config) => {
|
|
257
260
|
const withObject = config.withObject;
|
|
258
261
|
const token = config.token;
|
|
259
262
|
const vars = config.vars;
|
|
@@ -276,11 +279,7 @@ const Compiler = (config) => {
|
|
|
276
279
|
const regex = new RegExp(matches.join('|').concat('|$'), 'g');
|
|
277
280
|
const slurpStart = new RegExp([slurp.match, slurp.start].join(''), 'gm');
|
|
278
281
|
const slurpEnd = new RegExp([slurp.end, slurp.match].join(''), 'gm');
|
|
279
|
-
|
|
280
|
-
* @type function
|
|
281
|
-
* @name Compile
|
|
282
|
-
*/
|
|
283
|
-
return function (content, path) {
|
|
282
|
+
return function compiler(content, path) {
|
|
284
283
|
const { SCOPE, SAFE, BUFFER } = vars;
|
|
285
284
|
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
286
285
|
content = content
|
|
@@ -295,7 +294,7 @@ const Compiler = (config) => {
|
|
|
295
294
|
});
|
|
296
295
|
source += `');`;
|
|
297
296
|
source = `try{${source}}catch(e){console.info(e)}`;
|
|
298
|
-
if(withObject) {
|
|
297
|
+
if (withObject) {
|
|
299
298
|
source = `with(${SCOPE}){${source}}`;
|
|
300
299
|
}
|
|
301
300
|
source = `${BUFFER}.start();${source}return ${BUFFER}.end();`;
|
|
@@ -313,27 +312,38 @@ const Compiler = (config) => {
|
|
|
313
312
|
}
|
|
314
313
|
};
|
|
315
314
|
|
|
316
|
-
const
|
|
315
|
+
const configureWrapper = (config) => {
|
|
317
316
|
const name = config.export;
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
const useStrict = config.withObject !== true;
|
|
318
|
+
return function Wrapper(list) {
|
|
319
|
+
let out = '';
|
|
320
|
+
out += '(function(global,factory){';
|
|
321
|
+
out += 'typeof exports === "object" && typeof module !== "undefined" ?';
|
|
322
|
+
out += 'module.exports = factory():';
|
|
323
|
+
out += 'typeof define === "function" && define.amd ? define(factory):';
|
|
324
|
+
out += '(global = typeof globalThis !== "undefined" ? globalThis:';
|
|
325
|
+
out += 'global || self,global["' + name + '"] = factory())';
|
|
326
|
+
out += '})(this,(function(){';
|
|
327
|
+
if (useStrict) out += "'use strict';\n";
|
|
328
|
+
out += 'var list = {};\n';
|
|
320
329
|
list.forEach((item) => {
|
|
321
330
|
out +=
|
|
322
|
-
'
|
|
331
|
+
'list[' +
|
|
323
332
|
JSON.stringify(item.name) +
|
|
324
333
|
']=' +
|
|
325
334
|
String(item.content) +
|
|
326
|
-
'
|
|
335
|
+
';\n';
|
|
327
336
|
});
|
|
328
|
-
out += '
|
|
337
|
+
out += 'return list;}));\n';
|
|
329
338
|
return out
|
|
330
339
|
}
|
|
331
340
|
};
|
|
332
341
|
|
|
333
|
-
const
|
|
334
|
-
|
|
342
|
+
const httpRequest = (template) => {
|
|
343
|
+
return fetch(template).then((response) => response.text())
|
|
344
|
+
};
|
|
335
345
|
|
|
336
|
-
const
|
|
346
|
+
const fileSystem = (template) =>
|
|
337
347
|
new Promise((resolve, reject) => {
|
|
338
348
|
fs.readFile(template, (error, data) => {
|
|
339
349
|
if (error) {
|
|
@@ -344,7 +354,7 @@ const FileSystem = (template) =>
|
|
|
344
354
|
});
|
|
345
355
|
});
|
|
346
356
|
|
|
347
|
-
const
|
|
357
|
+
const enableWatcher = (path, cache) =>
|
|
348
358
|
chokidar
|
|
349
359
|
.watch('.', {
|
|
350
360
|
cwd: path,
|
|
@@ -356,15 +366,14 @@ const Watcher = (path, cache) =>
|
|
|
356
366
|
console.log('watcher error: ' + error);
|
|
357
367
|
});
|
|
358
368
|
|
|
359
|
-
const
|
|
369
|
+
const configureTemplate = (ejs, config) => {
|
|
360
370
|
const path = config.path;
|
|
361
|
-
|
|
371
|
+
const { cache, compile } = ejs;
|
|
362
372
|
const resolver = isFunction(config.resolver)
|
|
363
373
|
? config.resolver
|
|
364
374
|
: isNode()
|
|
365
|
-
?
|
|
366
|
-
:
|
|
367
|
-
|
|
375
|
+
? fileSystem
|
|
376
|
+
: httpRequest;
|
|
368
377
|
const normalize = (template) => {
|
|
369
378
|
template = [path, template].join('/');
|
|
370
379
|
template = template.replace(/\/\//g, '/');
|
|
@@ -377,7 +386,7 @@ const Template = (config, cache, compile) => {
|
|
|
377
386
|
cache.set(template, content);
|
|
378
387
|
return content
|
|
379
388
|
};
|
|
380
|
-
const
|
|
389
|
+
const template = (template) => {
|
|
381
390
|
if (cache.exist(template)) {
|
|
382
391
|
return cache.resolve(template)
|
|
383
392
|
}
|
|
@@ -387,17 +396,14 @@ const Template = (config, cache, compile) => {
|
|
|
387
396
|
return result(content, template)
|
|
388
397
|
};
|
|
389
398
|
if (config.watch && isNode()) {
|
|
390
|
-
|
|
399
|
+
enableWatcher(path, cache);
|
|
391
400
|
}
|
|
392
|
-
return
|
|
401
|
+
return template
|
|
393
402
|
};
|
|
394
403
|
|
|
395
404
|
const resolve = (list) => Promise.all(list).then((list) => list.join(''));
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @return {function}
|
|
399
|
-
*/
|
|
400
|
-
const Buffer = () => {
|
|
405
|
+
|
|
406
|
+
const createBuffer = () => {
|
|
401
407
|
let store = [],
|
|
402
408
|
array = [];
|
|
403
409
|
function buffer(value) {
|
|
@@ -415,7 +421,7 @@ const Buffer = () => {
|
|
|
415
421
|
array = store.pop();
|
|
416
422
|
return resolve(result)
|
|
417
423
|
};
|
|
418
|
-
buffer.error = function(e){
|
|
424
|
+
buffer.error = function (e) {
|
|
419
425
|
throw e
|
|
420
426
|
};
|
|
421
427
|
buffer.end = function () {
|
|
@@ -424,7 +430,7 @@ const Buffer = () => {
|
|
|
424
430
|
return buffer
|
|
425
431
|
};
|
|
426
432
|
|
|
427
|
-
const
|
|
433
|
+
const configureScope = (ejs, config) => {
|
|
428
434
|
const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
|
|
429
435
|
function Scope(data = {}) {
|
|
430
436
|
this.initBlocks();
|
|
@@ -442,88 +448,88 @@ const configure = (config, methods) => {
|
|
|
442
448
|
value: method,
|
|
443
449
|
writable: false,
|
|
444
450
|
configurable: false,
|
|
445
|
-
enumerable: false
|
|
451
|
+
enumerable: false,
|
|
446
452
|
});
|
|
447
453
|
};
|
|
448
454
|
Scope.property(BUFFER, {
|
|
449
|
-
value:
|
|
455
|
+
value: createBuffer(),
|
|
450
456
|
writable: false,
|
|
451
457
|
configurable: false,
|
|
452
|
-
enumerable: false
|
|
458
|
+
enumerable: false,
|
|
453
459
|
});
|
|
454
460
|
Scope.property(BLOCKS, {
|
|
455
461
|
value: {},
|
|
456
462
|
writable: true,
|
|
457
463
|
configurable: false,
|
|
458
|
-
enumerable: false
|
|
464
|
+
enumerable: false,
|
|
459
465
|
});
|
|
460
466
|
Scope.property(MACRO, {
|
|
461
467
|
value: {},
|
|
462
468
|
writable: true,
|
|
463
469
|
configurable: false,
|
|
464
|
-
enumerable: false
|
|
470
|
+
enumerable: false,
|
|
465
471
|
});
|
|
466
472
|
Scope.property(LAYOUT, {
|
|
467
473
|
value: false,
|
|
468
474
|
writable: true,
|
|
469
475
|
configurable: false,
|
|
470
|
-
enumerable: false
|
|
476
|
+
enumerable: false,
|
|
471
477
|
});
|
|
472
478
|
Scope.property(EXTEND, {
|
|
473
479
|
value: false,
|
|
474
480
|
writable: true,
|
|
475
481
|
configurable: false,
|
|
476
|
-
enumerable: false
|
|
482
|
+
enumerable: false,
|
|
477
483
|
});
|
|
478
|
-
Scope.method('initBlocks', function() {
|
|
484
|
+
Scope.method('initBlocks', function () {
|
|
479
485
|
this[BLOCKS] = {};
|
|
480
486
|
});
|
|
481
|
-
Scope.method('initMacro', function() {
|
|
487
|
+
Scope.method('initMacro', function () {
|
|
482
488
|
this[MACRO] = {};
|
|
483
489
|
});
|
|
484
|
-
Scope.method('getMacro', function() {
|
|
490
|
+
Scope.method('getMacro', function () {
|
|
485
491
|
return this[MACRO]
|
|
486
492
|
});
|
|
487
|
-
Scope.method('getBuffer', function() {
|
|
493
|
+
Scope.method('getBuffer', function () {
|
|
488
494
|
return this[BUFFER]
|
|
489
495
|
});
|
|
490
|
-
Scope.method('getBlocks', function() {
|
|
496
|
+
Scope.method('getBlocks', function () {
|
|
491
497
|
return this[BLOCKS]
|
|
492
498
|
});
|
|
493
|
-
Scope.method('setExtend', function(value) {
|
|
499
|
+
Scope.method('setExtend', function (value) {
|
|
494
500
|
this[EXTEND] = value;
|
|
495
501
|
});
|
|
496
|
-
Scope.method('getExtend', function() {
|
|
502
|
+
Scope.method('getExtend', function () {
|
|
497
503
|
return this[EXTEND]
|
|
498
504
|
});
|
|
499
|
-
Scope.method('setLayout', function(layout) {
|
|
505
|
+
Scope.method('setLayout', function (layout) {
|
|
500
506
|
this[LAYOUT] = layout;
|
|
501
507
|
});
|
|
502
|
-
Scope.method('getLayout', function() {
|
|
508
|
+
Scope.method('getLayout', function () {
|
|
503
509
|
return this[LAYOUT]
|
|
504
510
|
});
|
|
505
|
-
Scope.method('clone', function(exclude_blocks) {
|
|
511
|
+
Scope.method('clone', function (exclude_blocks) {
|
|
506
512
|
const filter = [LAYOUT, EXTEND, BUFFER];
|
|
507
513
|
if (exclude_blocks === true) {
|
|
508
514
|
filter.push(BLOCKS);
|
|
509
515
|
}
|
|
510
516
|
return omit(this, filter)
|
|
511
517
|
});
|
|
512
|
-
Scope.method('extend', function(layout) {
|
|
518
|
+
Scope.method('extend', function (layout) {
|
|
513
519
|
this.setExtend(true);
|
|
514
520
|
this.setLayout(layout);
|
|
515
521
|
});
|
|
516
|
-
Scope.method('echo', function() {
|
|
522
|
+
Scope.method('echo', function () {
|
|
517
523
|
const buffer = this.getBuffer();
|
|
518
524
|
const params = [].slice.call(arguments);
|
|
519
|
-
params.forEach(function(item) {
|
|
525
|
+
params.forEach(function (item) {
|
|
520
526
|
buffer(item);
|
|
521
527
|
});
|
|
522
528
|
});
|
|
523
|
-
Scope.method('fn', function(callback) {
|
|
529
|
+
Scope.method('fn', function (callback) {
|
|
524
530
|
const buffer = this.getBuffer();
|
|
525
531
|
const context = this;
|
|
526
|
-
return function() {
|
|
532
|
+
return function () {
|
|
527
533
|
buffer.backup();
|
|
528
534
|
if (isFunction(callback)) {
|
|
529
535
|
callback.apply(context, arguments);
|
|
@@ -531,30 +537,30 @@ const configure = (config, methods) => {
|
|
|
531
537
|
return buffer.restore()
|
|
532
538
|
}
|
|
533
539
|
});
|
|
534
|
-
Scope.method('get', function(name,defaults) {
|
|
540
|
+
Scope.method('get', function (name, defaults) {
|
|
535
541
|
const path = getPath(this, name);
|
|
536
542
|
const result = path.shift();
|
|
537
543
|
const prop = path.pop();
|
|
538
544
|
return hasProp(result, prop) ? result[prop] : defaults
|
|
539
545
|
});
|
|
540
|
-
Scope.method('set', function(name,value) {
|
|
546
|
+
Scope.method('set', function (name, value) {
|
|
541
547
|
const path = getPath(this, name);
|
|
542
548
|
const result = path.shift();
|
|
543
549
|
const prop = path.pop();
|
|
544
550
|
if (this.getExtend() && hasProp(result, prop)) {
|
|
545
551
|
return result[prop]
|
|
546
552
|
}
|
|
547
|
-
return result[prop] = value
|
|
553
|
+
return (result[prop] = value)
|
|
548
554
|
});
|
|
549
|
-
Scope.method('macro', function(name, callback) {
|
|
555
|
+
Scope.method('macro', function (name, callback) {
|
|
550
556
|
const list = this.getMacro();
|
|
551
557
|
const macro = this.fn(callback);
|
|
552
558
|
const context = this;
|
|
553
|
-
list[name] = function() {
|
|
559
|
+
list[name] = function () {
|
|
554
560
|
return context.echo(macro.apply(undefined, arguments))
|
|
555
561
|
};
|
|
556
562
|
});
|
|
557
|
-
Scope.method('call', function(name) {
|
|
563
|
+
Scope.method('call', function (name) {
|
|
558
564
|
const list = this.getMacro();
|
|
559
565
|
const macro = list[name];
|
|
560
566
|
const params = [].slice.call(arguments, 1);
|
|
@@ -562,13 +568,13 @@ const configure = (config, methods) => {
|
|
|
562
568
|
return macro.apply(macro, params)
|
|
563
569
|
}
|
|
564
570
|
});
|
|
565
|
-
Scope.method('block',function(name,callback){
|
|
571
|
+
Scope.method('block', function (name, callback) {
|
|
566
572
|
const blocks = this.getBlocks();
|
|
567
573
|
blocks[name] = blocks[name] || [];
|
|
568
574
|
blocks[name].push(this.fn(callback));
|
|
569
575
|
if (this.getExtend()) return
|
|
570
576
|
const list = Object.assign([], blocks[name]);
|
|
571
|
-
const current = function() {
|
|
577
|
+
const current = function () {
|
|
572
578
|
return list.shift()
|
|
573
579
|
};
|
|
574
580
|
const next = () => {
|
|
@@ -583,55 +589,70 @@ const configure = (config, methods) => {
|
|
|
583
589
|
};
|
|
584
590
|
this.echo(current()(next()));
|
|
585
591
|
});
|
|
586
|
-
Scope.method('include',function(path, data, cx){
|
|
592
|
+
Scope.method('include', function (path, data, cx) {
|
|
587
593
|
const context = cx === false ? {} : this.clone(true);
|
|
588
594
|
const params = extend(context, data || {});
|
|
589
595
|
const promise = this.render(path, params);
|
|
590
596
|
this.echo(promise);
|
|
591
597
|
});
|
|
592
|
-
Scope.method('use',function(path, namespace){
|
|
598
|
+
Scope.method('use', function (path, namespace) {
|
|
593
599
|
const promise = this.require(path);
|
|
594
|
-
this.echo(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
this.echo(
|
|
601
|
+
resolve$1(
|
|
602
|
+
promise,
|
|
603
|
+
function (exports) {
|
|
604
|
+
const list = this.getMacro();
|
|
605
|
+
each(exports, function (macro, name) {
|
|
606
|
+
list[[namespace, name].join('.')] = macro;
|
|
607
|
+
});
|
|
608
|
+
},
|
|
609
|
+
this
|
|
610
|
+
)
|
|
611
|
+
);
|
|
600
612
|
});
|
|
601
|
-
Scope.method('async',function(promise,callback){
|
|
613
|
+
Scope.method('async', function (promise, callback) {
|
|
602
614
|
this.echo(
|
|
603
|
-
resolve$1(
|
|
604
|
-
|
|
605
|
-
|
|
615
|
+
resolve$1(
|
|
616
|
+
promise,
|
|
617
|
+
function (data) {
|
|
618
|
+
return this.fn(callback)(data)
|
|
619
|
+
},
|
|
620
|
+
this
|
|
621
|
+
)
|
|
606
622
|
);
|
|
607
623
|
});
|
|
608
|
-
Scope.method('el',function(tag, attr, content){
|
|
624
|
+
Scope.method('el', function (tag, attr, content) {
|
|
609
625
|
if (isFunction(content)) {
|
|
610
626
|
content = this.fn(content)();
|
|
611
627
|
}
|
|
612
628
|
this.echo(
|
|
613
|
-
resolve$1(
|
|
614
|
-
|
|
615
|
-
|
|
629
|
+
resolve$1(
|
|
630
|
+
content,
|
|
631
|
+
function (content) {
|
|
632
|
+
return element(tag, attr, content)
|
|
633
|
+
},
|
|
634
|
+
this
|
|
635
|
+
)
|
|
616
636
|
);
|
|
617
637
|
});
|
|
618
|
-
Scope.method('each',function(object, callback){
|
|
638
|
+
Scope.method('each', function (object, callback) {
|
|
619
639
|
if (isString(object)) {
|
|
620
640
|
object = this.get(object, []);
|
|
621
641
|
}
|
|
622
642
|
each(object, callback);
|
|
623
643
|
});
|
|
624
|
-
Scope.helpers(methods);
|
|
625
644
|
return Scope
|
|
626
645
|
};
|
|
627
646
|
|
|
628
|
-
|
|
647
|
+
const global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
648
|
+
|
|
649
|
+
function configureCache(config) {
|
|
629
650
|
const namespace = config.export;
|
|
630
651
|
const list = {};
|
|
631
652
|
const cache = {
|
|
632
653
|
preload() {
|
|
633
654
|
if (isNode() === false) {
|
|
634
|
-
this.load(
|
|
655
|
+
this.load(global[namespace]);
|
|
635
656
|
}
|
|
636
657
|
return this
|
|
637
658
|
},
|
|
@@ -659,51 +680,38 @@ function Cache(config) {
|
|
|
659
680
|
return cache.preload()
|
|
660
681
|
}
|
|
661
682
|
|
|
662
|
-
function
|
|
663
|
-
/**
|
|
664
|
-
* @type {Object}
|
|
665
|
-
*/
|
|
683
|
+
function create(options) {
|
|
666
684
|
const config = {};
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (ext !== defaults) {
|
|
671
|
-
path = [path, defaults].join('.');
|
|
672
|
-
}
|
|
673
|
-
return path
|
|
674
|
-
};
|
|
675
|
-
const view = {
|
|
676
|
-
safeValue,
|
|
677
|
-
element,
|
|
685
|
+
const ejs = {
|
|
686
|
+
safeValue: safeValue,
|
|
687
|
+
element: element,
|
|
678
688
|
output(path, scope) {
|
|
679
|
-
return
|
|
689
|
+
return ejs.template(path).then(function (template) {
|
|
680
690
|
return template.call(scope, scope, scope.getBuffer(), safeValue)
|
|
681
691
|
})
|
|
682
692
|
},
|
|
683
693
|
render(name, data) {
|
|
684
694
|
const filepath = ext(name, config.extension);
|
|
685
|
-
const scope = new
|
|
686
|
-
return
|
|
695
|
+
const scope = new ejs.scope(data);
|
|
696
|
+
return ejs.output(filepath, scope).then((content) => {
|
|
687
697
|
if (scope.getExtend()) {
|
|
688
698
|
scope.setExtend(false);
|
|
689
699
|
const layout = scope.getLayout();
|
|
690
700
|
const data = scope.clone();
|
|
691
|
-
return
|
|
701
|
+
return ejs.render(layout, data)
|
|
692
702
|
}
|
|
693
703
|
return content
|
|
694
704
|
})
|
|
695
705
|
},
|
|
696
706
|
require(name) {
|
|
697
707
|
const filepath = ext(name, config.extension);
|
|
698
|
-
const scope = new
|
|
699
|
-
return
|
|
708
|
+
const scope = new ejs.scope({});
|
|
709
|
+
return ejs.output(filepath, scope).then(() => {
|
|
700
710
|
return scope.getMacro()
|
|
701
711
|
})
|
|
702
712
|
},
|
|
703
713
|
helpers(methods) {
|
|
704
|
-
methods
|
|
705
|
-
extend(helpers, methods);
|
|
706
|
-
view.scope.helpers(methods);
|
|
714
|
+
ejs.scope.helpers(methods);
|
|
707
715
|
},
|
|
708
716
|
configure(options) {
|
|
709
717
|
config.export = typeProp(isString, defaults.export, options.export);
|
|
@@ -725,12 +733,12 @@ function init(options) {
|
|
|
725
733
|
);
|
|
726
734
|
config.token = extend({}, defaults.token, options.token);
|
|
727
735
|
config.vars = extend({}, defaults.vars, options.vars);
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
return
|
|
736
|
+
ejs.scope = configureScope(ejs, config);
|
|
737
|
+
ejs.compile = configureCompiler(ejs, config);
|
|
738
|
+
ejs.wrapper = configureWrapper(ejs);
|
|
739
|
+
ejs.cache = configureCache(ejs);
|
|
740
|
+
ejs.template = configureTemplate(ejs, config);
|
|
741
|
+
return ejs
|
|
734
742
|
},
|
|
735
743
|
__express(name, options, callback) {
|
|
736
744
|
if (isFunction(options)) {
|
|
@@ -753,8 +761,8 @@ function init(options) {
|
|
|
753
761
|
const filename = path.relative(viewPath, name);
|
|
754
762
|
viewOptions.path = viewPath;
|
|
755
763
|
viewOptions.cache = viewCache;
|
|
756
|
-
|
|
757
|
-
return
|
|
764
|
+
ejs.configure(viewOptions);
|
|
765
|
+
return ejs
|
|
758
766
|
.render(filename, options)
|
|
759
767
|
.then((content) => {
|
|
760
768
|
callback(null, content);
|
|
@@ -764,24 +772,20 @@ function init(options) {
|
|
|
764
772
|
})
|
|
765
773
|
},
|
|
766
774
|
};
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
*/
|
|
770
|
-
view.configure(options || {});
|
|
771
|
-
/**
|
|
772
|
-
*
|
|
773
|
-
*/
|
|
774
|
-
view.helpers({
|
|
775
|
+
ejs.configure(options || {});
|
|
776
|
+
ejs.helpers({
|
|
775
777
|
require(name) {
|
|
776
|
-
return
|
|
778
|
+
return ejs.require(name, this)
|
|
777
779
|
},
|
|
778
780
|
render(name, data) {
|
|
779
|
-
return
|
|
781
|
+
return ejs.render(name, data)
|
|
780
782
|
},
|
|
781
783
|
});
|
|
782
|
-
return
|
|
784
|
+
return ejs
|
|
783
785
|
}
|
|
784
786
|
|
|
785
|
-
|
|
787
|
+
const instance = create();
|
|
788
|
+
|
|
789
|
+
instance.create = create;
|
|
786
790
|
|
|
787
|
-
export {
|
|
791
|
+
export { instance as default };
|
package/package.json
CHANGED
package/dist/templates.js
DELETED