@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/worker.js
CHANGED
|
@@ -658,6 +658,7 @@
|
|
|
658
658
|
defaults.vars = {
|
|
659
659
|
SCOPE: 'ejs',
|
|
660
660
|
COMPONENT: 'ui',
|
|
661
|
+
ELEMENT: 'el',
|
|
661
662
|
EXTEND: '$$e',
|
|
662
663
|
BUFFER: '$$a',
|
|
663
664
|
LAYOUT: '$$l',
|
|
@@ -694,7 +695,6 @@
|
|
|
694
695
|
_classCallCheck(this, Cache);
|
|
695
696
|
_classPrivateFieldInitSpec(this, _enabled, true);
|
|
696
697
|
_classPrivateFieldInitSpec(this, _list, {});
|
|
697
|
-
bindContext(this, ['configure']);
|
|
698
698
|
this.configure(config);
|
|
699
699
|
}
|
|
700
700
|
return _createClass(Cache, [{
|
|
@@ -776,7 +776,6 @@
|
|
|
776
776
|
return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
|
|
777
777
|
}
|
|
778
778
|
}]);
|
|
779
|
-
bindContext(this, ['configure', 'compile']);
|
|
780
779
|
this.configure(config);
|
|
781
780
|
}
|
|
782
781
|
return _createClass(Compiler, [{
|
|
@@ -811,7 +810,8 @@
|
|
|
811
810
|
SCOPE = _classPrivateFieldGet2$1.SCOPE,
|
|
812
811
|
SAFE = _classPrivateFieldGet2$1.SAFE,
|
|
813
812
|
BUFFER = _classPrivateFieldGet2$1.BUFFER,
|
|
814
|
-
COMPONENT = _classPrivateFieldGet2$1.COMPONENT
|
|
813
|
+
COMPONENT = _classPrivateFieldGet2$1.COMPONENT,
|
|
814
|
+
ELEMENT = _classPrivateFieldGet2$1.ELEMENT;
|
|
815
815
|
var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
|
|
816
816
|
if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
|
|
817
817
|
content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
|
@@ -834,7 +834,7 @@
|
|
|
834
834
|
source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
|
|
835
835
|
source += "\n//# sourceURL=".concat(path);
|
|
836
836
|
var result = null;
|
|
837
|
-
var params = [SCOPE,
|
|
837
|
+
var params = [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT].concat(GLOBALS);
|
|
838
838
|
try {
|
|
839
839
|
result = Function.apply(null, params.concat(source));
|
|
840
840
|
result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
|
|
@@ -865,7 +865,6 @@
|
|
|
865
865
|
assertInstanceOf(compiler, Compiler);
|
|
866
866
|
_classPrivateFieldSet2(_cache$1, this, cache);
|
|
867
867
|
_classPrivateFieldSet2(_compiler$1, this, compiler);
|
|
868
|
-
bindContext(this, ['configure', 'get']);
|
|
869
868
|
this.configure(config);
|
|
870
869
|
}
|
|
871
870
|
return _createClass(Template, [{
|
|
@@ -1027,17 +1026,17 @@
|
|
|
1027
1026
|
return buffer;
|
|
1028
1027
|
}
|
|
1029
1028
|
|
|
1030
|
-
var
|
|
1031
|
-
var _Object$definePropert;
|
|
1029
|
+
var createContextScope = function createContextScope(config, methods) {
|
|
1032
1030
|
var _config$vars = config.vars,
|
|
1033
1031
|
BLOCKS = _config$vars.BLOCKS,
|
|
1034
1032
|
MACRO = _config$vars.MACRO,
|
|
1035
1033
|
EXTEND = _config$vars.EXTEND,
|
|
1036
1034
|
LAYOUT = _config$vars.LAYOUT,
|
|
1037
1035
|
BUFFER = _config$vars.BUFFER,
|
|
1038
|
-
COMPONENT = _config$vars.COMPONENT,
|
|
1039
1036
|
SAFE = _config$vars.SAFE,
|
|
1040
|
-
SCOPE = _config$vars.SCOPE
|
|
1037
|
+
SCOPE = _config$vars.SCOPE,
|
|
1038
|
+
COMPONENT = _config$vars.COMPONENT,
|
|
1039
|
+
ELEMENT = _config$vars.ELEMENT;
|
|
1041
1040
|
/**
|
|
1042
1041
|
* @name ContextScope
|
|
1043
1042
|
* @param data
|
|
@@ -1046,200 +1045,267 @@
|
|
|
1046
1045
|
function ContextScope(data) {
|
|
1047
1046
|
this[BLOCKS] = {};
|
|
1048
1047
|
this[MACRO] = {};
|
|
1049
|
-
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT]));
|
|
1048
|
+
Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
|
|
1050
1049
|
}
|
|
1051
1050
|
Object.assign(ContextScope.prototype, methods);
|
|
1052
|
-
Object.
|
|
1051
|
+
Object.defineProperty(ContextScope.prototype, BUFFER, {
|
|
1053
1052
|
value: createBuffer()
|
|
1054
|
-
})
|
|
1053
|
+
});
|
|
1054
|
+
Object.defineProperty(ContextScope.prototype, BLOCKS, {
|
|
1055
1055
|
value: {},
|
|
1056
1056
|
writable: true
|
|
1057
|
-
})
|
|
1057
|
+
});
|
|
1058
|
+
Object.defineProperty(ContextScope.prototype, MACRO, {
|
|
1058
1059
|
value: {},
|
|
1059
1060
|
writable: true
|
|
1060
|
-
})
|
|
1061
|
+
});
|
|
1062
|
+
Object.defineProperty(ContextScope.prototype, LAYOUT, {
|
|
1061
1063
|
value: false,
|
|
1062
1064
|
writable: true
|
|
1063
|
-
})
|
|
1065
|
+
});
|
|
1066
|
+
Object.defineProperty(ContextScope.prototype, EXTEND, {
|
|
1064
1067
|
value: false,
|
|
1065
1068
|
writable: true
|
|
1066
|
-
})
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1069
|
+
});
|
|
1070
|
+
Object.defineProperties(ContextScope.prototype, {
|
|
1071
|
+
/** @type {function} */
|
|
1072
|
+
useSafeValue: {
|
|
1073
|
+
get: function get() {
|
|
1074
|
+
return safeValue;
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
/** @type {function} */
|
|
1078
|
+
useComponent: {
|
|
1079
|
+
get: function get() {
|
|
1080
|
+
if (isFunction(this[COMPONENT])) {
|
|
1081
|
+
return this[COMPONENT].bind(this);
|
|
1082
|
+
} else {
|
|
1083
|
+
return function () {
|
|
1084
|
+
throw new Error("".concat(COMPONENT, " must be a function"));
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
},
|
|
1089
|
+
/** @type {function} */
|
|
1090
|
+
useElement: {
|
|
1091
|
+
get: function get() {
|
|
1092
|
+
if (isFunction(this[ELEMENT])) {
|
|
1093
|
+
return this[ELEMENT].bind(this);
|
|
1094
|
+
} else {
|
|
1095
|
+
return function () {
|
|
1096
|
+
throw new Error("".concat(ELEMENT, " must be a function"));
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
/** @type {()=>this[MACRO]} */
|
|
1102
|
+
getMacro: {
|
|
1103
|
+
value: function value() {
|
|
1104
|
+
return this[MACRO];
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
/** @type {function} */
|
|
1108
|
+
getBuffer: {
|
|
1109
|
+
value: function value() {
|
|
1110
|
+
return this[BUFFER];
|
|
1111
|
+
}
|
|
1112
|
+
},
|
|
1113
|
+
/** @type {function} */
|
|
1114
|
+
getBlocks: {
|
|
1115
|
+
value: function value() {
|
|
1116
|
+
return this[BLOCKS];
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
/** @type {function} */
|
|
1120
|
+
setExtend: {
|
|
1121
|
+
value: function value(_value) {
|
|
1122
|
+
this[EXTEND] = _value;
|
|
1123
|
+
}
|
|
1124
|
+
},
|
|
1125
|
+
/** @type {function} */
|
|
1126
|
+
getExtend: {
|
|
1127
|
+
value: function value() {
|
|
1128
|
+
return this[EXTEND];
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
/** @type {function} */
|
|
1132
|
+
setLayout: {
|
|
1133
|
+
value: function value(layout) {
|
|
1134
|
+
this[LAYOUT] = layout;
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
/** @type {function} */
|
|
1138
|
+
getLayout: {
|
|
1139
|
+
value: function value() {
|
|
1140
|
+
return this[LAYOUT];
|
|
1141
|
+
}
|
|
1142
|
+
},
|
|
1143
|
+
/** @type {function} */
|
|
1144
|
+
clone: {
|
|
1145
|
+
value: function value(exclude_blocks) {
|
|
1146
|
+
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
1147
|
+
if (exclude_blocks === true) {
|
|
1148
|
+
filter.push(BLOCKS);
|
|
1149
|
+
}
|
|
1150
|
+
return omit(this, filter);
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
/** @type {function} */
|
|
1154
|
+
extend: {
|
|
1155
|
+
value: function value(layout) {
|
|
1156
|
+
this.setExtend(true);
|
|
1157
|
+
this.setLayout(layout);
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
/** @type {function} */
|
|
1161
|
+
echo: {
|
|
1162
|
+
value: function value(layout) {
|
|
1163
|
+
var buffer = this.getBuffer();
|
|
1164
|
+
var params = [].slice.call(arguments);
|
|
1165
|
+
params.forEach(buffer);
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
/** @type {function} */
|
|
1169
|
+
fn: {
|
|
1170
|
+
value: function value(callback) {
|
|
1171
|
+
var buffer = this.getBuffer();
|
|
1172
|
+
var context = this;
|
|
1078
1173
|
return function () {
|
|
1079
|
-
|
|
1174
|
+
if (isFunction(callback)) {
|
|
1175
|
+
buffer.backup();
|
|
1176
|
+
buffer(callback.apply(context, arguments));
|
|
1177
|
+
return buffer.restore();
|
|
1178
|
+
}
|
|
1080
1179
|
};
|
|
1081
1180
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
this[EXTEND] = _value;
|
|
1093
|
-
}
|
|
1094
|
-
}), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_Object$definePropert, "getExtend", {
|
|
1095
|
-
value: function value() {
|
|
1096
|
-
return this[EXTEND];
|
|
1097
|
-
}
|
|
1098
|
-
}), "setLayout", {
|
|
1099
|
-
value: function value(layout) {
|
|
1100
|
-
this[LAYOUT] = layout;
|
|
1101
|
-
}
|
|
1102
|
-
}), "getLayout", {
|
|
1103
|
-
value: function value() {
|
|
1104
|
-
return this[LAYOUT];
|
|
1105
|
-
}
|
|
1106
|
-
}), "clone", {
|
|
1107
|
-
value: function value(exclude_blocks) {
|
|
1108
|
-
var filter = [LAYOUT, EXTEND, BUFFER];
|
|
1109
|
-
if (exclude_blocks === true) {
|
|
1110
|
-
filter.push(BLOCKS);
|
|
1181
|
+
},
|
|
1182
|
+
/** @type {function} */
|
|
1183
|
+
macro: {
|
|
1184
|
+
value: function value(name, callback) {
|
|
1185
|
+
var list = this.getMacro();
|
|
1186
|
+
var macro = this.fn(callback);
|
|
1187
|
+
var context = this;
|
|
1188
|
+
list[name] = function () {
|
|
1189
|
+
return context.echo(macro.apply(undefined, arguments));
|
|
1190
|
+
};
|
|
1111
1191
|
}
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
var buffer = this.getBuffer();
|
|
1122
|
-
var params = [].slice.call(arguments);
|
|
1123
|
-
params.forEach(buffer);
|
|
1124
|
-
}
|
|
1125
|
-
}), "fn", {
|
|
1126
|
-
value: function value(callback) {
|
|
1127
|
-
var buffer = this.getBuffer();
|
|
1128
|
-
var context = this;
|
|
1129
|
-
return function () {
|
|
1130
|
-
buffer.backup();
|
|
1131
|
-
if (isFunction(callback)) {
|
|
1132
|
-
callback.apply(context, arguments);
|
|
1192
|
+
},
|
|
1193
|
+
/** @type {function} */
|
|
1194
|
+
call: {
|
|
1195
|
+
value: function value(name) {
|
|
1196
|
+
var list = this.getMacro();
|
|
1197
|
+
var macro = list[name];
|
|
1198
|
+
var params = [].slice.call(arguments, 1);
|
|
1199
|
+
if (isFunction(macro)) {
|
|
1200
|
+
return macro.apply(macro, params);
|
|
1133
1201
|
}
|
|
1134
|
-
return buffer.restore();
|
|
1135
|
-
};
|
|
1136
|
-
}
|
|
1137
|
-
}), "get", {
|
|
1138
|
-
value: function value(name, defaults) {
|
|
1139
|
-
var path = getPath(this, name, true);
|
|
1140
|
-
var result = path.shift();
|
|
1141
|
-
var prop = path.pop();
|
|
1142
|
-
return hasProp(result, prop) ? result[prop] : defaults;
|
|
1143
|
-
}
|
|
1144
|
-
}), "set", {
|
|
1145
|
-
value: function value(name, _value2) {
|
|
1146
|
-
var path = getPath(this, name, false);
|
|
1147
|
-
var result = path.shift();
|
|
1148
|
-
var prop = path.pop();
|
|
1149
|
-
if (this.getExtend() && hasProp(result, prop)) {
|
|
1150
|
-
return result[prop];
|
|
1151
1202
|
}
|
|
1152
|
-
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1203
|
+
},
|
|
1204
|
+
/** @type {function} */
|
|
1205
|
+
block: {
|
|
1206
|
+
value: function value(name, callback) {
|
|
1207
|
+
var _this = this;
|
|
1208
|
+
var blocks = this.getBlocks();
|
|
1209
|
+
blocks[name] = blocks[name] || [];
|
|
1210
|
+
blocks[name].push(this.fn(callback));
|
|
1211
|
+
if (this.getExtend()) return;
|
|
1212
|
+
var list = Object.assign([], blocks[name]);
|
|
1213
|
+
var current = function current() {
|
|
1214
|
+
return list.shift();
|
|
1215
|
+
};
|
|
1216
|
+
var _next = function next() {
|
|
1217
|
+
var parent = current();
|
|
1218
|
+
if (parent) {
|
|
1219
|
+
return function () {
|
|
1220
|
+
_this.echo(parent(_next()));
|
|
1221
|
+
};
|
|
1222
|
+
} else {
|
|
1223
|
+
return noop;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
this.echo(current()(_next()));
|
|
1170
1227
|
}
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1228
|
+
},
|
|
1229
|
+
/** @type {function} */
|
|
1230
|
+
hasBlock: {
|
|
1231
|
+
value: function value(name) {
|
|
1232
|
+
return this.getBlocks().hasOwnProperty(name);
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
/** @type {function} */
|
|
1236
|
+
include: {
|
|
1237
|
+
value: function value(path, data, cx) {
|
|
1238
|
+
var context = cx === false ? {} : this.clone(true);
|
|
1239
|
+
var params = extend(context, data || {});
|
|
1240
|
+
var promise = this.render(path, params);
|
|
1241
|
+
this.echo(promise);
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
/** @type {function} */
|
|
1245
|
+
use: {
|
|
1246
|
+
value: function value(path, namespace) {
|
|
1247
|
+
var _this2 = this;
|
|
1248
|
+
this.echo(Promise.resolve(this.require(path)).then(function (exports) {
|
|
1249
|
+
var list = _this2.getMacro();
|
|
1250
|
+
each(exports, function (macro, name) {
|
|
1251
|
+
list[[namespace, name].join('.')] = macro;
|
|
1252
|
+
});
|
|
1253
|
+
}));
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
/** @type {function} */
|
|
1257
|
+
async: {
|
|
1258
|
+
value: function value(promise, callback) {
|
|
1259
|
+
this.echo(Promise.resolve(promise).then(callback));
|
|
1260
|
+
}
|
|
1261
|
+
},
|
|
1262
|
+
/** @type {function} */
|
|
1263
|
+
get: {
|
|
1264
|
+
value: function value(name, defaults) {
|
|
1265
|
+
var path = getPath(this, name, true);
|
|
1266
|
+
var result = path.shift();
|
|
1267
|
+
var prop = path.pop();
|
|
1268
|
+
return hasProp(result, prop) ? result[prop] : defaults;
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
/** @type {function} */
|
|
1272
|
+
set: {
|
|
1273
|
+
value: function value(name, _value2) {
|
|
1274
|
+
var path = getPath(this, name, false);
|
|
1275
|
+
var result = path.shift();
|
|
1276
|
+
var prop = path.pop();
|
|
1277
|
+
if (this.getExtend() && hasProp(result, prop)) {
|
|
1278
|
+
return result[prop];
|
|
1191
1279
|
}
|
|
1192
|
-
|
|
1193
|
-
this.echo(current()(_next()));
|
|
1194
|
-
}
|
|
1195
|
-
}), "hasBlock", {
|
|
1196
|
-
value: function value(name) {
|
|
1197
|
-
return this.getBlocks().hasOwnProperty(name);
|
|
1198
|
-
}
|
|
1199
|
-
}), "include", {
|
|
1200
|
-
value: function value(path, data, cx) {
|
|
1201
|
-
var context = cx === false ? {} : this.clone(true);
|
|
1202
|
-
var params = extend(context, data || {});
|
|
1203
|
-
var promise = this.render(path, params);
|
|
1204
|
-
this.echo(promise);
|
|
1205
|
-
}
|
|
1206
|
-
}), "promiseResolve", {
|
|
1207
|
-
value: function value(_value3, callback) {
|
|
1208
|
-
return Promise.resolve(isFunction(_value3) ? this.fn(_value3)() : _value3).then(callback.bind(this));
|
|
1209
|
-
}
|
|
1210
|
-
}), "use", {
|
|
1211
|
-
value: function value(path, namespace) {
|
|
1212
|
-
this.echo(this.promiseResolve(this.require(path), function (exports) {
|
|
1213
|
-
var list = this.getMacro();
|
|
1214
|
-
each(exports, function (macro, name) {
|
|
1215
|
-
list[[namespace, name].join('.')] = macro;
|
|
1216
|
-
});
|
|
1217
|
-
}));
|
|
1218
|
-
}
|
|
1219
|
-
}), "async", {
|
|
1220
|
-
value: function value(promise, callback) {
|
|
1221
|
-
this.echo(this.promiseResolve(promise, function (data) {
|
|
1222
|
-
return this.fn(callback)(data);
|
|
1223
|
-
}));
|
|
1224
|
-
}
|
|
1225
|
-
}), "each", {
|
|
1226
|
-
value: function value(object, callback) {
|
|
1227
|
-
if (isString(object)) {
|
|
1228
|
-
object = this.get(object, []);
|
|
1280
|
+
return result[prop] = _value2;
|
|
1229
1281
|
}
|
|
1230
|
-
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1282
|
+
},
|
|
1283
|
+
/** @type {function} */
|
|
1284
|
+
each: {
|
|
1285
|
+
value: function value(object, callback) {
|
|
1286
|
+
if (isString(object)) {
|
|
1287
|
+
object = this.get(object, []);
|
|
1288
|
+
}
|
|
1289
|
+
each(object, callback);
|
|
1290
|
+
},
|
|
1291
|
+
writable: true
|
|
1292
|
+
},
|
|
1293
|
+
/** @type {function} */
|
|
1294
|
+
el: {
|
|
1295
|
+
value: function value(tag, attr, content) {
|
|
1296
|
+
content = isFunction(content) ? this.fn(content)() : content;
|
|
1297
|
+
this.echo(Promise.resolve(content).then(function (content) {
|
|
1298
|
+
return element(tag, attr, content);
|
|
1299
|
+
}));
|
|
1300
|
+
},
|
|
1301
|
+
writable: true
|
|
1302
|
+
},
|
|
1303
|
+
/** @type {function} */
|
|
1304
|
+
ui: {
|
|
1305
|
+
value: function value(layout) {},
|
|
1306
|
+
writable: true
|
|
1241
1307
|
}
|
|
1242
|
-
})
|
|
1308
|
+
});
|
|
1243
1309
|
return ContextScope;
|
|
1244
1310
|
};
|
|
1245
1311
|
var _scope = /*#__PURE__*/new WeakMap();
|
|
@@ -1247,7 +1313,6 @@
|
|
|
1247
1313
|
function Context(config, methods) {
|
|
1248
1314
|
_classCallCheck(this, Context);
|
|
1249
1315
|
_classPrivateFieldInitSpec(this, _scope, void 0);
|
|
1250
|
-
bindContext(this, ['create', 'helpers', 'configure']);
|
|
1251
1316
|
this.configure(config, methods);
|
|
1252
1317
|
}
|
|
1253
1318
|
return _createClass(Context, [{
|
|
@@ -1258,7 +1323,7 @@
|
|
|
1258
1323
|
}, {
|
|
1259
1324
|
key: "configure",
|
|
1260
1325
|
value: function configure(config, methods) {
|
|
1261
|
-
_classPrivateFieldSet2(_scope, this,
|
|
1326
|
+
_classPrivateFieldSet2(_scope, this, createContextScope(config, methods));
|
|
1262
1327
|
}
|
|
1263
1328
|
}, {
|
|
1264
1329
|
key: "helpers",
|
|
@@ -1291,10 +1356,10 @@
|
|
|
1291
1356
|
_classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
|
|
1292
1357
|
_classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
|
|
1293
1358
|
//
|
|
1294
|
-
bindContext(this, ['configure', 'create', 'render', 'context', 'preload', 'compile', 'helpers']);
|
|
1359
|
+
bindContext(this, ['configure', 'create', 'render', 'require', 'context', 'preload', 'compile', 'helpers']);
|
|
1295
1360
|
//
|
|
1296
1361
|
this.helpers({
|
|
1297
|
-
require:
|
|
1362
|
+
require: this.require,
|
|
1298
1363
|
render: this.render
|
|
1299
1364
|
});
|
|
1300
1365
|
}
|
|
@@ -1349,163 +1414,21 @@
|
|
|
1349
1414
|
value: function create(options) {
|
|
1350
1415
|
return new this.constructor(options);
|
|
1351
1416
|
}
|
|
1417
|
+
}, {
|
|
1418
|
+
key: "require",
|
|
1419
|
+
value: function require(name) {
|
|
1420
|
+
var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
|
|
1421
|
+
var scope = this.context({});
|
|
1422
|
+
return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
|
|
1423
|
+
return scope.getMacro();
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1352
1426
|
}]);
|
|
1353
1427
|
}();
|
|
1354
|
-
|
|
1355
|
-
// export function EJS2(options) {
|
|
1356
|
-
// const self = {
|
|
1357
|
-
// config: {},
|
|
1358
|
-
// helpers: {},
|
|
1359
|
-
// /**
|
|
1360
|
-
// * @type {Context}
|
|
1361
|
-
// */
|
|
1362
|
-
// context: null,
|
|
1363
|
-
// /**
|
|
1364
|
-
// * @type {Compiler}
|
|
1365
|
-
// */
|
|
1366
|
-
// compiler: null,
|
|
1367
|
-
// /**
|
|
1368
|
-
// * @type {Template}
|
|
1369
|
-
// */
|
|
1370
|
-
// template: null,
|
|
1371
|
-
// /**
|
|
1372
|
-
// * @type {Cache}
|
|
1373
|
-
// */
|
|
1374
|
-
// cache: null,
|
|
1375
|
-
// }
|
|
1376
|
-
// /**
|
|
1377
|
-
// *
|
|
1378
|
-
// */
|
|
1379
|
-
// configSchema(self.config, options || {})
|
|
1380
|
-
// self.context = useContext(self.config, self.helpers)
|
|
1381
|
-
// self.compiler = useCompiler(self.config)
|
|
1382
|
-
// self.cache = useCache(self.config)
|
|
1383
|
-
// self.template = useTemplate(self.config, self.cache, self.compiler)
|
|
1384
|
-
// /**
|
|
1385
|
-
// *
|
|
1386
|
-
// * @param {string} path
|
|
1387
|
-
// * @param {ContextScope} scope
|
|
1388
|
-
// * @return {Promise<string>}
|
|
1389
|
-
// */
|
|
1390
|
-
// const output = (path, scope) => {
|
|
1391
|
-
// const { globalHelpers } = self.config
|
|
1392
|
-
// const params = [
|
|
1393
|
-
// scope,
|
|
1394
|
-
// scope.getComponent(),
|
|
1395
|
-
// scope.getBuffer(),
|
|
1396
|
-
// safeValue,
|
|
1397
|
-
// ].concat(
|
|
1398
|
-
// globalHelpers
|
|
1399
|
-
// .filter((name) => isFunction(scope[name]))
|
|
1400
|
-
// .map((name) => scope[name].bind(scope))
|
|
1401
|
-
// )
|
|
1402
|
-
// return self.template
|
|
1403
|
-
// .get(path)
|
|
1404
|
-
// .then((callback) => callback.apply(scope, params))
|
|
1405
|
-
// }
|
|
1406
|
-
// /**
|
|
1407
|
-
// *
|
|
1408
|
-
// * @param name
|
|
1409
|
-
// * @return {Promise<string>}
|
|
1410
|
-
// */
|
|
1411
|
-
// const require = (name) => {
|
|
1412
|
-
// const filepath = ext(name, self.config.extension)
|
|
1413
|
-
// const scope = context({})
|
|
1414
|
-
// return output(filepath, scope).then(() => scope.getMacro())
|
|
1415
|
-
// }
|
|
1416
|
-
// /**
|
|
1417
|
-
// *
|
|
1418
|
-
// * @param {string} name
|
|
1419
|
-
// * @param {{}} [data]
|
|
1420
|
-
// * @return {Promise<string>}
|
|
1421
|
-
// */
|
|
1422
|
-
// const render = (name, data) => {
|
|
1423
|
-
// const filepath = ext(name, self.config.extension)
|
|
1424
|
-
// const scope = context(data)
|
|
1425
|
-
// return output(filepath, scope).then((content) => {
|
|
1426
|
-
// if (scope.getExtend()) {
|
|
1427
|
-
// scope.setExtend(false)
|
|
1428
|
-
// const layout = scope.getLayout()
|
|
1429
|
-
// const data = scope.clone()
|
|
1430
|
-
// return render(layout, data)
|
|
1431
|
-
// }
|
|
1432
|
-
// return content
|
|
1433
|
-
// })
|
|
1434
|
-
// }
|
|
1435
|
-
// /**
|
|
1436
|
-
// *
|
|
1437
|
-
// * @param options
|
|
1438
|
-
// * @return {{}}
|
|
1439
|
-
// */
|
|
1440
|
-
// const configure = (options = {}) => {
|
|
1441
|
-
// configSchema(self.config, options || {})
|
|
1442
|
-
// self.context.configure(self.config, self.helpers)
|
|
1443
|
-
// self.compiler.configure(self.config)
|
|
1444
|
-
// self.cache.configure(self.config)
|
|
1445
|
-
// self.template.configure(self.config)
|
|
1446
|
-
// return self.config
|
|
1447
|
-
// }
|
|
1448
|
-
// /**
|
|
1449
|
-
// *
|
|
1450
|
-
// * @param methods
|
|
1451
|
-
// */
|
|
1452
|
-
// const helpers = (methods) => {
|
|
1453
|
-
// self.context.helpers(extend(self.helpers, methods))
|
|
1454
|
-
// }
|
|
1455
|
-
// /**
|
|
1456
|
-
// *
|
|
1457
|
-
// * @param list
|
|
1458
|
-
// * @return {*}
|
|
1459
|
-
// */
|
|
1460
|
-
// const preload = (list) => {
|
|
1461
|
-
// return self.cache.load(list || {})
|
|
1462
|
-
// }
|
|
1463
|
-
// /**
|
|
1464
|
-
// *
|
|
1465
|
-
// * @param options
|
|
1466
|
-
// * @return {any}
|
|
1467
|
-
// */
|
|
1468
|
-
// const create = (options) => {
|
|
1469
|
-
// return EJS(options)
|
|
1470
|
-
// }
|
|
1471
|
-
// /**
|
|
1472
|
-
// *
|
|
1473
|
-
// * @param content
|
|
1474
|
-
// * @param path
|
|
1475
|
-
// * @return {Function}
|
|
1476
|
-
// */
|
|
1477
|
-
// const compile = (content, path) => {
|
|
1478
|
-
// return self.compiler.compile(content, path)
|
|
1479
|
-
// }
|
|
1480
|
-
// /**
|
|
1481
|
-
// *
|
|
1482
|
-
// * @param data
|
|
1483
|
-
// * @return {ContextScope}
|
|
1484
|
-
// */
|
|
1485
|
-
// const context = (data = {}) => {
|
|
1486
|
-
// return self.context.create(data)
|
|
1487
|
-
// }
|
|
1488
|
-
// /**
|
|
1489
|
-
// *
|
|
1490
|
-
// */
|
|
1491
|
-
// helpers({ require, render })
|
|
1492
|
-
// /**
|
|
1493
|
-
// *
|
|
1494
|
-
// */
|
|
1495
|
-
// return {
|
|
1496
|
-
// configure,
|
|
1497
|
-
// helpers,
|
|
1498
|
-
// preload,
|
|
1499
|
-
// context,
|
|
1500
|
-
// compile,
|
|
1501
|
-
// create,
|
|
1502
|
-
// render,
|
|
1503
|
-
// }
|
|
1504
|
-
// }
|
|
1505
1428
|
function _output(path, scope) {
|
|
1506
1429
|
var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
|
|
1507
1430
|
globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
|
|
1508
|
-
var params = [scope, scope.
|
|
1431
|
+
var params = [scope, scope.getBuffer(), scope.useSafeValue, scope.useComponent, scope.useElement].concat(globalHelpers.filter(function (name) {
|
|
1509
1432
|
return isFunction(scope[name]);
|
|
1510
1433
|
}).map(function (name) {
|
|
1511
1434
|
return scope[name].bind(scope);
|
|
@@ -1514,13 +1437,6 @@
|
|
|
1514
1437
|
return callback.apply(scope, params);
|
|
1515
1438
|
});
|
|
1516
1439
|
}
|
|
1517
|
-
function _require(name) {
|
|
1518
|
-
var filepath = ext(name, _classPrivateFieldGet2(_config, this).extension);
|
|
1519
|
-
var scope = this.context({});
|
|
1520
|
-
return _assertClassBrand(_EJS_brand, this, _output).call(this, filepath, scope).then(function () {
|
|
1521
|
-
return scope.getMacro();
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
1440
|
|
|
1525
1441
|
var templates = {};
|
|
1526
1442
|
var getOrigin = function getOrigin(url, secure) {
|