@kosatyi/ejs 0.0.103 → 0.0.105
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/worker.js +252 -296
- package/dist/esm/worker.js +21 -12
- package/dist/umd/worker.js +252 -296
- package/dist/umd/worker.min.js +3 -1
- package/package.json +2 -2
package/dist/esm/worker.js
CHANGED
|
@@ -1005,21 +1005,21 @@ class EJS {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
}
|
|
1007
1007
|
|
|
1008
|
-
const
|
|
1008
|
+
const templateCache = {};
|
|
1009
1009
|
|
|
1010
1010
|
const getOrigin = (url, secure) => {
|
|
1011
|
-
url =
|
|
1011
|
+
url = URL.parse(url);
|
|
1012
1012
|
url.protocol = secure ? 'https:' : 'http:';
|
|
1013
1013
|
return url.origin
|
|
1014
1014
|
};
|
|
1015
1015
|
|
|
1016
|
-
const { render, context, helpers, configure
|
|
1016
|
+
const { render, context, helpers, configure } = new EJS({
|
|
1017
1017
|
cache: false,
|
|
1018
1018
|
withObject: false,
|
|
1019
1019
|
resolver(path, name) {
|
|
1020
1020
|
return new Promise((resolve, reject) => {
|
|
1021
|
-
if (
|
|
1022
|
-
resolve(
|
|
1021
|
+
if (isFunction(templateCache[name])) {
|
|
1022
|
+
resolve(templateCache[name]);
|
|
1023
1023
|
} else {
|
|
1024
1024
|
reject(new TemplateNotFound(`template ${name} not found`));
|
|
1025
1025
|
}
|
|
@@ -1028,13 +1028,18 @@ const { render, context, helpers, configure, create } = new EJS({
|
|
|
1028
1028
|
});
|
|
1029
1029
|
|
|
1030
1030
|
/**
|
|
1031
|
-
*
|
|
1032
|
-
* @param list
|
|
1031
|
+
* @param {Object<string,any>} templates
|
|
1033
1032
|
*/
|
|
1034
|
-
function
|
|
1035
|
-
Object.assign(
|
|
1033
|
+
function useTemplates(templates = {}) {
|
|
1034
|
+
Object.assign(templateCache, templates);
|
|
1036
1035
|
}
|
|
1037
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* @deprecated Renamed to `useTemplates`
|
|
1039
|
+
* @param {Object<string,any>} templates
|
|
1040
|
+
*/
|
|
1041
|
+
const setTemplates = useTemplates;
|
|
1042
|
+
|
|
1038
1043
|
/**
|
|
1039
1044
|
* @typedef {{}} HonoContext
|
|
1040
1045
|
* @property {function(*):Promise<Response>} html
|
|
@@ -1049,7 +1054,8 @@ function setTemplates(list) {
|
|
|
1049
1054
|
* @param {Object<string,any>} options
|
|
1050
1055
|
* @return {(function(c:HonoContext, next): Promise<any>)|*}
|
|
1051
1056
|
*/
|
|
1052
|
-
function
|
|
1057
|
+
function useRenderer({ templates = {}, version, secure = true } = {}) {
|
|
1058
|
+
useTemplates(templates);
|
|
1053
1059
|
return async (c, next) => {
|
|
1054
1060
|
c.data = context({});
|
|
1055
1061
|
c.data.set('version', version);
|
|
@@ -1064,6 +1070,9 @@ function setRenderer({ version, secure = true } = {}) {
|
|
|
1064
1070
|
}
|
|
1065
1071
|
}
|
|
1066
1072
|
|
|
1067
|
-
|
|
1073
|
+
/**
|
|
1074
|
+
* @deprecated Renamed to `useRenderer`
|
|
1075
|
+
*/
|
|
1076
|
+
const setRenderer = useRenderer;
|
|
1068
1077
|
|
|
1069
|
-
export { TemplateError, TemplateNotFound, TemplateSyntaxError, configure, context,
|
|
1078
|
+
export { TemplateError, TemplateNotFound, TemplateSyntaxError, configure, context, helpers, render, setRenderer, setTemplates, useRenderer, useTemplates };
|