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