@kosatyi/ejs 0.0.64 → 0.0.66
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/README.md +2 -6
- package/dist/cjs/index.js +387 -246
- package/dist/esm/index.js +415 -323
- package/dist/umd/index.js +387 -246
- package/dist/umd/index.min.js +1 -1
- package/package.json +3 -9
package/dist/cjs/index.js
CHANGED
|
@@ -62,7 +62,7 @@ var safeValue = function safeValue(value, escape) {
|
|
|
62
62
|
return check == null ? '' : escape === true ? entities(check) : check;
|
|
63
63
|
};
|
|
64
64
|
var instanceOf = function instanceOf(object, instance) {
|
|
65
|
-
return object instanceof instance;
|
|
65
|
+
return Boolean(object instanceof instance);
|
|
66
66
|
};
|
|
67
67
|
var getPath = function getPath(context, name, strict) {
|
|
68
68
|
var data = context;
|
|
@@ -91,11 +91,14 @@ var ext = function ext(path, defaults) {
|
|
|
91
91
|
}
|
|
92
92
|
return path;
|
|
93
93
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @type {<T extends {}, U, V, W,Y>(T,U,V,W,Y)=> T & U & V & W & Y}
|
|
97
|
+
*/
|
|
98
|
+
var extend = function extend(target) {
|
|
99
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
100
|
+
args[_key - 1] = arguments[_key];
|
|
97
101
|
}
|
|
98
|
-
var target = args.shift();
|
|
99
102
|
return args.filter(function (source) {
|
|
100
103
|
return source;
|
|
101
104
|
}).reduce(function (target, source) {
|
|
@@ -208,67 +211,54 @@ var configSchema = function configSchema(config, options) {
|
|
|
208
211
|
extension: typeProp(isString, defaults.extension, config.extension, options.extension),
|
|
209
212
|
withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
|
|
210
213
|
rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
|
|
211
|
-
cache: typeProp(isBoolean, defaults.
|
|
214
|
+
cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
|
|
212
215
|
token: extend({}, defaults.token, config.token, options.token),
|
|
213
216
|
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
214
217
|
});
|
|
215
218
|
};
|
|
216
219
|
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return fetch(resolvePath(path, template)).then(function (response) {
|
|
224
|
-
return response.text();
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
|
-
var fileSystem = function fileSystem(path, template) {
|
|
228
|
-
return new Promise(function (resolve, reject) {
|
|
229
|
-
fs.readFile(resolvePath(path, template), function (error, data) {
|
|
230
|
-
if (error) {
|
|
231
|
-
reject(error);
|
|
232
|
-
} else {
|
|
233
|
-
resolve(data.toString());
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
var fileResolver = function fileResolver(resolver) {
|
|
239
|
-
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
240
|
-
};
|
|
241
|
-
function Template(config, cache, compiler) {
|
|
242
|
-
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
243
|
-
var template = {};
|
|
244
|
-
var result = function result(template, content) {
|
|
245
|
-
cache.set(template, content);
|
|
246
|
-
return content;
|
|
220
|
+
var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
221
|
+
function Cache(config) {
|
|
222
|
+
if (instanceOf(this, Cache) === false) return new Cache();
|
|
223
|
+
var cache = {
|
|
224
|
+
enabled: true,
|
|
225
|
+
list: {}
|
|
247
226
|
};
|
|
248
|
-
|
|
249
|
-
|
|
227
|
+
this.configure = function (config) {
|
|
228
|
+
cache.enabled = config.cache;
|
|
229
|
+
if (isNode() === false) {
|
|
230
|
+
this.load(global[config["export"]]);
|
|
231
|
+
}
|
|
250
232
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
233
|
+
this.clear = function () {
|
|
234
|
+
cache.list = {};
|
|
235
|
+
};
|
|
236
|
+
this.load = function (data) {
|
|
237
|
+
if (cache.enabled) {
|
|
238
|
+
extend(cache.list, data || {});
|
|
256
239
|
}
|
|
240
|
+
return this;
|
|
257
241
|
};
|
|
258
|
-
this.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
242
|
+
this.get = function (key) {
|
|
243
|
+
if (cache.enabled) {
|
|
244
|
+
return cache.list[key];
|
|
245
|
+
}
|
|
262
246
|
};
|
|
263
|
-
this.
|
|
264
|
-
if (cache.
|
|
265
|
-
|
|
247
|
+
this.set = function (key, value) {
|
|
248
|
+
if (cache.enabled) {
|
|
249
|
+
cache.list[key] = value;
|
|
266
250
|
}
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
251
|
+
return this;
|
|
252
|
+
};
|
|
253
|
+
this.resolve = function (key) {
|
|
254
|
+
return Promise.resolve(this.get(key));
|
|
255
|
+
};
|
|
256
|
+
this.remove = function (key) {
|
|
257
|
+
delete cache.list[key];
|
|
258
|
+
};
|
|
259
|
+
this.exist = function (key) {
|
|
260
|
+
return hasProp(cache.list, key);
|
|
270
261
|
};
|
|
271
|
-
this.configure(config);
|
|
272
262
|
}
|
|
273
263
|
|
|
274
264
|
var tagList = [{
|
|
@@ -366,46 +356,92 @@ function Compiler(config) {
|
|
|
366
356
|
this.configure(config);
|
|
367
357
|
}
|
|
368
358
|
|
|
369
|
-
var
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
359
|
+
var resolvePath = function resolvePath(path, template) {
|
|
360
|
+
template = [path, template].join('/');
|
|
361
|
+
template = template.replace(/\/\//g, '/');
|
|
362
|
+
return template;
|
|
363
|
+
};
|
|
364
|
+
var httpRequest = function httpRequest(path, template) {
|
|
365
|
+
return fetch(resolvePath(path, template)).then(function (response) {
|
|
366
|
+
return response.text();
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
var fileSystem = function fileSystem(path, template) {
|
|
370
|
+
return new Promise(function (resolve, reject) {
|
|
371
|
+
fs.readFile(resolvePath(path, template), function (error, data) {
|
|
372
|
+
if (error) {
|
|
373
|
+
reject(error);
|
|
374
|
+
} else {
|
|
375
|
+
resolve(data.toString());
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
var fileResolver = function fileResolver(resolver) {
|
|
381
|
+
return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
|
|
382
|
+
};
|
|
383
|
+
function Template(config, cache, compiler) {
|
|
384
|
+
if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
|
|
385
|
+
if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
|
|
386
|
+
if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
|
|
387
|
+
var template = {};
|
|
388
|
+
var result = function result(template, content) {
|
|
389
|
+
cache.set(template, content);
|
|
390
|
+
return content;
|
|
375
391
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
cache.enabled = config.cache;
|
|
379
|
-
if (isNode() === false) {
|
|
380
|
-
this.load(global[config["export"]]);
|
|
381
|
-
}
|
|
392
|
+
var resolve = function resolve(path) {
|
|
393
|
+
return template.resolver(template.path, path);
|
|
382
394
|
};
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
395
|
+
var compile = function compile(content, template) {
|
|
396
|
+
if (isFunction(content)) {
|
|
397
|
+
return content;
|
|
398
|
+
} else {
|
|
399
|
+
return compiler.compile(content, template);
|
|
386
400
|
}
|
|
387
|
-
return this;
|
|
388
401
|
};
|
|
389
|
-
this.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
402
|
+
this.configure = function (config) {
|
|
403
|
+
template.path = config.path;
|
|
404
|
+
template.cache = config.cache;
|
|
405
|
+
template.resolver = fileResolver(config.resolver);
|
|
393
406
|
};
|
|
394
|
-
this.
|
|
395
|
-
if (cache.
|
|
396
|
-
cache.
|
|
407
|
+
this.get = function (template) {
|
|
408
|
+
if (cache.exist(template)) {
|
|
409
|
+
return cache.resolve(template);
|
|
397
410
|
}
|
|
398
|
-
return
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
return Promise.resolve(this.get(key));
|
|
402
|
-
};
|
|
403
|
-
this.remove = function (key) {
|
|
404
|
-
delete cache.list[key];
|
|
405
|
-
};
|
|
406
|
-
this.exist = function (key) {
|
|
407
|
-
return hasProp(cache.list, key);
|
|
411
|
+
return result(template, resolve(template).then(function (content) {
|
|
412
|
+
return result(template, compile(content, template));
|
|
413
|
+
}));
|
|
408
414
|
};
|
|
415
|
+
this.configure(config);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function _defineProperty(obj, key, value) {
|
|
419
|
+
key = _toPropertyKey(key);
|
|
420
|
+
if (key in obj) {
|
|
421
|
+
Object.defineProperty(obj, key, {
|
|
422
|
+
value: value,
|
|
423
|
+
enumerable: true,
|
|
424
|
+
configurable: true,
|
|
425
|
+
writable: true
|
|
426
|
+
});
|
|
427
|
+
} else {
|
|
428
|
+
obj[key] = value;
|
|
429
|
+
}
|
|
430
|
+
return obj;
|
|
431
|
+
}
|
|
432
|
+
function _toPrimitive(input, hint) {
|
|
433
|
+
if (typeof input !== "object" || input === null) return input;
|
|
434
|
+
var prim = input[Symbol.toPrimitive];
|
|
435
|
+
if (prim !== undefined) {
|
|
436
|
+
var res = prim.call(input, hint || "default");
|
|
437
|
+
if (typeof res !== "object") return res;
|
|
438
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
439
|
+
}
|
|
440
|
+
return (hint === "string" ? String : Number)(input);
|
|
441
|
+
}
|
|
442
|
+
function _toPropertyKey(arg) {
|
|
443
|
+
var key = _toPrimitive(arg, "string");
|
|
444
|
+
return typeof key === "symbol" ? key : String(key);
|
|
409
445
|
}
|
|
410
446
|
|
|
411
447
|
function resolve(list) {
|
|
@@ -413,7 +449,7 @@ function resolve(list) {
|
|
|
413
449
|
return list.join('');
|
|
414
450
|
});
|
|
415
451
|
}
|
|
416
|
-
|
|
452
|
+
function createBuffer() {
|
|
417
453
|
var store = [],
|
|
418
454
|
array = [];
|
|
419
455
|
function buffer(value) {
|
|
@@ -438,11 +474,12 @@ var createBuffer = function createBuffer() {
|
|
|
438
474
|
return resolve(array);
|
|
439
475
|
};
|
|
440
476
|
return buffer;
|
|
441
|
-
}
|
|
477
|
+
}
|
|
442
478
|
|
|
443
479
|
function Context(config) {
|
|
444
480
|
if (instanceOf(this, Context) === false) return new Context(config);
|
|
445
481
|
this.configure = function (config, methods) {
|
|
482
|
+
var _Object$definePropert;
|
|
446
483
|
var _config$vars = config.vars,
|
|
447
484
|
BLOCKS = _config$vars.BLOCKS,
|
|
448
485
|
MACRO = _config$vars.MACRO,
|
|
@@ -455,6 +492,7 @@ function Context(config) {
|
|
|
455
492
|
};
|
|
456
493
|
this.helpers = function (methods) {
|
|
457
494
|
extend(Scope.prototype, methods || {});
|
|
495
|
+
console.log('helpers', Scope.prototype);
|
|
458
496
|
};
|
|
459
497
|
function Scope(data) {
|
|
460
498
|
this[BLOCKS] = {};
|
|
@@ -462,168 +500,270 @@ function Context(config) {
|
|
|
462
500
|
extend(this, data || {});
|
|
463
501
|
}
|
|
464
502
|
Scope.prototype = extend({}, methods || {});
|
|
465
|
-
Scope.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
503
|
+
Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_Object$definePropert, BUFFER, {
|
|
504
|
+
value: createBuffer(),
|
|
505
|
+
writable: true,
|
|
506
|
+
configurable: false,
|
|
507
|
+
enumerable: false
|
|
508
|
+
}), _defineProperty(_Object$definePropert, BLOCKS, {
|
|
509
|
+
value: {},
|
|
510
|
+
writable: true,
|
|
511
|
+
configurable: false,
|
|
512
|
+
enumerable: false
|
|
513
|
+
}), _defineProperty(_Object$definePropert, MACRO, {
|
|
514
|
+
value: {},
|
|
515
|
+
writable: true,
|
|
516
|
+
configurable: false,
|
|
517
|
+
enumerable: false
|
|
518
|
+
}), _defineProperty(_Object$definePropert, LAYOUT, {
|
|
519
|
+
value: false,
|
|
520
|
+
writable: true,
|
|
521
|
+
configurable: false,
|
|
522
|
+
enumerable: false
|
|
523
|
+
}), _defineProperty(_Object$definePropert, EXTEND, {
|
|
524
|
+
value: false,
|
|
525
|
+
writable: true,
|
|
526
|
+
configurable: false,
|
|
527
|
+
enumerable: false
|
|
528
|
+
}), _defineProperty(_Object$definePropert, "getMacro", {
|
|
529
|
+
value: function value() {
|
|
530
|
+
return this[MACRO];
|
|
531
|
+
},
|
|
532
|
+
writable: false,
|
|
533
|
+
configurable: false,
|
|
534
|
+
enumerable: false
|
|
535
|
+
}), _defineProperty(_Object$definePropert, "getBuffer", {
|
|
536
|
+
value: function value() {
|
|
537
|
+
return this[BUFFER];
|
|
538
|
+
},
|
|
539
|
+
writable: false,
|
|
540
|
+
configurable: false,
|
|
541
|
+
enumerable: false
|
|
542
|
+
}), _defineProperty(_Object$definePropert, "getComponent", {
|
|
543
|
+
value: function value() {
|
|
544
|
+
var context = this;
|
|
545
|
+
if (COMPONENT in context) {
|
|
546
|
+
return function () {
|
|
547
|
+
return context[COMPONENT].apply(context, arguments);
|
|
548
|
+
};
|
|
549
|
+
}
|
|
487
550
|
return function () {
|
|
488
|
-
|
|
551
|
+
console.log('%s function not defined', COMPONENT);
|
|
489
552
|
};
|
|
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
|
-
|
|
553
|
+
},
|
|
554
|
+
writable: false,
|
|
555
|
+
configurable: false,
|
|
556
|
+
enumerable: false
|
|
557
|
+
}), _defineProperty(_Object$definePropert, "getBlocks", {
|
|
558
|
+
value: function value() {
|
|
559
|
+
return this[BLOCKS];
|
|
560
|
+
},
|
|
561
|
+
writable: false,
|
|
562
|
+
configurable: false,
|
|
563
|
+
enumerable: false
|
|
564
|
+
}), _defineProperty(_Object$definePropert, "setExtend", {
|
|
565
|
+
value: function value(_value) {
|
|
566
|
+
this[EXTEND] = _value;
|
|
567
|
+
},
|
|
568
|
+
writable: false,
|
|
569
|
+
configurable: false,
|
|
570
|
+
enumerable: false
|
|
571
|
+
}), _defineProperty(_Object$definePropert, "getExtend", {
|
|
572
|
+
value: function value() {
|
|
573
|
+
return this[EXTEND];
|
|
574
|
+
},
|
|
575
|
+
writable: false,
|
|
576
|
+
configurable: false,
|
|
577
|
+
enumerable: false
|
|
578
|
+
}), _defineProperty(_Object$definePropert, "setLayout", {
|
|
579
|
+
value: function value(layout) {
|
|
580
|
+
this[LAYOUT] = layout;
|
|
581
|
+
},
|
|
582
|
+
writable: false,
|
|
583
|
+
configurable: false,
|
|
584
|
+
enumerable: false
|
|
585
|
+
}), _defineProperty(_Object$definePropert, "getLayout", {
|
|
586
|
+
value: function value() {
|
|
587
|
+
return this[LAYOUT];
|
|
588
|
+
},
|
|
589
|
+
writable: false,
|
|
590
|
+
configurable: false,
|
|
591
|
+
enumerable: false
|
|
592
|
+
}), _defineProperty(_Object$definePropert, "clone", {
|
|
593
|
+
value: function value(exclude_blocks) {
|
|
594
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
595
|
+
if (exclude_blocks === true) {
|
|
596
|
+
filter.push(BLOCKS);
|
|
533
597
|
}
|
|
534
|
-
return
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
return
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
598
|
+
return omit(this, filter);
|
|
599
|
+
},
|
|
600
|
+
writable: false,
|
|
601
|
+
configurable: false,
|
|
602
|
+
enumerable: false
|
|
603
|
+
}), _defineProperty(_Object$definePropert, "extend", {
|
|
604
|
+
value: function value(layout) {
|
|
605
|
+
this.setExtend(true);
|
|
606
|
+
this.setLayout(layout);
|
|
607
|
+
},
|
|
608
|
+
writable: false,
|
|
609
|
+
configurable: false,
|
|
610
|
+
enumerable: false
|
|
611
|
+
}), _defineProperty(_Object$definePropert, "echo", {
|
|
612
|
+
value: function value(layout) {
|
|
613
|
+
var buffer = this.getBuffer();
|
|
614
|
+
var params = [].slice.call(arguments);
|
|
615
|
+
params.forEach(buffer);
|
|
616
|
+
},
|
|
617
|
+
writable: false,
|
|
618
|
+
configurable: false,
|
|
619
|
+
enumerable: false
|
|
620
|
+
}), _defineProperty(_Object$definePropert, "fn", {
|
|
621
|
+
value: function value(callback) {
|
|
622
|
+
var buffer = this.getBuffer();
|
|
623
|
+
var context = this;
|
|
624
|
+
return function () {
|
|
625
|
+
buffer.backup();
|
|
626
|
+
if (isFunction(callback)) {
|
|
627
|
+
callback.apply(context, arguments);
|
|
628
|
+
}
|
|
629
|
+
return buffer.restore();
|
|
630
|
+
};
|
|
631
|
+
},
|
|
632
|
+
writable: false,
|
|
633
|
+
configurable: false,
|
|
634
|
+
enumerable: false
|
|
635
|
+
}), _defineProperty(_Object$definePropert, "get", {
|
|
636
|
+
value: function value(name, defaults) {
|
|
637
|
+
var path = getPath(this, name, true);
|
|
638
|
+
var result = path.shift();
|
|
639
|
+
var prop = path.pop();
|
|
640
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
641
|
+
},
|
|
642
|
+
writable: false,
|
|
643
|
+
configurable: false,
|
|
644
|
+
enumerable: false
|
|
645
|
+
}), _defineProperty(_Object$definePropert, "set", {
|
|
646
|
+
value: function value(name, _value2) {
|
|
647
|
+
var path = getPath(this, name, false);
|
|
648
|
+
var result = path.shift();
|
|
649
|
+
var prop = path.pop();
|
|
650
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
651
|
+
return result[prop];
|
|
586
652
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
this.echo(promise);
|
|
595
|
-
});
|
|
596
|
-
Scope.method('use', function (path, namespace) {
|
|
597
|
-
var promise = this.require(path);
|
|
598
|
-
this.echo(resolve$1(promise, function (exports) {
|
|
653
|
+
return result[prop] = _value2;
|
|
654
|
+
},
|
|
655
|
+
writable: false,
|
|
656
|
+
configurable: false,
|
|
657
|
+
enumerable: false
|
|
658
|
+
}), _defineProperty(_Object$definePropert, "macro", {
|
|
659
|
+
value: function value(name, callback) {
|
|
599
660
|
var list = this.getMacro();
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
})
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
661
|
+
var macro = this.fn(callback);
|
|
662
|
+
var context = this;
|
|
663
|
+
list[name] = function () {
|
|
664
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
665
|
+
};
|
|
666
|
+
},
|
|
667
|
+
writable: false,
|
|
668
|
+
configurable: false,
|
|
669
|
+
enumerable: false
|
|
670
|
+
}), _defineProperty(_Object$definePropert, "call", {
|
|
671
|
+
value: function value(name) {
|
|
672
|
+
var list = this.getMacro();
|
|
673
|
+
var macro = list[name];
|
|
674
|
+
var params = [].slice.call(arguments, 1);
|
|
675
|
+
if (isFunction(macro)) {
|
|
676
|
+
return macro.apply(macro, params);
|
|
677
|
+
}
|
|
678
|
+
},
|
|
679
|
+
writable: false,
|
|
680
|
+
configurable: false,
|
|
681
|
+
enumerable: false
|
|
682
|
+
}), _defineProperty(_Object$definePropert, "block", {
|
|
683
|
+
value: function value(name, callback) {
|
|
684
|
+
var _this = this;
|
|
685
|
+
var blocks = this.getBlocks();
|
|
686
|
+
blocks[name] = blocks[name] || [];
|
|
687
|
+
blocks[name].push(this.fn(callback));
|
|
688
|
+
if (this.getExtend()) return;
|
|
689
|
+
var list = Object.assign([], blocks[name]);
|
|
690
|
+
var current = function current() {
|
|
691
|
+
return list.shift();
|
|
692
|
+
};
|
|
693
|
+
var next = function next() {
|
|
694
|
+
var parent = current();
|
|
695
|
+
if (parent) {
|
|
696
|
+
return function () {
|
|
697
|
+
_this.echo(parent(next()));
|
|
698
|
+
};
|
|
699
|
+
} else {
|
|
700
|
+
return noop;
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
this.echo(current()(next()));
|
|
704
|
+
},
|
|
705
|
+
writable: false,
|
|
706
|
+
configurable: false,
|
|
707
|
+
enumerable: false
|
|
708
|
+
}), _defineProperty(_Object$definePropert, "include", {
|
|
709
|
+
value: function value(path, data, cx) {
|
|
710
|
+
var context = cx === false ? {} : this.clone(true);
|
|
711
|
+
var params = extend(context, data || {});
|
|
712
|
+
var promise = this.render(path, params);
|
|
713
|
+
this.echo(promise);
|
|
714
|
+
},
|
|
715
|
+
writable: false,
|
|
716
|
+
configurable: false,
|
|
717
|
+
enumerable: false
|
|
718
|
+
}), _defineProperty(_Object$definePropert, "use", {
|
|
719
|
+
value: function value(path, namespace) {
|
|
720
|
+
var promise = this.require(path);
|
|
721
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
722
|
+
var list = this.getMacro();
|
|
723
|
+
each(exports, function (macro, name) {
|
|
724
|
+
list[[namespace, name].join('.')] = macro;
|
|
725
|
+
});
|
|
726
|
+
}, this));
|
|
727
|
+
},
|
|
728
|
+
writable: false,
|
|
729
|
+
configurable: false,
|
|
730
|
+
enumerable: false
|
|
731
|
+
}), _defineProperty(_Object$definePropert, "async", {
|
|
732
|
+
value: function value(promise, callback) {
|
|
733
|
+
this.echo(resolve$1(promise, function (data) {
|
|
734
|
+
return this.fn(callback)(data);
|
|
735
|
+
}, this));
|
|
736
|
+
},
|
|
737
|
+
writable: false,
|
|
738
|
+
configurable: false,
|
|
739
|
+
enumerable: false
|
|
740
|
+
}), _defineProperty(_Object$definePropert, "each", {
|
|
741
|
+
value: function value(object, callback) {
|
|
742
|
+
if (isString(object)) {
|
|
743
|
+
object = this.get(object, []);
|
|
744
|
+
}
|
|
745
|
+
each(object, callback);
|
|
746
|
+
},
|
|
747
|
+
writable: false,
|
|
748
|
+
configurable: false,
|
|
749
|
+
enumerable: false
|
|
750
|
+
}), _defineProperty(_Object$definePropert, "element", {
|
|
751
|
+
value: function value(tag, attr, content) {
|
|
618
752
|
return element(tag, attr, content);
|
|
619
|
-
}, this));
|
|
620
|
-
});
|
|
621
|
-
Scope.method('each', function (object, callback) {
|
|
622
|
-
if (isString(object)) {
|
|
623
|
-
object = this.get(object, []);
|
|
624
753
|
}
|
|
625
|
-
|
|
626
|
-
|
|
754
|
+
}), _defineProperty(_Object$definePropert, "el", {
|
|
755
|
+
value: function value(tag, attr, content) {
|
|
756
|
+
if (isFunction(content)) {
|
|
757
|
+
content = this.fn(content)();
|
|
758
|
+
}
|
|
759
|
+
this.echo(resolve$1(content, function (content) {
|
|
760
|
+
return this.element(tag, attr, content);
|
|
761
|
+
}, this));
|
|
762
|
+
},
|
|
763
|
+
writable: false,
|
|
764
|
+
configurable: false,
|
|
765
|
+
enumerable: false
|
|
766
|
+
}), _Object$definePropert));
|
|
627
767
|
};
|
|
628
768
|
this.configure(config);
|
|
629
769
|
}
|
|
@@ -675,7 +815,7 @@ function EJS(options) {
|
|
|
675
815
|
return render(name, data);
|
|
676
816
|
};
|
|
677
817
|
this.helpers = function (methods) {
|
|
678
|
-
context.helpers(
|
|
818
|
+
context.helpers(extend(scope, methods));
|
|
679
819
|
};
|
|
680
820
|
this.preload = function (list) {
|
|
681
821
|
return cache.load(list || {});
|
|
@@ -693,6 +833,7 @@ function EJS(options) {
|
|
|
693
833
|
require: require,
|
|
694
834
|
render: render
|
|
695
835
|
});
|
|
836
|
+
return this;
|
|
696
837
|
}
|
|
697
838
|
|
|
698
839
|
var ejs = new EJS();
|
|
@@ -718,7 +859,7 @@ function __express(name, options, callback) {
|
|
|
718
859
|
viewOptions.path = viewPath;
|
|
719
860
|
viewOptions.cache = viewCache;
|
|
720
861
|
configure(viewOptions);
|
|
721
|
-
return
|
|
862
|
+
return render(filename, options).then(function (content) {
|
|
722
863
|
callback(null, content);
|
|
723
864
|
})["catch"](function (error) {
|
|
724
865
|
callback(error);
|