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