@kosatyi/ejs 0.0.26 → 0.0.27
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 +544 -410
- package/dist/ejs.js +547 -412
- package/dist/ejs.min.js +1 -1
- package/dist/ejs.mjs +471 -420
- package/package.json +1 -1
package/dist/ejs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ?
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ejs =
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ejs = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var path = {};
|
|
8
8
|
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
var slash = '/';
|
|
165
165
|
var lt = '<';
|
|
166
166
|
var gt = '>';
|
|
167
|
-
function element(tag, attrs, content) {
|
|
167
|
+
var element = function element(tag, attrs, content) {
|
|
168
168
|
var result = [];
|
|
169
169
|
var hasClosedTag = selfClosed.indexOf(tag) === -1;
|
|
170
170
|
var attributes = map(attrs, function (value, key) {
|
|
@@ -180,9 +180,60 @@
|
|
|
180
180
|
result.push([lt, slash, tag, gt].join(''));
|
|
181
181
|
}
|
|
182
182
|
return result.join('');
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
function _classCallCheck(instance, Constructor) {
|
|
186
|
+
if (!(instance instanceof Constructor)) {
|
|
187
|
+
throw new TypeError("Cannot call a class as a function");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function _defineProperties(target, props) {
|
|
191
|
+
for (var i = 0; i < props.length; i++) {
|
|
192
|
+
var descriptor = props[i];
|
|
193
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
194
|
+
descriptor.configurable = true;
|
|
195
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
196
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
200
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
201
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
202
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
203
|
+
writable: false
|
|
204
|
+
});
|
|
205
|
+
return Constructor;
|
|
206
|
+
}
|
|
207
|
+
function _defineProperty(obj, key, value) {
|
|
208
|
+
key = _toPropertyKey(key);
|
|
209
|
+
if (key in obj) {
|
|
210
|
+
Object.defineProperty(obj, key, {
|
|
211
|
+
value: value,
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
obj[key] = value;
|
|
218
|
+
}
|
|
219
|
+
return obj;
|
|
220
|
+
}
|
|
221
|
+
function _toPrimitive(input, hint) {
|
|
222
|
+
if (typeof input !== "object" || input === null) return input;
|
|
223
|
+
var prim = input[Symbol.toPrimitive];
|
|
224
|
+
if (prim !== undefined) {
|
|
225
|
+
var res = prim.call(input, hint || "default");
|
|
226
|
+
if (typeof res !== "object") return res;
|
|
227
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
228
|
+
}
|
|
229
|
+
return (hint === "string" ? String : Number)(input);
|
|
230
|
+
}
|
|
231
|
+
function _toPropertyKey(arg) {
|
|
232
|
+
var key = _toPrimitive(arg, "string");
|
|
233
|
+
return typeof key === "symbol" ? key : String(key);
|
|
183
234
|
}
|
|
184
235
|
|
|
185
|
-
var
|
|
236
|
+
var tagList = [{
|
|
186
237
|
symbol: '-',
|
|
187
238
|
format: function format(value) {
|
|
188
239
|
return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
|
|
@@ -203,7 +254,7 @@
|
|
|
203
254
|
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
204
255
|
}
|
|
205
256
|
}];
|
|
206
|
-
var
|
|
257
|
+
var matchTokens = function matchTokens(regex, text, callback) {
|
|
207
258
|
var index = 0;
|
|
208
259
|
text.replace(regex, function () {
|
|
209
260
|
var params = [].slice.call(arguments, 0, -1);
|
|
@@ -214,78 +265,105 @@
|
|
|
214
265
|
return match;
|
|
215
266
|
});
|
|
216
267
|
};
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
240
|
-
content = content.replace(slurpStart, slurp.start).replace(slurpEnd, slurp.end);
|
|
241
|
-
var source = "".concat(BUFFER, "('");
|
|
242
|
-
match(regex, content, function (params, index, offset) {
|
|
243
|
-
source += symbols(content.slice(index, offset));
|
|
244
|
-
params.forEach(function (value, index) {
|
|
245
|
-
if (value) source += formats[index](value);
|
|
268
|
+
var Compiler = /*#__PURE__*/function () {
|
|
269
|
+
function Compiler(config) {
|
|
270
|
+
_classCallCheck(this, Compiler);
|
|
271
|
+
this.configure(config);
|
|
272
|
+
}
|
|
273
|
+
_createClass(Compiler, [{
|
|
274
|
+
key: "configure",
|
|
275
|
+
value: function configure(config) {
|
|
276
|
+
var _this = this;
|
|
277
|
+
this.withObject = config.withObject;
|
|
278
|
+
this.token = config.token;
|
|
279
|
+
this.vars = config.vars;
|
|
280
|
+
this.matches = [];
|
|
281
|
+
this.formats = [];
|
|
282
|
+
this.slurp = {
|
|
283
|
+
match: '[ \\t]*',
|
|
284
|
+
start: [this.token.start, '_'],
|
|
285
|
+
end: ['_', this.token.end]
|
|
286
|
+
};
|
|
287
|
+
tagList.forEach(function (item) {
|
|
288
|
+
_this.matches.push(_this.token.start.concat(item.symbol).concat(_this.token.regex).concat(_this.token.end));
|
|
289
|
+
_this.formats.push(item.format.bind(_this.vars));
|
|
246
290
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (withObject) {
|
|
251
|
-
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
291
|
+
this.regex = new RegExp(this.matches.join('|').concat('|$'), 'g');
|
|
292
|
+
this.slurpStart = new RegExp([this.slurp.match, this.slurp.start].join(''), 'gm');
|
|
293
|
+
this.slurpEnd = new RegExp([this.slurp.end, this.slurp.match].join(''), 'gm');
|
|
252
294
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
295
|
+
}, {
|
|
296
|
+
key: "compile",
|
|
297
|
+
value: function compile(content, path) {
|
|
298
|
+
var _this2 = this;
|
|
299
|
+
var _this$vars = this.vars,
|
|
300
|
+
SCOPE = _this$vars.SCOPE,
|
|
301
|
+
SAFE = _this$vars.SAFE,
|
|
302
|
+
BUFFER = _this$vars.BUFFER;
|
|
303
|
+
content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
304
|
+
content = content.replace(this.slurpStart, this.slurp.start).replace(this.slurpEnd, this.slurp.end);
|
|
305
|
+
var source = "".concat(BUFFER, "('");
|
|
306
|
+
matchTokens(this.regex, content, function (params, index, offset) {
|
|
307
|
+
source += symbols(content.slice(index, offset));
|
|
308
|
+
params.forEach(function (value, index) {
|
|
309
|
+
if (value) source += _this2.formats[index](value);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
source += "');";
|
|
313
|
+
source = "try{".concat(source, "}catch(e){console.info(e)}");
|
|
314
|
+
if (this.withObject) {
|
|
315
|
+
source = "with(".concat(SCOPE, "){").concat(source, "}");
|
|
316
|
+
}
|
|
317
|
+
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
318
|
+
source += "\n//# sourceURL=".concat(path);
|
|
319
|
+
var result = null;
|
|
320
|
+
try {
|
|
321
|
+
result = new Function(SCOPE, BUFFER, SAFE, source);
|
|
322
|
+
result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
|
|
323
|
+
} catch (e) {
|
|
324
|
+
e.filename = path;
|
|
325
|
+
e.source = source;
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
return result;
|
|
263
329
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
};
|
|
330
|
+
}]);
|
|
331
|
+
return Compiler;
|
|
332
|
+
}();
|
|
267
333
|
|
|
268
|
-
var
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
out += '
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
334
|
+
var Bundler = /*#__PURE__*/function () {
|
|
335
|
+
function Bundler(config) {
|
|
336
|
+
_classCallCheck(this, Bundler);
|
|
337
|
+
this.configure(config);
|
|
338
|
+
}
|
|
339
|
+
_createClass(Bundler, [{
|
|
340
|
+
key: "configure",
|
|
341
|
+
value: function configure(config) {
|
|
342
|
+
this.namespace = config["export"];
|
|
343
|
+
this.useStrict = config.withObject === false;
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: "wrapper",
|
|
347
|
+
value: function wrapper(list) {
|
|
348
|
+
var out = '';
|
|
349
|
+
out += '(function(global,factory){';
|
|
350
|
+
out += 'typeof exports === "object" && typeof module !== "undefined" ?';
|
|
351
|
+
out += 'module.exports = factory():';
|
|
352
|
+
out += 'typeof define === "function" && define.amd ? define(factory):';
|
|
353
|
+
out += '(global = typeof globalThis !== "undefined" ? globalThis:';
|
|
354
|
+
out += 'global || self,global["' + this.namespace + '"] = factory())';
|
|
355
|
+
out += '})(this,(function(){';
|
|
356
|
+
if (this.useStrict) out += "'use strict';\n";
|
|
357
|
+
out += 'var list = {};\n';
|
|
358
|
+
list.forEach(function (item) {
|
|
359
|
+
out += 'list[' + JSON.stringify(item.name) + ']=' + String(item.content) + ';\n';
|
|
360
|
+
});
|
|
361
|
+
out += 'return list;}));\n';
|
|
362
|
+
return out;
|
|
363
|
+
}
|
|
364
|
+
}]);
|
|
365
|
+
return Bundler;
|
|
366
|
+
}();
|
|
289
367
|
|
|
290
368
|
var httpRequest = function httpRequest(template) {
|
|
291
369
|
return fetch(template).then(function (response) {
|
|
@@ -303,46 +381,50 @@
|
|
|
303
381
|
});
|
|
304
382
|
});
|
|
305
383
|
};
|
|
306
|
-
var
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}).on('change', function (name) {
|
|
310
|
-
cache.remove(name);
|
|
311
|
-
}).on('error', function (error) {
|
|
312
|
-
console.log('watcher error: ' + error);
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
var configureTemplate = function configureTemplate(ejs, config) {
|
|
316
|
-
var path = config.path;
|
|
317
|
-
var cache = ejs.cache,
|
|
318
|
-
compile = ejs.compile;
|
|
319
|
-
var resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
320
|
-
var normalize = function normalize(template) {
|
|
321
|
-
template = [path, template].join('/');
|
|
322
|
-
template = template.replace(/\/\//g, '/');
|
|
323
|
-
return template;
|
|
324
|
-
};
|
|
325
|
-
var resolve = function resolve(template) {
|
|
326
|
-
return resolver(normalize(template));
|
|
327
|
-
};
|
|
328
|
-
var result = function result(content, template) {
|
|
329
|
-
cache.set(template, content);
|
|
330
|
-
return content;
|
|
331
|
-
};
|
|
332
|
-
var template = function template(_template) {
|
|
333
|
-
if (cache.exist(_template)) {
|
|
334
|
-
return cache.resolve(_template);
|
|
335
|
-
}
|
|
336
|
-
var content = resolve(_template).then(function (content) {
|
|
337
|
-
return result(compile(content, _template), _template);
|
|
338
|
-
});
|
|
339
|
-
return result(content, _template);
|
|
340
|
-
};
|
|
341
|
-
if (config.watch && isNode()) {
|
|
342
|
-
enableWatcher(path, cache);
|
|
343
|
-
}
|
|
384
|
+
var normalizePath = function normalizePath(path, template) {
|
|
385
|
+
template = [path, template].join('/');
|
|
386
|
+
template = template.replace(/\/\//g, '/');
|
|
344
387
|
return template;
|
|
345
388
|
};
|
|
389
|
+
var Template = /*#__PURE__*/function () {
|
|
390
|
+
function Template(config, cache, compiler) {
|
|
391
|
+
_classCallCheck(this, Template);
|
|
392
|
+
this.cache = cache;
|
|
393
|
+
this.compiler = compiler;
|
|
394
|
+
this.configure(config);
|
|
395
|
+
}
|
|
396
|
+
_createClass(Template, [{
|
|
397
|
+
key: "configure",
|
|
398
|
+
value: function configure(config) {
|
|
399
|
+
this.path = config.path;
|
|
400
|
+
this.resolver = isFunction(config.resolver) ? config.resolver : isNode() ? fileSystem : httpRequest;
|
|
401
|
+
}
|
|
402
|
+
}, {
|
|
403
|
+
key: "resolve",
|
|
404
|
+
value: function resolve(template) {
|
|
405
|
+
return this.resolver(normalizePath(this.path, template));
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "result",
|
|
409
|
+
value: function result(content, template) {
|
|
410
|
+
this.cache.set(template, content);
|
|
411
|
+
return content;
|
|
412
|
+
}
|
|
413
|
+
}, {
|
|
414
|
+
key: "get",
|
|
415
|
+
value: function get(template) {
|
|
416
|
+
var _this = this;
|
|
417
|
+
if (this.cache.exist(template)) {
|
|
418
|
+
return this.cache.resolve(template);
|
|
419
|
+
}
|
|
420
|
+
var content = this.resolve(template).then(function (content) {
|
|
421
|
+
return _this.result(_this.compiler.compile(content, template), template);
|
|
422
|
+
});
|
|
423
|
+
return this.result(content, template);
|
|
424
|
+
}
|
|
425
|
+
}]);
|
|
426
|
+
return Template;
|
|
427
|
+
}();
|
|
346
428
|
|
|
347
429
|
var resolve = function resolve(list) {
|
|
348
430
|
return Promise.all(list).then(function (list) {
|
|
@@ -376,327 +458,380 @@
|
|
|
376
458
|
return buffer;
|
|
377
459
|
};
|
|
378
460
|
|
|
379
|
-
var
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
BLOCKS = _config$vars.BLOCKS,
|
|
384
|
-
BUFFER = _config$vars.BUFFER,
|
|
385
|
-
MACRO = _config$vars.MACRO;
|
|
386
|
-
function Scope() {
|
|
387
|
-
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
388
|
-
this.initBlocks();
|
|
389
|
-
this.initMacro();
|
|
390
|
-
extend(this, data);
|
|
461
|
+
var Context = /*#__PURE__*/function () {
|
|
462
|
+
function Context(config) {
|
|
463
|
+
_classCallCheck(this, Context);
|
|
464
|
+
this.configure(config);
|
|
391
465
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
Scope.property(BLOCKS, {
|
|
413
|
-
value: {},
|
|
414
|
-
writable: true,
|
|
415
|
-
configurable: false,
|
|
416
|
-
enumerable: false
|
|
417
|
-
});
|
|
418
|
-
Scope.property(MACRO, {
|
|
419
|
-
value: {},
|
|
420
|
-
writable: true,
|
|
421
|
-
configurable: false,
|
|
422
|
-
enumerable: false
|
|
423
|
-
});
|
|
424
|
-
Scope.property(LAYOUT, {
|
|
425
|
-
value: false,
|
|
426
|
-
writable: true,
|
|
427
|
-
configurable: false,
|
|
428
|
-
enumerable: false
|
|
429
|
-
});
|
|
430
|
-
Scope.property(EXTEND, {
|
|
431
|
-
value: false,
|
|
432
|
-
writable: true,
|
|
433
|
-
configurable: false,
|
|
434
|
-
enumerable: false
|
|
435
|
-
});
|
|
436
|
-
Scope.method('initBlocks', function () {
|
|
437
|
-
this[BLOCKS] = {};
|
|
438
|
-
});
|
|
439
|
-
Scope.method('initMacro', function () {
|
|
440
|
-
this[MACRO] = {};
|
|
441
|
-
});
|
|
442
|
-
Scope.method('getMacro', function () {
|
|
443
|
-
return this[MACRO];
|
|
444
|
-
});
|
|
445
|
-
Scope.method('getBuffer', function () {
|
|
446
|
-
return this[BUFFER];
|
|
447
|
-
});
|
|
448
|
-
Scope.method('getBlocks', function () {
|
|
449
|
-
return this[BLOCKS];
|
|
450
|
-
});
|
|
451
|
-
Scope.method('setExtend', function (value) {
|
|
452
|
-
this[EXTEND] = value;
|
|
453
|
-
});
|
|
454
|
-
Scope.method('getExtend', function () {
|
|
455
|
-
return this[EXTEND];
|
|
456
|
-
});
|
|
457
|
-
Scope.method('setLayout', function (layout) {
|
|
458
|
-
this[LAYOUT] = layout;
|
|
459
|
-
});
|
|
460
|
-
Scope.method('getLayout', function () {
|
|
461
|
-
return this[LAYOUT];
|
|
462
|
-
});
|
|
463
|
-
Scope.method('clone', function (exclude_blocks) {
|
|
464
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
465
|
-
if (exclude_blocks === true) {
|
|
466
|
-
filter.push(BLOCKS);
|
|
467
|
-
}
|
|
468
|
-
return omit(this, filter);
|
|
469
|
-
});
|
|
470
|
-
Scope.method('extend', function (layout) {
|
|
471
|
-
this.setExtend(true);
|
|
472
|
-
this.setLayout(layout);
|
|
473
|
-
});
|
|
474
|
-
Scope.method('echo', function () {
|
|
475
|
-
var buffer = this.getBuffer();
|
|
476
|
-
var params = [].slice.call(arguments);
|
|
477
|
-
params.forEach(function (item) {
|
|
478
|
-
buffer(item);
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
Scope.method('fn', function (callback) {
|
|
482
|
-
var buffer = this.getBuffer();
|
|
483
|
-
var context = this;
|
|
484
|
-
return function () {
|
|
485
|
-
buffer.backup();
|
|
486
|
-
if (isFunction(callback)) {
|
|
487
|
-
callback.apply(context, arguments);
|
|
466
|
+
_createClass(Context, [{
|
|
467
|
+
key: "configure",
|
|
468
|
+
value: function configure(config) {
|
|
469
|
+
var _config$vars = config.vars,
|
|
470
|
+
EXTEND = _config$vars.EXTEND,
|
|
471
|
+
LAYOUT = _config$vars.LAYOUT,
|
|
472
|
+
BLOCKS = _config$vars.BLOCKS,
|
|
473
|
+
BUFFER = _config$vars.BUFFER,
|
|
474
|
+
MACRO = _config$vars.MACRO;
|
|
475
|
+
this.create = function (data) {
|
|
476
|
+
return new Scope(data);
|
|
477
|
+
};
|
|
478
|
+
this.helpers = function (methods) {
|
|
479
|
+
extend(Scope.prototype, methods);
|
|
480
|
+
};
|
|
481
|
+
function Scope() {
|
|
482
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
483
|
+
this.initBlocks();
|
|
484
|
+
this.initMacro();
|
|
485
|
+
extend(this, data);
|
|
488
486
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
487
|
+
Scope.helpers = function (methods) {
|
|
488
|
+
extend(Scope.prototype, methods);
|
|
489
|
+
};
|
|
490
|
+
Scope.defineProp = Scope.method = function (name, value) {
|
|
491
|
+
var writable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
492
|
+
var configurable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
493
|
+
var enumerable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
494
|
+
Object.defineProperty(Scope.prototype, name, {
|
|
495
|
+
value: value,
|
|
496
|
+
writable: writable,
|
|
497
|
+
configurable: configurable,
|
|
498
|
+
enumerable: enumerable
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
Scope.defineProp(BUFFER, createBuffer());
|
|
502
|
+
Scope.defineProp(BLOCKS, {}, true);
|
|
503
|
+
Scope.defineProp(MACRO, {}, true);
|
|
504
|
+
Scope.defineProp(LAYOUT, false, true);
|
|
505
|
+
Scope.defineProp(EXTEND, false, true);
|
|
506
|
+
Scope.method('initBlocks', function () {
|
|
507
|
+
this[BLOCKS] = {};
|
|
508
|
+
});
|
|
509
|
+
Scope.method('initMacro', function () {
|
|
510
|
+
this[MACRO] = {};
|
|
511
|
+
});
|
|
512
|
+
Scope.method('getMacro', function () {
|
|
513
|
+
return this[MACRO];
|
|
514
|
+
});
|
|
515
|
+
Scope.method('getBuffer', function () {
|
|
516
|
+
return this[BUFFER];
|
|
517
|
+
});
|
|
518
|
+
Scope.method('getBlocks', function () {
|
|
519
|
+
return this[BLOCKS];
|
|
520
|
+
});
|
|
521
|
+
Scope.method('setExtend', function (value) {
|
|
522
|
+
this[EXTEND] = value;
|
|
523
|
+
});
|
|
524
|
+
Scope.method('getExtend', function () {
|
|
525
|
+
return this[EXTEND];
|
|
526
|
+
});
|
|
527
|
+
Scope.method('setLayout', function (layout) {
|
|
528
|
+
this[LAYOUT] = layout;
|
|
529
|
+
});
|
|
530
|
+
Scope.method('getLayout', function () {
|
|
531
|
+
return this[LAYOUT];
|
|
532
|
+
});
|
|
533
|
+
Scope.method('clone', function (exclude_blocks) {
|
|
534
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
535
|
+
if (exclude_blocks === true) {
|
|
536
|
+
filter.push(BLOCKS);
|
|
537
|
+
}
|
|
538
|
+
return omit(this, filter);
|
|
539
|
+
});
|
|
540
|
+
Scope.method('extend', function (layout) {
|
|
541
|
+
this.setExtend(true);
|
|
542
|
+
this.setLayout(layout);
|
|
543
|
+
});
|
|
544
|
+
Scope.method('echo', function () {
|
|
545
|
+
var buffer = this.getBuffer();
|
|
546
|
+
var params = [].slice.call(arguments);
|
|
547
|
+
params.forEach(buffer);
|
|
548
|
+
});
|
|
549
|
+
Scope.method('fn', function (callback) {
|
|
550
|
+
var buffer = this.getBuffer();
|
|
551
|
+
var context = this;
|
|
536
552
|
return function () {
|
|
537
|
-
|
|
553
|
+
buffer.backup();
|
|
554
|
+
if (isFunction(callback)) {
|
|
555
|
+
callback.apply(context, arguments);
|
|
556
|
+
}
|
|
557
|
+
return buffer.restore();
|
|
538
558
|
};
|
|
539
|
-
} else {
|
|
540
|
-
return noop;
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
this.echo(current()(next()));
|
|
544
|
-
});
|
|
545
|
-
Scope.method('include', function (path, data, cx) {
|
|
546
|
-
var context = cx === false ? {} : this.clone(true);
|
|
547
|
-
var params = extend(context, data || {});
|
|
548
|
-
var promise = this.render(path, params);
|
|
549
|
-
this.echo(promise);
|
|
550
|
-
});
|
|
551
|
-
Scope.method('use', function (path, namespace) {
|
|
552
|
-
var promise = this.require(path);
|
|
553
|
-
this.echo(resolve$1(promise, function (exports) {
|
|
554
|
-
var list = this.getMacro();
|
|
555
|
-
each(exports, function (macro, name) {
|
|
556
|
-
list[[namespace, name].join('.')] = macro;
|
|
557
559
|
});
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
560
|
+
Scope.method('get', function (name, defaults) {
|
|
561
|
+
var path = getPath(this, name);
|
|
562
|
+
var result = path.shift();
|
|
563
|
+
var prop = path.pop();
|
|
564
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
565
|
+
});
|
|
566
|
+
Scope.method('set', function (name, value) {
|
|
567
|
+
var path = getPath(this, name);
|
|
568
|
+
var result = path.shift();
|
|
569
|
+
var prop = path.pop();
|
|
570
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
571
|
+
return result[prop];
|
|
572
|
+
}
|
|
573
|
+
return result[prop] = value;
|
|
574
|
+
});
|
|
575
|
+
Scope.method('macro', function (name, callback) {
|
|
576
|
+
var list = this.getMacro();
|
|
577
|
+
var macro = this.fn(callback);
|
|
578
|
+
var context = this;
|
|
579
|
+
list[name] = function () {
|
|
580
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
581
|
+
};
|
|
582
|
+
});
|
|
583
|
+
Scope.method('call', function (name) {
|
|
584
|
+
var list = this.getMacro();
|
|
585
|
+
var macro = list[name];
|
|
586
|
+
var params = [].slice.call(arguments, 1);
|
|
587
|
+
if (isFunction(macro)) {
|
|
588
|
+
return macro.apply(macro, params);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
Scope.method('block', function (name, callback) {
|
|
592
|
+
var _this = this;
|
|
593
|
+
var blocks = this.getBlocks();
|
|
594
|
+
blocks[name] = blocks[name] || [];
|
|
595
|
+
blocks[name].push(this.fn(callback));
|
|
596
|
+
if (this.getExtend()) return;
|
|
597
|
+
var list = Object.assign([], blocks[name]);
|
|
598
|
+
var current = function current() {
|
|
599
|
+
return list.shift();
|
|
600
|
+
};
|
|
601
|
+
var next = function next() {
|
|
602
|
+
var parent = current();
|
|
603
|
+
if (parent) {
|
|
604
|
+
return function () {
|
|
605
|
+
_this.echo(parent(next()));
|
|
606
|
+
};
|
|
607
|
+
} else {
|
|
608
|
+
return noop;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
this.echo(current()(next()));
|
|
612
|
+
});
|
|
613
|
+
Scope.method('include', function (path, data, cx) {
|
|
614
|
+
var context = cx === false ? {} : this.clone(true);
|
|
615
|
+
var params = extend(context, data || {});
|
|
616
|
+
var promise = this.render(path, params);
|
|
617
|
+
this.echo(promise);
|
|
618
|
+
});
|
|
619
|
+
Scope.method('use', function (path, namespace) {
|
|
620
|
+
var promise = this.require(path);
|
|
621
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
622
|
+
var list = this.getMacro();
|
|
623
|
+
each(exports, function (macro, name) {
|
|
624
|
+
list[[namespace, name].join('.')] = macro;
|
|
625
|
+
});
|
|
626
|
+
}, this));
|
|
627
|
+
});
|
|
628
|
+
Scope.method('async', function (promise, callback) {
|
|
629
|
+
this.echo(resolve$1(promise, function (data) {
|
|
630
|
+
return this.fn(callback)(data);
|
|
631
|
+
}, this));
|
|
632
|
+
});
|
|
633
|
+
Scope.method('el', function (tag, attr, content) {
|
|
634
|
+
if (isFunction(content)) {
|
|
635
|
+
content = this.fn(content)();
|
|
636
|
+
}
|
|
637
|
+
this.echo(resolve$1(content, function (content) {
|
|
638
|
+
return element(tag, attr, content);
|
|
639
|
+
}, this));
|
|
640
|
+
});
|
|
641
|
+
Scope.method('each', function (object, callback) {
|
|
642
|
+
if (isString(object)) {
|
|
643
|
+
object = this.get(object, []);
|
|
644
|
+
}
|
|
645
|
+
each(object, callback);
|
|
646
|
+
});
|
|
576
647
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
};
|
|
648
|
+
}]);
|
|
649
|
+
return Context;
|
|
650
|
+
}();
|
|
581
651
|
|
|
582
652
|
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
583
|
-
function
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
653
|
+
var Cache = /*#__PURE__*/function () {
|
|
654
|
+
function Cache(config) {
|
|
655
|
+
_classCallCheck(this, Cache);
|
|
656
|
+
_defineProperty(this, "list", {});
|
|
657
|
+
this.configure(config);
|
|
658
|
+
if (isNode() === false) {
|
|
659
|
+
this.load(global[this.namespace]);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
_createClass(Cache, [{
|
|
663
|
+
key: "configure",
|
|
664
|
+
value: function configure(config) {
|
|
665
|
+
this.list = {};
|
|
666
|
+
this.namespace = config["export"];
|
|
667
|
+
}
|
|
668
|
+
}, {
|
|
669
|
+
key: "load",
|
|
670
|
+
value: function load(data) {
|
|
671
|
+
extend(this.list, data);
|
|
591
672
|
return this;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
673
|
+
}
|
|
674
|
+
}, {
|
|
675
|
+
key: "exist",
|
|
676
|
+
value: function exist(key) {
|
|
677
|
+
return hasProp(this.list, key);
|
|
678
|
+
}
|
|
679
|
+
}, {
|
|
680
|
+
key: "get",
|
|
681
|
+
value: function get(key) {
|
|
682
|
+
return this.list[key];
|
|
683
|
+
}
|
|
684
|
+
}, {
|
|
685
|
+
key: "remove",
|
|
686
|
+
value: function remove(key) {
|
|
687
|
+
delete this.list[key];
|
|
688
|
+
}
|
|
689
|
+
}, {
|
|
690
|
+
key: "resolve",
|
|
691
|
+
value: function resolve(key) {
|
|
603
692
|
return Promise.resolve(this.get(key));
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
load: function load(data) {
|
|
610
|
-
extend(list, data);
|
|
693
|
+
}
|
|
694
|
+
}, {
|
|
695
|
+
key: "set",
|
|
696
|
+
value: function set(key, value) {
|
|
697
|
+
this.list[key] = value;
|
|
611
698
|
return this;
|
|
612
699
|
}
|
|
613
|
-
};
|
|
614
|
-
return
|
|
615
|
-
}
|
|
700
|
+
}]);
|
|
701
|
+
return Cache;
|
|
702
|
+
}();
|
|
616
703
|
|
|
617
|
-
function
|
|
704
|
+
var configSchema = function configSchema(config, options) {
|
|
705
|
+
extend(config, {
|
|
706
|
+
"export": typeProp(isString, defaults["export"], options["export"]),
|
|
707
|
+
path: typeProp(isString, defaults.path, options.path),
|
|
708
|
+
resolver: typeProp(isFunction, defaults.resolver, options.resolver),
|
|
709
|
+
extension: typeProp(isString, defaults.extension, options.extension),
|
|
710
|
+
withObject: typeProp(isBoolean, defaults.withObject, options.withObject),
|
|
711
|
+
token: extend({}, defaults.token, options.token),
|
|
712
|
+
vars: extend({}, defaults.vars, options.vars)
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
var init = function init(options) {
|
|
716
|
+
/**
|
|
717
|
+
* EJS template
|
|
718
|
+
* @module ejs
|
|
719
|
+
*/
|
|
618
720
|
var config = {};
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
config.extension = typeProp(isString, defaults.extension, options.extension);
|
|
655
|
-
config.withObject = typeProp(isBoolean, defaults.withObject, options.withObject);
|
|
656
|
-
config.token = extend({}, defaults.token, options.token);
|
|
657
|
-
config.vars = extend({}, defaults.vars, options.vars);
|
|
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;
|
|
664
|
-
},
|
|
665
|
-
__express: function __express(name, options, callback) {
|
|
666
|
-
if (isFunction(options)) {
|
|
667
|
-
callback = options;
|
|
668
|
-
options = {};
|
|
721
|
+
configSchema(config, options || {});
|
|
722
|
+
var context = new Context(config);
|
|
723
|
+
var compiler = new Compiler(config);
|
|
724
|
+
var bundler = new Bundler(config);
|
|
725
|
+
var cache = new Cache(config);
|
|
726
|
+
var template = new Template(config, cache, compiler);
|
|
727
|
+
var configure = function configure(options) {
|
|
728
|
+
configSchema(config, options);
|
|
729
|
+
context.configure(config);
|
|
730
|
+
compiler.configure(config);
|
|
731
|
+
bundler.configure(config);
|
|
732
|
+
cache.configure(config);
|
|
733
|
+
template.configure(config);
|
|
734
|
+
};
|
|
735
|
+
var output = function output(path, scope) {
|
|
736
|
+
return template.get(path).then(function (callback) {
|
|
737
|
+
return callback.call(scope, scope, scope.getBuffer(), safeValue);
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
var _require = function require(name) {
|
|
741
|
+
var filepath = ext(name, config.extension);
|
|
742
|
+
var scope = context.create({});
|
|
743
|
+
return output(filepath, scope).then(function () {
|
|
744
|
+
return scope.getMacro();
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
var _render = function render(name, data) {
|
|
748
|
+
var filepath = ext(name, config.extension);
|
|
749
|
+
var scope = context.create(data);
|
|
750
|
+
return output(filepath, scope).then(function (content) {
|
|
751
|
+
if (scope.getExtend()) {
|
|
752
|
+
scope.setExtend(false);
|
|
753
|
+
var layout = scope.getLayout();
|
|
754
|
+
var _data = scope.clone();
|
|
755
|
+
return _render(layout, _data);
|
|
669
756
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
callback(null, content);
|
|
681
|
-
})["catch"](function (error) {
|
|
682
|
-
callback(error);
|
|
683
|
-
});
|
|
757
|
+
return content;
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
var helpers = function helpers(methods) {
|
|
761
|
+
context.helpers(extend(callbacks, methods || {}));
|
|
762
|
+
};
|
|
763
|
+
var __express = function __express(name, options, callback) {
|
|
764
|
+
if (isFunction(options)) {
|
|
765
|
+
callback = options;
|
|
766
|
+
options = {};
|
|
684
767
|
}
|
|
768
|
+
options = options || {};
|
|
769
|
+
var settings = extend({}, options.settings);
|
|
770
|
+
var viewPath = typeProp(isString, settings['views'], defaults.path);
|
|
771
|
+
var viewCache = typeProp(isBoolean, settings['view cache'], defaults.cache);
|
|
772
|
+
var viewOptions = extend({}, settings['view options']);
|
|
773
|
+
var filename = path.relative(viewPath, name);
|
|
774
|
+
viewOptions.path = viewPath;
|
|
775
|
+
viewOptions.cache = viewCache;
|
|
776
|
+
configure(viewOptions);
|
|
777
|
+
return _render(filename, options).then(function (content) {
|
|
778
|
+
callback(null, content);
|
|
779
|
+
})["catch"](function (error) {
|
|
780
|
+
callback(error);
|
|
781
|
+
});
|
|
782
|
+
};
|
|
783
|
+
var preload = function preload(list) {
|
|
784
|
+
return cache.load(list);
|
|
785
|
+
};
|
|
786
|
+
var wrapper = function wrapper(list) {
|
|
787
|
+
return bundler.wrapper(list);
|
|
788
|
+
};
|
|
789
|
+
var compile = function compile(content, path) {
|
|
790
|
+
return compiler.compile(content, path);
|
|
685
791
|
};
|
|
686
|
-
|
|
687
|
-
|
|
792
|
+
var create = function create(options) {
|
|
793
|
+
return init(options);
|
|
794
|
+
};
|
|
795
|
+
helpers({
|
|
688
796
|
require: function require(name) {
|
|
689
|
-
return
|
|
797
|
+
return _require(name);
|
|
690
798
|
},
|
|
691
799
|
render: function render(name, data) {
|
|
692
|
-
return
|
|
800
|
+
return _render(name, data);
|
|
693
801
|
}
|
|
694
802
|
});
|
|
695
|
-
return
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
803
|
+
return {
|
|
804
|
+
render: _render,
|
|
805
|
+
helpers: helpers,
|
|
806
|
+
configure: configure,
|
|
807
|
+
wrapper: wrapper,
|
|
808
|
+
compile: compile,
|
|
809
|
+
create: create,
|
|
810
|
+
preload: preload,
|
|
811
|
+
__express: __express
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
var _init = init({}),
|
|
815
|
+
render = _init.render,
|
|
816
|
+
helpers = _init.helpers,
|
|
817
|
+
configure = _init.configure,
|
|
818
|
+
wrapper = _init.wrapper,
|
|
819
|
+
compile = _init.compile,
|
|
820
|
+
create = _init.create,
|
|
821
|
+
preload = _init.preload,
|
|
822
|
+
__express = _init.__express;
|
|
823
|
+
|
|
824
|
+
exports.__express = __express;
|
|
825
|
+
exports.compile = compile;
|
|
826
|
+
exports.configure = configure;
|
|
827
|
+
exports.create = create;
|
|
828
|
+
exports.element = element;
|
|
829
|
+
exports.helpers = helpers;
|
|
830
|
+
exports.preload = preload;
|
|
831
|
+
exports.render = render;
|
|
832
|
+
exports.safeValue = safeValue;
|
|
833
|
+
exports.wrapper = wrapper;
|
|
699
834
|
|
|
700
|
-
|
|
835
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
701
836
|
|
|
702
837
|
}));
|