@kosatyi/ejs 0.0.65 → 0.0.67
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 +298 -162
- package/dist/esm/index.js +317 -223
- package/dist/umd/index.js +298 -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,
|
|
@@ -466,168 +499,270 @@ function Context(config) {
|
|
|
466
499
|
extend(this, data || {});
|
|
467
500
|
}
|
|
468
501
|
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
|
-
|
|
502
|
+
Object.defineProperties(Scope.prototype, (_Object$definePropert = {}, _defineProperty(_Object$definePropert, BUFFER, {
|
|
503
|
+
value: createBuffer(),
|
|
504
|
+
writable: true,
|
|
505
|
+
configurable: false,
|
|
506
|
+
enumerable: false
|
|
507
|
+
}), _defineProperty(_Object$definePropert, BLOCKS, {
|
|
508
|
+
value: {},
|
|
509
|
+
writable: true,
|
|
510
|
+
configurable: false,
|
|
511
|
+
enumerable: false
|
|
512
|
+
}), _defineProperty(_Object$definePropert, MACRO, {
|
|
513
|
+
value: {},
|
|
514
|
+
writable: true,
|
|
515
|
+
configurable: false,
|
|
516
|
+
enumerable: false
|
|
517
|
+
}), _defineProperty(_Object$definePropert, LAYOUT, {
|
|
518
|
+
value: false,
|
|
519
|
+
writable: true,
|
|
520
|
+
configurable: false,
|
|
521
|
+
enumerable: false
|
|
522
|
+
}), _defineProperty(_Object$definePropert, EXTEND, {
|
|
523
|
+
value: false,
|
|
524
|
+
writable: true,
|
|
525
|
+
configurable: false,
|
|
526
|
+
enumerable: false
|
|
527
|
+
}), _defineProperty(_Object$definePropert, "getMacro", {
|
|
528
|
+
value: function value() {
|
|
529
|
+
return this[MACRO];
|
|
530
|
+
},
|
|
531
|
+
writable: false,
|
|
532
|
+
configurable: false,
|
|
533
|
+
enumerable: false
|
|
534
|
+
}), _defineProperty(_Object$definePropert, "getBuffer", {
|
|
535
|
+
value: function value() {
|
|
536
|
+
return this[BUFFER];
|
|
537
|
+
},
|
|
538
|
+
writable: false,
|
|
539
|
+
configurable: false,
|
|
540
|
+
enumerable: false
|
|
541
|
+
}), _defineProperty(_Object$definePropert, "getComponent", {
|
|
542
|
+
value: function value() {
|
|
543
|
+
var context = this;
|
|
544
|
+
if (COMPONENT in context) {
|
|
545
|
+
return function () {
|
|
546
|
+
return context[COMPONENT].apply(context, arguments);
|
|
547
|
+
};
|
|
548
|
+
}
|
|
491
549
|
return function () {
|
|
492
|
-
|
|
550
|
+
console.log('%s function not defined', COMPONENT);
|
|
493
551
|
};
|
|
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
|
-
|
|
552
|
+
},
|
|
553
|
+
writable: false,
|
|
554
|
+
configurable: false,
|
|
555
|
+
enumerable: false
|
|
556
|
+
}), _defineProperty(_Object$definePropert, "getBlocks", {
|
|
557
|
+
value: function value() {
|
|
558
|
+
return this[BLOCKS];
|
|
559
|
+
},
|
|
560
|
+
writable: false,
|
|
561
|
+
configurable: false,
|
|
562
|
+
enumerable: false
|
|
563
|
+
}), _defineProperty(_Object$definePropert, "setExtend", {
|
|
564
|
+
value: function value(_value) {
|
|
565
|
+
this[EXTEND] = _value;
|
|
566
|
+
},
|
|
567
|
+
writable: false,
|
|
568
|
+
configurable: false,
|
|
569
|
+
enumerable: false
|
|
570
|
+
}), _defineProperty(_Object$definePropert, "getExtend", {
|
|
571
|
+
value: function value() {
|
|
572
|
+
return this[EXTEND];
|
|
573
|
+
},
|
|
574
|
+
writable: false,
|
|
575
|
+
configurable: false,
|
|
576
|
+
enumerable: false
|
|
577
|
+
}), _defineProperty(_Object$definePropert, "setLayout", {
|
|
578
|
+
value: function value(layout) {
|
|
579
|
+
this[LAYOUT] = layout;
|
|
580
|
+
},
|
|
581
|
+
writable: false,
|
|
582
|
+
configurable: false,
|
|
583
|
+
enumerable: false
|
|
584
|
+
}), _defineProperty(_Object$definePropert, "getLayout", {
|
|
585
|
+
value: function value() {
|
|
586
|
+
return this[LAYOUT];
|
|
587
|
+
},
|
|
588
|
+
writable: false,
|
|
589
|
+
configurable: false,
|
|
590
|
+
enumerable: false
|
|
591
|
+
}), _defineProperty(_Object$definePropert, "clone", {
|
|
592
|
+
value: function value(exclude_blocks) {
|
|
593
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
594
|
+
if (exclude_blocks === true) {
|
|
595
|
+
filter.push(BLOCKS);
|
|
537
596
|
}
|
|
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
|
-
|
|
597
|
+
return omit(this, filter);
|
|
598
|
+
},
|
|
599
|
+
writable: false,
|
|
600
|
+
configurable: false,
|
|
601
|
+
enumerable: false
|
|
602
|
+
}), _defineProperty(_Object$definePropert, "extend", {
|
|
603
|
+
value: function value(layout) {
|
|
604
|
+
this.setExtend(true);
|
|
605
|
+
this.setLayout(layout);
|
|
606
|
+
},
|
|
607
|
+
writable: false,
|
|
608
|
+
configurable: false,
|
|
609
|
+
enumerable: false
|
|
610
|
+
}), _defineProperty(_Object$definePropert, "echo", {
|
|
611
|
+
value: function value(layout) {
|
|
612
|
+
var buffer = this.getBuffer();
|
|
613
|
+
var params = [].slice.call(arguments);
|
|
614
|
+
params.forEach(buffer);
|
|
615
|
+
},
|
|
616
|
+
writable: false,
|
|
617
|
+
configurable: false,
|
|
618
|
+
enumerable: false
|
|
619
|
+
}), _defineProperty(_Object$definePropert, "fn", {
|
|
620
|
+
value: function value(callback) {
|
|
621
|
+
var buffer = this.getBuffer();
|
|
622
|
+
var context = this;
|
|
623
|
+
return function () {
|
|
624
|
+
buffer.backup();
|
|
625
|
+
if (isFunction(callback)) {
|
|
626
|
+
callback.apply(context, arguments);
|
|
627
|
+
}
|
|
628
|
+
return buffer.restore();
|
|
629
|
+
};
|
|
630
|
+
},
|
|
631
|
+
writable: false,
|
|
632
|
+
configurable: false,
|
|
633
|
+
enumerable: false
|
|
634
|
+
}), _defineProperty(_Object$definePropert, "get", {
|
|
635
|
+
value: function value(name, defaults) {
|
|
636
|
+
var path = getPath(this, name, true);
|
|
637
|
+
var result = path.shift();
|
|
638
|
+
var prop = path.pop();
|
|
639
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
640
|
+
},
|
|
641
|
+
writable: false,
|
|
642
|
+
configurable: false,
|
|
643
|
+
enumerable: false
|
|
644
|
+
}), _defineProperty(_Object$definePropert, "set", {
|
|
645
|
+
value: function value(name, _value2) {
|
|
646
|
+
var path = getPath(this, name, false);
|
|
647
|
+
var result = path.shift();
|
|
648
|
+
var prop = path.pop();
|
|
649
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
650
|
+
return result[prop];
|
|
590
651
|
}
|
|
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) {
|
|
652
|
+
return result[prop] = _value2;
|
|
653
|
+
},
|
|
654
|
+
writable: false,
|
|
655
|
+
configurable: false,
|
|
656
|
+
enumerable: false
|
|
657
|
+
}), _defineProperty(_Object$definePropert, "macro", {
|
|
658
|
+
value: function value(name, callback) {
|
|
603
659
|
var list = this.getMacro();
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
})
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
660
|
+
var macro = this.fn(callback);
|
|
661
|
+
var context = this;
|
|
662
|
+
list[name] = function () {
|
|
663
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
664
|
+
};
|
|
665
|
+
},
|
|
666
|
+
writable: false,
|
|
667
|
+
configurable: false,
|
|
668
|
+
enumerable: false
|
|
669
|
+
}), _defineProperty(_Object$definePropert, "call", {
|
|
670
|
+
value: function value(name) {
|
|
671
|
+
var list = this.getMacro();
|
|
672
|
+
var macro = list[name];
|
|
673
|
+
var params = [].slice.call(arguments, 1);
|
|
674
|
+
if (isFunction(macro)) {
|
|
675
|
+
return macro.apply(macro, params);
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
writable: false,
|
|
679
|
+
configurable: false,
|
|
680
|
+
enumerable: false
|
|
681
|
+
}), _defineProperty(_Object$definePropert, "block", {
|
|
682
|
+
value: function value(name, callback) {
|
|
683
|
+
var _this = this;
|
|
684
|
+
var blocks = this.getBlocks();
|
|
685
|
+
blocks[name] = blocks[name] || [];
|
|
686
|
+
blocks[name].push(this.fn(callback));
|
|
687
|
+
if (this.getExtend()) return;
|
|
688
|
+
var list = Object.assign([], blocks[name]);
|
|
689
|
+
var current = function current() {
|
|
690
|
+
return list.shift();
|
|
691
|
+
};
|
|
692
|
+
var next = function next() {
|
|
693
|
+
var parent = current();
|
|
694
|
+
if (parent) {
|
|
695
|
+
return function () {
|
|
696
|
+
_this.echo(parent(next()));
|
|
697
|
+
};
|
|
698
|
+
} else {
|
|
699
|
+
return noop;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
this.echo(current()(next()));
|
|
703
|
+
},
|
|
704
|
+
writable: false,
|
|
705
|
+
configurable: false,
|
|
706
|
+
enumerable: false
|
|
707
|
+
}), _defineProperty(_Object$definePropert, "include", {
|
|
708
|
+
value: function value(path, data, cx) {
|
|
709
|
+
var context = cx === false ? {} : this.clone(true);
|
|
710
|
+
var params = extend(context, data || {});
|
|
711
|
+
var promise = this.render(path, params);
|
|
712
|
+
this.echo(promise);
|
|
713
|
+
},
|
|
714
|
+
writable: false,
|
|
715
|
+
configurable: false,
|
|
716
|
+
enumerable: false
|
|
717
|
+
}), _defineProperty(_Object$definePropert, "use", {
|
|
718
|
+
value: function value(path, namespace) {
|
|
719
|
+
var promise = this.require(path);
|
|
720
|
+
this.echo(resolve$1(promise, function (exports) {
|
|
721
|
+
var list = this.getMacro();
|
|
722
|
+
each(exports, function (macro, name) {
|
|
723
|
+
list[[namespace, name].join('.')] = macro;
|
|
724
|
+
});
|
|
725
|
+
}, this));
|
|
726
|
+
},
|
|
727
|
+
writable: false,
|
|
728
|
+
configurable: false,
|
|
729
|
+
enumerable: false
|
|
730
|
+
}), _defineProperty(_Object$definePropert, "async", {
|
|
731
|
+
value: function value(promise, callback) {
|
|
732
|
+
this.echo(resolve$1(promise, function (data) {
|
|
733
|
+
return this.fn(callback)(data);
|
|
734
|
+
}, this));
|
|
735
|
+
},
|
|
736
|
+
writable: false,
|
|
737
|
+
configurable: false,
|
|
738
|
+
enumerable: false
|
|
739
|
+
}), _defineProperty(_Object$definePropert, "each", {
|
|
740
|
+
value: function value(object, callback) {
|
|
741
|
+
if (isString(object)) {
|
|
742
|
+
object = this.get(object, []);
|
|
743
|
+
}
|
|
744
|
+
each(object, callback);
|
|
745
|
+
},
|
|
746
|
+
writable: false,
|
|
747
|
+
configurable: false,
|
|
748
|
+
enumerable: false
|
|
749
|
+
}), _defineProperty(_Object$definePropert, "element", {
|
|
750
|
+
value: function value(tag, attr, content) {
|
|
622
751
|
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
752
|
}
|
|
629
|
-
|
|
630
|
-
|
|
753
|
+
}), _defineProperty(_Object$definePropert, "el", {
|
|
754
|
+
value: function value(tag, attr, content) {
|
|
755
|
+
if (isFunction(content)) {
|
|
756
|
+
content = this.fn(content)();
|
|
757
|
+
}
|
|
758
|
+
this.echo(resolve$1(content, function (content) {
|
|
759
|
+
return this.element(tag, attr, content);
|
|
760
|
+
}, this));
|
|
761
|
+
},
|
|
762
|
+
writable: false,
|
|
763
|
+
configurable: false,
|
|
764
|
+
enumerable: false
|
|
765
|
+
}), _Object$definePropert));
|
|
631
766
|
};
|
|
632
767
|
this.configure(config);
|
|
633
768
|
}
|
|
@@ -679,7 +814,7 @@ function EJS(options) {
|
|
|
679
814
|
return render(name, data);
|
|
680
815
|
};
|
|
681
816
|
this.helpers = function (methods) {
|
|
682
|
-
context.helpers(
|
|
817
|
+
context.helpers(extend(scope, methods));
|
|
683
818
|
};
|
|
684
819
|
this.preload = function (list) {
|
|
685
820
|
return cache.load(list || {});
|
|
@@ -697,6 +832,7 @@ function EJS(options) {
|
|
|
697
832
|
require: require,
|
|
698
833
|
render: render
|
|
699
834
|
});
|
|
835
|
+
return this;
|
|
700
836
|
}
|
|
701
837
|
|
|
702
838
|
var ejs = new EJS();
|