@kosatyi/ejs 0.0.98 → 0.0.100
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/cjs/browser.js +261 -345
- package/dist/cjs/index.js +261 -345
- package/dist/cjs/worker.js +261 -345
- package/dist/esm/browser.js +112 -253
- package/dist/esm/index.js +112 -253
- package/dist/esm/worker.js +112 -253
- package/dist/umd/browser.js +261 -345
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/index.js +261 -345
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +261 -345
- package/dist/umd/worker.min.js +1 -1
- package/package.json +1 -1
- package/types/ejs.d.ts +26 -26
package/dist/umd/browser.js
CHANGED
|
@@ -337,6 +337,7 @@
|
|
|
337
337
|
defaults.vars = {
|
|
338
338
|
SCOPE: 'ejs',
|
|
339
339
|
COMPONENT: 'ui',
|
|
340
|
+
ELEMENT: 'el',
|
|
340
341
|
EXTEND: '$$e',
|
|
341
342
|
BUFFER: '$$a',
|
|
342
343
|
LAYOUT: '$$l',
|
|
@@ -373,7 +374,6 @@
|
|
|
373
374
|
_classCallCheck(this, Cache);
|
|
374
375
|
_classPrivateFieldInitSpec(this, _enabled, true);
|
|
375
376
|
_classPrivateFieldInitSpec(this, _list, {});
|
|
376
|
-
bindContext(this, ['configure']);
|
|
377
377
|
this.configure(config);
|
|
378
378
|
}
|
|
379
379
|
return _createClass(Cache, [{
|
|
@@ -455,7 +455,6 @@
|
|
|
455
455
|
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
456
456
|
}
|
|
457
457
|
}]);
|
|
458
|
-
bindContext(this, ['configure', 'compile']);
|
|
459
458
|
this.configure(config);
|
|
460
459
|
}
|
|
461
460
|
return _createClass(Compiler, [{
|
|
@@ -490,7 +489,8 @@
|
|
|
490
489
|
SCOPE = _classPrivateFieldGet2$1.SCOPE,
|
|
491
490
|
SAFE = _classPrivateFieldGet2$1.SAFE,
|
|
492
491
|
BUFFER = _classPrivateFieldGet2$1.BUFFER,
|
|
493
|
-
COMPONENT = _classPrivateFieldGet2$1.COMPONENT
|
|
492
|
+
COMPONENT = _classPrivateFieldGet2$1.COMPONENT,
|
|
493
|
+
ELEMENT = _classPrivateFieldGet2$1.ELEMENT;
|
|
494
494
|
var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
|
|
495
495
|
if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
|
|
496
496
|
content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
@@ -513,7 +513,7 @@
|
|
|
513
513
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
514
514
|
source += "\n//# sourceURL=".concat(path);
|
|
515
515
|
var result = null;
|
|
516
|
-
var params = [SCOPE,
|
|
516
|
+
var params = [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT].concat(GLOBALS);
|
|
517
517
|
try {
|
|
518
518
|
result = Function.apply(null, params.concat(source));
|
|
519
519
|
result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
|
|
@@ -544,7 +544,6 @@
|
|
|
544
544
|
assertInstanceOf(compiler, Compiler);
|
|
545
545
|
_classPrivateFieldSet2(_cache$1, this, cache);
|
|
546
546
|
_classPrivateFieldSet2(_compiler$1, this, compiler);
|
|
547
|
-
bindContext(this, ['configure', 'get']);
|
|
548
547
|
this.configure(config);
|
|
549
548
|
}
|
|
550
549
|
return _createClass(Template, [{
|
|
@@ -706,17 +705,17 @@
|
|
|
706
705
|
return buffer;
|
|
707
706
|
}
|
|
708
707
|
|
|
709
|
-
var
|
|
710
|
-
var _Object$definePropert;
|
|
708
|
+
var createContextScope = function createContextScope(config, methods) {
|
|
711
709
|
var _config$vars = config.vars,
|
|
712
710
|
BLOCKS = _config$vars.BLOCKS,
|
|
713
711
|
MACRO = _config$vars.MACRO,
|
|
714
712
|
EXTEND = _config$vars.EXTEND,
|
|
715
713
|
LAYOUT = _config$vars.LAYOUT,
|
|
716
714
|
BUFFER = _config$vars.BUFFER,
|
|
717
|
-
COMPONENT = _config$vars.COMPONENT,
|
|
718
715
|
SAFE = _config$vars.SAFE,
|
|
719
|
-
SCOPE = _config$vars.SCOPE
|
|
716
|
+
SCOPE = _config$vars.SCOPE,
|
|
717
|
+
COMPONENT = _config$vars.COMPONENT,
|
|
718
|
+
ELEMENT = _config$vars.ELEMENT;
|
|
720
719
|
/**
|
|
721
720
|
* @name ContextScope
|
|
722
721
|
* @param data
|
|
@@ -725,200 +724,267 @@
|
|
|
725
724
|
function ContextScope(data) {
|
|
726
725
|
this[BLOCKS] = {};
|
|
727
726
|
this[MACRO] = {};
|
|
728
|
-
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT]));
|
|
727
|
+
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
729
728
|
}
|
|
730
729
|
Object.assign(ContextScope.prototype, methods);
|
|
731
|
-
Object.
|
|
730
|
+
Object.defineProperty(ContextScope.prototype, BUFFER, {
|
|
732
731
|
value: createBuffer()
|
|
733
|
-
})
|
|
732
|
+
});
|
|
733
|
+
Object.defineProperty(ContextScope.prototype, BLOCKS, {
|
|
734
734
|
value: {},
|
|
735
735
|
writable: true
|
|
736
|
-
})
|
|
736
|
+
});
|
|
737
|
+
Object.defineProperty(ContextScope.prototype, MACRO, {
|
|
737
738
|
value: {},
|
|
738
739
|
writable: true
|
|
739
|
-
})
|
|
740
|
+
});
|
|
741
|
+
Object.defineProperty(ContextScope.prototype, LAYOUT, {
|
|
740
742
|
value: false,
|
|
741
743
|
writable: true
|
|
742
|
-
})
|
|
744
|
+
});
|
|
745
|
+
Object.defineProperty(ContextScope.prototype, EXTEND, {
|
|
743
746
|
value: false,
|
|
744
747
|
writable: true
|
|
745
|
-
})
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
748
|
+
});
|
|
749
|
+
Object.defineProperties(ContextScope.prototype, {
|
|
750
|
+
/** @type {function} */
|
|
751
|
+
useSafeValue: {
|
|
752
|
+
get: function get() {
|
|
753
|
+
return safeValue;
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
/** @type {function} */
|
|
757
|
+
useComponent: {
|
|
758
|
+
get: function get() {
|
|
759
|
+
if (isFunction(this[COMPONENT])) {
|
|
760
|
+
return this[COMPONENT].bind(this);
|
|
761
|
+
} else {
|
|
762
|
+
return function () {
|
|
763
|
+
throw new Error("".concat(COMPONENT, " must be a function"));
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
/** @type {function} */
|
|
769
|
+
useElement: {
|
|
770
|
+
get: function get() {
|
|
771
|
+
if (isFunction(this[ELEMENT])) {
|
|
772
|
+
return this[ELEMENT].bind(this);
|
|
773
|
+
} else {
|
|
774
|
+
return function () {
|
|
775
|
+
throw new Error("".concat(ELEMENT, " must be a function"));
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
/** @type {()=>this[MACRO]} */
|
|
781
|
+
getMacro: {
|
|
782
|
+
value: function value() {
|
|
783
|
+
return this[MACRO];
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
/** @type {function} */
|
|
787
|
+
getBuffer: {
|
|
788
|
+
value: function value() {
|
|
789
|
+
return this[BUFFER];
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
/** @type {function} */
|
|
793
|
+
getBlocks: {
|
|
794
|
+
value: function value() {
|
|
795
|
+
return this[BLOCKS];
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
/** @type {function} */
|
|
799
|
+
setExtend: {
|
|
800
|
+
value: function value(_value) {
|
|
801
|
+
this[EXTEND] = _value;
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
/** @type {function} */
|
|
805
|
+
getExtend: {
|
|
806
|
+
value: function value() {
|
|
807
|
+
return this[EXTEND];
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
/** @type {function} */
|
|
811
|
+
setLayout: {
|
|
812
|
+
value: function value(layout) {
|
|
813
|
+
this[LAYOUT] = layout;
|
|
814
|
+
}
|
|
815
|
+
},
|
|
816
|
+
/** @type {function} */
|
|
817
|
+
getLayout: {
|
|
818
|
+
value: function value() {
|
|
819
|
+
return this[LAYOUT];
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
/** @type {function} */
|
|
823
|
+
clone: {
|
|
824
|
+
value: function value(exclude_blocks) {
|
|
825
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
826
|
+
if (exclude_blocks === true) {
|
|
827
|
+
filter.push(BLOCKS);
|
|
828
|
+
}
|
|
829
|
+
return omit(this, filter);
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
/** @type {function} */
|
|
833
|
+
extend: {
|
|
834
|
+
value: function value(layout) {
|
|
835
|
+
this.setExtend(true);
|
|
836
|
+
this.setLayout(layout);
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
/** @type {function} */
|
|
840
|
+
echo: {
|
|
841
|
+
value: function value(layout) {
|
|
842
|
+
var buffer = this.getBuffer();
|
|
843
|
+
var params = [].slice.call(arguments);
|
|
844
|
+
params.forEach(buffer);
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
/** @type {function} */
|
|
848
|
+
fn: {
|
|
849
|
+
value: function value(callback) {
|
|
850
|
+
var buffer = this.getBuffer();
|
|
851
|
+
var context = this;
|
|
757
852
|
return function () {
|
|
758
|
-
|
|
853
|
+
if (isFunction(callback)) {
|
|
854
|
+
buffer.backup();
|
|
855
|
+
buffer(callback.apply(context, arguments));
|
|
856
|
+
return buffer.restore();
|
|
857
|
+
}
|
|
759
858
|
};
|
|
760
859
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
this[EXTEND] = _value;
|
|
772
|
-
}
|
|
773
|
-
}), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
|
|
774
|
-
value: function value() {
|
|
775
|
-
return this[EXTEND];
|
|
776
|
-
}
|
|
777
|
-
}), "setLayout", {
|
|
778
|
-
value: function value(layout) {
|
|
779
|
-
this[LAYOUT] = layout;
|
|
780
|
-
}
|
|
781
|
-
}), "getLayout", {
|
|
782
|
-
value: function value() {
|
|
783
|
-
return this[LAYOUT];
|
|
784
|
-
}
|
|
785
|
-
}), "clone", {
|
|
786
|
-
value: function value(exclude_blocks) {
|
|
787
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
788
|
-
if (exclude_blocks === true) {
|
|
789
|
-
filter.push(BLOCKS);
|
|
860
|
+
},
|
|
861
|
+
/** @type {function} */
|
|
862
|
+
macro: {
|
|
863
|
+
value: function value(name, callback) {
|
|
864
|
+
var list = this.getMacro();
|
|
865
|
+
var macro = this.fn(callback);
|
|
866
|
+
var context = this;
|
|
867
|
+
list[name] = function () {
|
|
868
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
869
|
+
};
|
|
790
870
|
}
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
var buffer = this.getBuffer();
|
|
801
|
-
var params = [].slice.call(arguments);
|
|
802
|
-
params.forEach(buffer);
|
|
803
|
-
}
|
|
804
|
-
}), "fn", {
|
|
805
|
-
value: function value(callback) {
|
|
806
|
-
var buffer = this.getBuffer();
|
|
807
|
-
var context = this;
|
|
808
|
-
return function () {
|
|
809
|
-
buffer.backup();
|
|
810
|
-
if (isFunction(callback)) {
|
|
811
|
-
callback.apply(context, arguments);
|
|
871
|
+
},
|
|
872
|
+
/** @type {function} */
|
|
873
|
+
call: {
|
|
874
|
+
value: function value(name) {
|
|
875
|
+
var list = this.getMacro();
|
|
876
|
+
var macro = list[name];
|
|
877
|
+
var params = [].slice.call(arguments, 1);
|
|
878
|
+
if (isFunction(macro)) {
|
|
879
|
+
return macro.apply(macro, params);
|
|
812
880
|
}
|
|
813
|
-
return buffer.restore();
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
}), "get", {
|
|
817
|
-
value: function value(name, defaults) {
|
|
818
|
-
var path = getPath(this, name, true);
|
|
819
|
-
var result = path.shift();
|
|
820
|
-
var prop = path.pop();
|
|
821
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
822
|
-
}
|
|
823
|
-
}), "set", {
|
|
824
|
-
value: function value(name, _value2) {
|
|
825
|
-
var path = getPath(this, name, false);
|
|
826
|
-
var result = path.shift();
|
|
827
|
-
var prop = path.pop();
|
|
828
|
-
if (this.getExtend() && hasProp(result, prop)) {
|
|
829
|
-
return result[prop];
|
|
830
881
|
}
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
882
|
+
},
|
|
883
|
+
/** @type {function} */
|
|
884
|
+
block: {
|
|
885
|
+
value: function value(name, callback) {
|
|
886
|
+
var _this = this;
|
|
887
|
+
var blocks = this.getBlocks();
|
|
888
|
+
blocks[name] = blocks[name] || [];
|
|
889
|
+
blocks[name].push(this.fn(callback));
|
|
890
|
+
if (this.getExtend()) return;
|
|
891
|
+
var list = Object.assign([], blocks[name]);
|
|
892
|
+
var current = function current() {
|
|
893
|
+
return list.shift();
|
|
894
|
+
};
|
|
895
|
+
var _next = function next() {
|
|
896
|
+
var parent = current();
|
|
897
|
+
if (parent) {
|
|
898
|
+
return function () {
|
|
899
|
+
_this.echo(parent(_next()));
|
|
900
|
+
};
|
|
901
|
+
} else {
|
|
902
|
+
return noop;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
this.echo(current()(_next()));
|
|
849
906
|
}
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
907
|
+
},
|
|
908
|
+
/** @type {function} */
|
|
909
|
+
hasBlock: {
|
|
910
|
+
value: function value(name) {
|
|
911
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
/** @type {function} */
|
|
915
|
+
include: {
|
|
916
|
+
value: function value(path, data, cx) {
|
|
917
|
+
var context = cx === false ? {} : this.clone(true);
|
|
918
|
+
var params = extend(context, data || {});
|
|
919
|
+
var promise = this.render(path, params);
|
|
920
|
+
this.echo(promise);
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
/** @type {function} */
|
|
924
|
+
use: {
|
|
925
|
+
value: function value(path, namespace) {
|
|
926
|
+
var _this2 = this;
|
|
927
|
+
this.echo(Promise.resolve(this.require(path)).then(function (exports) {
|
|
928
|
+
var list = _this2.getMacro();
|
|
929
|
+
each(exports, function (macro, name) {
|
|
930
|
+
list[[namespace, name].join('.')] = macro;
|
|
931
|
+
});
|
|
932
|
+
}));
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
/** @type {function} */
|
|
936
|
+
async: {
|
|
937
|
+
value: function value(promise, callback) {
|
|
938
|
+
this.echo(Promise.resolve(promise).then(callback));
|
|
939
|
+
}
|
|
940
|
+
},
|
|
941
|
+
/** @type {function} */
|
|
942
|
+
get: {
|
|
943
|
+
value: function value(name, defaults) {
|
|
944
|
+
var path = getPath(this, name, true);
|
|
945
|
+
var result = path.shift();
|
|
946
|
+
var prop = path.pop();
|
|
947
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
948
|
+
}
|
|
949
|
+
},
|
|
950
|
+
/** @type {function} */
|
|
951
|
+
set: {
|
|
952
|
+
value: function value(name, _value2) {
|
|
953
|
+
var path = getPath(this, name, false);
|
|
954
|
+
var result = path.shift();
|
|
955
|
+
var prop = path.pop();
|
|
956
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
957
|
+
return result[prop];
|
|
870
958
|
}
|
|
871
|
-
|
|
872
|
-
this.echo(current()(_next()));
|
|
873
|
-
}
|
|
874
|
-
}), "hasBlock", {
|
|
875
|
-
value: function value(name) {
|
|
876
|
-
return this.getBlocks().hasOwnProperty(name);
|
|
877
|
-
}
|
|
878
|
-
}), "include", {
|
|
879
|
-
value: function value(path, data, cx) {
|
|
880
|
-
var context = cx === false ? {} : this.clone(true);
|
|
881
|
-
var params = extend(context, data || {});
|
|
882
|
-
var promise = this.render(path, params);
|
|
883
|
-
this.echo(promise);
|
|
884
|
-
}
|
|
885
|
-
}), "promiseResolve", {
|
|
886
|
-
value: function value(_value3, callback) {
|
|
887
|
-
return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
|
|
888
|
-
}
|
|
889
|
-
}), "use", {
|
|
890
|
-
value: function value(path, namespace) {
|
|
891
|
-
this.echo(this.promiseResolve(this.require(path), function (exports) {
|
|
892
|
-
var list = this.getMacro();
|
|
893
|
-
each(exports, function (macro, name) {
|
|
894
|
-
list[[namespace, name].join('.')] = macro;
|
|
895
|
-
});
|
|
896
|
-
}));
|
|
897
|
-
}
|
|
898
|
-
}), "async", {
|
|
899
|
-
value: function value(promise, callback) {
|
|
900
|
-
this.echo(this.promiseResolve(promise, function (data) {
|
|
901
|
-
return this.fn(callback)(data);
|
|
902
|
-
}));
|
|
903
|
-
}
|
|
904
|
-
}), "each", {
|
|
905
|
-
value: function value(object, callback) {
|
|
906
|
-
if (isString(object)) {
|
|
907
|
-
object = this.get(object, []);
|
|
959
|
+
return result[prop] = _value2;
|
|
908
960
|
}
|
|
909
|
-
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
961
|
+
},
|
|
962
|
+
/** @type {function} */
|
|
963
|
+
each: {
|
|
964
|
+
value: function value(object, callback) {
|
|
965
|
+
if (isString(object)) {
|
|
966
|
+
object = this.get(object, []);
|
|
967
|
+
}
|
|
968
|
+
each(object, callback);
|
|
969
|
+
},
|
|
970
|
+
writable: true
|
|
971
|
+
},
|
|
972
|
+
/** @type {function} */
|
|
973
|
+
el: {
|
|
974
|
+
value: function value(tag, attr, content) {
|
|
975
|
+
content = isFunction(content) ? this.fn(content)() : content;
|
|
976
|
+
this.echo(Promise.resolve(content).then(function (content) {
|
|
977
|
+
return element(tag, attr, content);
|
|
978
|
+
}));
|
|
979
|
+
},
|
|
980
|
+
writable: true
|
|
981
|
+
},
|
|
982
|
+
/** @type {function} */
|
|
983
|
+
ui: {
|
|
984
|
+
value: function value(layout) {},
|
|
985
|
+
writable: true
|
|
920
986
|
}
|
|
921
|
-
})
|
|
987
|
+
});
|
|
922
988
|
return ContextScope;
|
|
923
989
|
};
|
|
924
990
|
var _scope = /*#__PURE__*/new WeakMap();
|
|
@@ -926,7 +992,6 @@
|
|
|
926
992
|
function Context(config, methods) {
|
|
927
993
|
_classCallCheck(this, Context);
|
|
928
994
|
_classPrivateFieldInitSpec(this, _scope, void 0);
|
|
929
|
-
bindContext(this, ['create', 'helpers', 'configure']);
|
|
930
995
|
this.configure(config, methods);
|
|
931
996
|
}
|
|
932
997
|
return _createClass(Context, [{
|
|
@@ -937,7 +1002,7 @@
|
|
|
937
1002
|
}, {
|
|
938
1003
|
key: "configure",
|
|
939
1004
|
value: function configure(config, methods) {
|
|
940
|
-
_classPrivateFieldSet2(_scope, this,
|
|
1005
|
+
_classPrivateFieldSet2(_scope, this, createContextScope(config, methods));
|
|
941
1006
|
}
|
|
942
1007
|
}, {
|
|
943
1008
|
key: "helpers",
|
|
@@ -970,10 +1035,10 @@
|
|
|
970
1035
|
_classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
|
|
971
1036
|
_classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
|
|
972
1037
|
//
|
|
973
|
-
bindContext(this, ['configure', 'create', 'render', 'context', 'preload', 'compile', 'helpers']);
|
|
1038
|
+
bindContext(this, ['configure', 'create', 'render', 'require', 'context', 'preload', 'compile', 'helpers']);
|
|
974
1039
|
//
|
|
975
1040
|
this.helpers({
|
|
976
|
-
require:
|
|
1041
|
+
require: this.require,
|
|
977
1042
|
render: this.render
|
|
978
1043
|
});
|
|
979
1044
|
}
|
|
@@ -1028,163 +1093,21 @@
|
|
|
1028
1093
|
value: function create(options) {
|
|
1029
1094
|
return new this.constructor(options);
|
|
1030
1095
|
}
|
|
1096
|
+
}, {
|
|
1097
|
+
key: "require",
|
|
1098
|
+
value: function require(name) {
|
|
1099
|
+
var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
|
|
1100
|
+
var scope = this.context({});
|
|
1101
|
+
return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
|
|
1102
|
+
return scope.getMacro();
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1031
1105
|
}]);
|
|
1032
1106
|
}();
|
|
1033
|
-
|
|
1034
|
-
// export function EJS2(options) {
|
|
1035
|
-
// const self = {
|
|
1036
|
-
// config: {},
|
|
1037
|
-
// helpers: {},
|
|
1038
|
-
// /**
|
|
1039
|
-
// * @type {Context}
|
|
1040
|
-
// */
|
|
1041
|
-
// context: null,
|
|
1042
|
-
// /**
|
|
1043
|
-
// * @type {Compiler}
|
|
1044
|
-
// */
|
|
1045
|
-
// compiler: null,
|
|
1046
|
-
// /**
|
|
1047
|
-
// * @type {Template}
|
|
1048
|
-
// */
|
|
1049
|
-
// template: null,
|
|
1050
|
-
// /**
|
|
1051
|
-
// * @type {Cache}
|
|
1052
|
-
// */
|
|
1053
|
-
// cache: null,
|
|
1054
|
-
// }
|
|
1055
|
-
// /**
|
|
1056
|
-
// *
|
|
1057
|
-
// */
|
|
1058
|
-
// configSchema(self.config, options || {})
|
|
1059
|
-
// self.context = useContext(self.config, self.helpers)
|
|
1060
|
-
// self.compiler = useCompiler(self.config)
|
|
1061
|
-
// self.cache = useCache(self.config)
|
|
1062
|
-
// self.template = useTemplate(self.config, self.cache, self.compiler)
|
|
1063
|
-
// /**
|
|
1064
|
-
// *
|
|
1065
|
-
// * @param {string} path
|
|
1066
|
-
// * @param {ContextScope} scope
|
|
1067
|
-
// * @return {Promise<string>}
|
|
1068
|
-
// */
|
|
1069
|
-
// const output = (path, scope) => {
|
|
1070
|
-
// const { globalHelpers } = self.config
|
|
1071
|
-
// const params = [
|
|
1072
|
-
// scope,
|
|
1073
|
-
// scope.getComponent(),
|
|
1074
|
-
// scope.getBuffer(),
|
|
1075
|
-
// safeValue,
|
|
1076
|
-
// ].concat(
|
|
1077
|
-
// globalHelpers
|
|
1078
|
-
// .filter((name) => isFunction(scope[name]))
|
|
1079
|
-
// .map((name) => scope[name].bind(scope))
|
|
1080
|
-
// )
|
|
1081
|
-
// return self.template
|
|
1082
|
-
// .get(path)
|
|
1083
|
-
// .then((callback) => callback.apply(scope, params))
|
|
1084
|
-
// }
|
|
1085
|
-
// /**
|
|
1086
|
-
// *
|
|
1087
|
-
// * @param name
|
|
1088
|
-
// * @return {Promise<string>}
|
|
1089
|
-
// */
|
|
1090
|
-
// const require = (name) => {
|
|
1091
|
-
// const filepath = ext(name, self.config.extension)
|
|
1092
|
-
// const scope = context({})
|
|
1093
|
-
// return output(filepath, scope).then(() => scope.getMacro())
|
|
1094
|
-
// }
|
|
1095
|
-
// /**
|
|
1096
|
-
// *
|
|
1097
|
-
// * @param {string} name
|
|
1098
|
-
// * @param {{}} [data]
|
|
1099
|
-
// * @return {Promise<string>}
|
|
1100
|
-
// */
|
|
1101
|
-
// const render = (name, data) => {
|
|
1102
|
-
// const filepath = ext(name, self.config.extension)
|
|
1103
|
-
// const scope = context(data)
|
|
1104
|
-
// return output(filepath, scope).then((content) => {
|
|
1105
|
-
// if (scope.getExtend()) {
|
|
1106
|
-
// scope.setExtend(false)
|
|
1107
|
-
// const layout = scope.getLayout()
|
|
1108
|
-
// const data = scope.clone()
|
|
1109
|
-
// return render(layout, data)
|
|
1110
|
-
// }
|
|
1111
|
-
// return content
|
|
1112
|
-
// })
|
|
1113
|
-
// }
|
|
1114
|
-
// /**
|
|
1115
|
-
// *
|
|
1116
|
-
// * @param options
|
|
1117
|
-
// * @return {{}}
|
|
1118
|
-
// */
|
|
1119
|
-
// const configure = (options = {}) => {
|
|
1120
|
-
// configSchema(self.config, options || {})
|
|
1121
|
-
// self.context.configure(self.config, self.helpers)
|
|
1122
|
-
// self.compiler.configure(self.config)
|
|
1123
|
-
// self.cache.configure(self.config)
|
|
1124
|
-
// self.template.configure(self.config)
|
|
1125
|
-
// return self.config
|
|
1126
|
-
// }
|
|
1127
|
-
// /**
|
|
1128
|
-
// *
|
|
1129
|
-
// * @param methods
|
|
1130
|
-
// */
|
|
1131
|
-
// const helpers = (methods) => {
|
|
1132
|
-
// self.context.helpers(extend(self.helpers, methods))
|
|
1133
|
-
// }
|
|
1134
|
-
// /**
|
|
1135
|
-
// *
|
|
1136
|
-
// * @param list
|
|
1137
|
-
// * @return {*}
|
|
1138
|
-
// */
|
|
1139
|
-
// const preload = (list) => {
|
|
1140
|
-
// return self.cache.load(list || {})
|
|
1141
|
-
// }
|
|
1142
|
-
// /**
|
|
1143
|
-
// *
|
|
1144
|
-
// * @param options
|
|
1145
|
-
// * @return {any}
|
|
1146
|
-
// */
|
|
1147
|
-
// const create = (options) => {
|
|
1148
|
-
// return EJS(options)
|
|
1149
|
-
// }
|
|
1150
|
-
// /**
|
|
1151
|
-
// *
|
|
1152
|
-
// * @param content
|
|
1153
|
-
// * @param path
|
|
1154
|
-
// * @return {Function}
|
|
1155
|
-
// */
|
|
1156
|
-
// const compile = (content, path) => {
|
|
1157
|
-
// return self.compiler.compile(content, path)
|
|
1158
|
-
// }
|
|
1159
|
-
// /**
|
|
1160
|
-
// *
|
|
1161
|
-
// * @param data
|
|
1162
|
-
// * @return {ContextScope}
|
|
1163
|
-
// */
|
|
1164
|
-
// const context = (data = {}) => {
|
|
1165
|
-
// return self.context.create(data)
|
|
1166
|
-
// }
|
|
1167
|
-
// /**
|
|
1168
|
-
// *
|
|
1169
|
-
// */
|
|
1170
|
-
// helpers({ require, render })
|
|
1171
|
-
// /**
|
|
1172
|
-
// *
|
|
1173
|
-
// */
|
|
1174
|
-
// return {
|
|
1175
|
-
// configure,
|
|
1176
|
-
// helpers,
|
|
1177
|
-
// preload,
|
|
1178
|
-
// context,
|
|
1179
|
-
// compile,
|
|
1180
|
-
// create,
|
|
1181
|
-
// render,
|
|
1182
|
-
// }
|
|
1183
|
-
// }
|
|
1184
1107
|
function _output(path, scope) {
|
|
1185
1108
|
var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
|
|
1186
1109
|
globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
|
|
1187
|
-
var params = [scope, scope.
|
|
1110
|
+
var params = [scope, scope.getBuffer(), scope.useSafeValue, scope.useComponent, scope.useElement].concat(globalHelpers.filter(function (name) {
|
|
1188
1111
|
return isFunction(scope[name]);
|
|
1189
1112
|
}).map(function (name) {
|
|
1190
1113
|
return scope[name].bind(scope);
|
|
@@ -1193,13 +1116,6 @@
|
|
|
1193
1116
|
return callback.apply(scope, params);
|
|
1194
1117
|
});
|
|
1195
1118
|
}
|
|
1196
|
-
function _require(name) {
|
|
1197
|
-
var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
|
|
1198
|
-
var scope = this.context({});
|
|
1199
|
-
return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
|
|
1200
|
-
return scope.getMacro();
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
1119
|
|
|
1204
1120
|
var httpRequest = function httpRequest(path, template) {
|
|
1205
1121
|
return fetch(joinPath(path, template)).then(function (response) {
|