@kosatyi/ejs 0.0.65 → 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 +299 -162
- package/dist/esm/index.js +318 -223
- package/dist/umd/index.js +299 -162
- package/dist/umd/index.min.js +1 -1
- package/package.json +3 -9
package/README.md
CHANGED
|
@@ -55,10 +55,8 @@ const ejs = require('@kosatyi/ejs')
|
|
|
55
55
|
const app = express()
|
|
56
56
|
app.engine('ejs', ejs.__express)
|
|
57
57
|
app.set('views', 'views')
|
|
58
|
+
app.set('view cache', false)
|
|
58
59
|
app.set('view engine', 'ejs')
|
|
59
|
-
app.set('view options', {
|
|
60
|
-
watch: true,
|
|
61
|
-
})
|
|
62
60
|
```
|
|
63
61
|
|
|
64
62
|
or use `ejs` alias
|
|
@@ -72,9 +70,7 @@ const express = require('express')
|
|
|
72
70
|
const app = express()
|
|
73
71
|
app.set('views', 'views')
|
|
74
72
|
app.set('view engine', 'ejs')
|
|
75
|
-
app.set('view
|
|
76
|
-
watch: true,
|
|
77
|
-
})
|
|
73
|
+
app.set('view cache', false)
|
|
78
74
|
```
|
|
79
75
|
|
|
80
76
|
## Template Example
|
package/dist/cjs/index.js
CHANGED
|
@@ -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) {
|
|
@@ -412,12 +415,41 @@ function Template(config, cache, compiler) {
|
|
|
412
415
|
this.configure(config);
|
|
413
416
|
}
|
|
414
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);
|
|
445
|
+
}
|
|
446
|
+
|
|
415
447
|
function resolve(list) {
|
|
416
448
|
return Promise.all(list || []).then(function (list) {
|
|
417
449
|
return list.join('');
|
|
418
450
|
});
|
|
419
451
|
}
|
|
420
|
-
|
|
452
|
+
function createBuffer() {
|
|
421
453
|
var store = [],
|
|
422
454
|
array = [];
|
|
423
455
|
function buffer(value) {
|
|
@@ -442,11 +474,12 @@ var createBuffer = function createBuffer() {
|
|
|
442
474
|
return resolve(array);
|
|
443
475
|
};
|
|
444
476
|
return buffer;
|
|
445
|
-
}
|
|
477
|
+
}
|
|
446
478
|
|
|
447
479
|
function Context(config) {
|
|
448
480
|
if (instanceOf(this, Context) === false) return new Context(config);
|
|
449
481
|
this.configure = function (config, methods) {
|
|
482
|
+
var _Object$definePropert;
|
|
450
483
|
var _config$vars = config.vars,
|
|
451
484
|
BLOCKS = _config$vars.BLOCKS,
|
|
452
485
|
MACRO = _config$vars.MACRO,
|
|
@@ -459,6 +492,7 @@ function Context(config) {
|
|
|
459
492
|
};
|
|
460
493
|
this.helpers = function (methods) {
|
|
461
494
|
extend(Scope.prototype, methods || {});
|
|
495
|
+
console.log('helpers', Scope.prototype);
|
|
462
496
|
};
|
|
463
497
|
function Scope(data) {
|
|
464
498
|
this[BLOCKS] = {};
|
|
@@ -466,168 +500,270 @@ function Context(config) {
|
|
|
466
500
|
extend(this, data || {});
|
|
467
501
|
}
|
|
468
502
|
Scope.prototype = extend({}, methods || {});
|
|
469
|
-
Scope.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
+
}
|
|
491
550
|
return function () {
|
|
492
|
-
|
|
551
|
+
console.log('%s function not defined', COMPONENT);
|
|
493
552
|
};
|
|
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
|
-
|
|
536
|
-
|
|
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);
|
|
537
597
|
}
|
|
538
|
-
return
|
|
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
|
-
|
|
580
|
-
return
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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];
|
|
590
652
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
this.echo(promise);
|
|
599
|
-
});
|
|
600
|
-
Scope.method('use', function (path, namespace) {
|
|
601
|
-
var promise = this.require(path);
|
|
602
|
-
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) {
|
|
603
660
|
var list = this.getMacro();
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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) {
|
|
622
752
|
return element(tag, attr, content);
|
|
623
|
-
}, this));
|
|
624
|
-
});
|
|
625
|
-
Scope.method('each', function (object, callback) {
|
|
626
|
-
if (isString(object)) {
|
|
627
|
-
object = this.get(object, []);
|
|
628
753
|
}
|
|
629
|
-
|
|
630
|
-
|
|
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));
|
|
631
767
|
};
|
|
632
768
|
this.configure(config);
|
|
633
769
|
}
|
|
@@ -679,7 +815,7 @@ function EJS(options) {
|
|
|
679
815
|
return render(name, data);
|
|
680
816
|
};
|
|
681
817
|
this.helpers = function (methods) {
|
|
682
|
-
context.helpers(
|
|
818
|
+
context.helpers(extend(scope, methods));
|
|
683
819
|
};
|
|
684
820
|
this.preload = function (list) {
|
|
685
821
|
return cache.load(list || {});
|
|
@@ -697,6 +833,7 @@ function EJS(options) {
|
|
|
697
833
|
require: require,
|
|
698
834
|
render: render
|
|
699
835
|
});
|
|
836
|
+
return this;
|
|
700
837
|
}
|
|
701
838
|
|
|
702
839
|
var ejs = new EJS();
|