@prairielearn/html-ejs 1.0.1 → 1.1.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +12 -3
- package/tsconfig.json +1 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { type HtmlSafeString } from '@prairielearn/html';
|
|
|
6
6
|
* The resulting string is assumed to be appropriately escaped and will be used
|
|
7
7
|
* verbatim in the resulting HTML.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param filePathOrUrl The path or file URL of the file from which relative includes should be resolved.
|
|
10
10
|
* @param template The raw EJS template string.
|
|
11
11
|
* @param data Any data to be made available to the template.
|
|
12
12
|
* @returns The rendered EJS.
|
|
13
13
|
*/
|
|
14
|
-
export declare function renderEjs(
|
|
14
|
+
export declare function renderEjs(filePathOrUrl: string, template: string, data?: any): HtmlSafeString;
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.renderEjs = void 0;
|
|
7
7
|
const ejs_1 = __importDefault(require("ejs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const url_1 = require("url");
|
|
9
10
|
const html_1 = require("@prairielearn/html");
|
|
10
11
|
/**
|
|
11
12
|
* This is a shim to allow for the use of EJS templates inside of HTML tagged
|
|
@@ -14,13 +15,19 @@ const html_1 = require("@prairielearn/html");
|
|
|
14
15
|
* The resulting string is assumed to be appropriately escaped and will be used
|
|
15
16
|
* verbatim in the resulting HTML.
|
|
16
17
|
*
|
|
17
|
-
* @param
|
|
18
|
+
* @param filePathOrUrl The path or file URL of the file from which relative includes should be resolved.
|
|
18
19
|
* @param template The raw EJS template string.
|
|
19
20
|
* @param data Any data to be made available to the template.
|
|
20
21
|
* @returns The rendered EJS.
|
|
21
22
|
*/
|
|
22
|
-
function renderEjs(
|
|
23
|
-
|
|
23
|
+
function renderEjs(filePathOrUrl, template, data = {}) {
|
|
24
|
+
let resolvedPath = filePathOrUrl;
|
|
25
|
+
// This allows for us to pass `import.meta.url` to this function in ES Modules
|
|
26
|
+
// environments where `__filename` is not available.
|
|
27
|
+
if (filePathOrUrl.startsWith('file://')) {
|
|
28
|
+
resolvedPath = (0, url_1.fileURLToPath)(filePathOrUrl);
|
|
29
|
+
}
|
|
30
|
+
return (0, html_1.unsafeHtml)(ejs_1.default.render(template, data, { views: [path_1.default.dirname(resolvedPath)] }));
|
|
24
31
|
}
|
|
25
32
|
exports.renderEjs = renderEjs;
|
|
26
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,gDAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,gDAAwB;AACxB,6BAAoC;AAEpC,6CAAqE;AACrE;;;;;;;;;;;GAWG;AACH,SAAgB,SAAS,CAAC,aAAqB,EAAE,QAAgB,EAAE,OAAY,EAAE;IAC/E,IAAI,YAAY,GAAG,aAAa,CAAC;IAEjC,8EAA8E;IAC9E,oDAAoD;IACpD,IAAI,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QACvC,YAAY,GAAG,IAAA,mBAAa,EAAC,aAAa,CAAC,CAAC;KAC7C;IAED,OAAO,IAAA,iBAAU,EAAC,aAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC;AAVD,8BAUC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prairielearn/html-ejs",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@prairielearn/html": "^2.0.0",
|
|
12
|
-
"ejs": "^3.1.
|
|
12
|
+
"ejs": "^3.1.8"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@prairielearn/tsconfig": "*",
|
|
16
|
-
"@types/ejs": "^3.1.
|
|
17
|
-
"mocha": "^
|
|
18
|
-
"ts-node": "^10.
|
|
19
|
-
"typescript": "^4.
|
|
16
|
+
"@types/ejs": "^3.1.1",
|
|
17
|
+
"mocha": "^10.0.0",
|
|
18
|
+
"ts-node": "^10.8.1",
|
|
19
|
+
"typescript": "^4.7.4"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ejs from 'ejs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
3
4
|
|
|
4
5
|
import { unsafeHtml, type HtmlSafeString } from '@prairielearn/html';
|
|
5
6
|
/**
|
|
@@ -9,11 +10,19 @@ import { unsafeHtml, type HtmlSafeString } from '@prairielearn/html';
|
|
|
9
10
|
* The resulting string is assumed to be appropriately escaped and will be used
|
|
10
11
|
* verbatim in the resulting HTML.
|
|
11
12
|
*
|
|
12
|
-
* @param
|
|
13
|
+
* @param filePathOrUrl The path or file URL of the file from which relative includes should be resolved.
|
|
13
14
|
* @param template The raw EJS template string.
|
|
14
15
|
* @param data Any data to be made available to the template.
|
|
15
16
|
* @returns The rendered EJS.
|
|
16
17
|
*/
|
|
17
|
-
export function renderEjs(
|
|
18
|
-
|
|
18
|
+
export function renderEjs(filePathOrUrl: string, template: string, data: any = {}): HtmlSafeString {
|
|
19
|
+
let resolvedPath = filePathOrUrl;
|
|
20
|
+
|
|
21
|
+
// This allows for us to pass `import.meta.url` to this function in ES Modules
|
|
22
|
+
// environments where `__filename` is not available.
|
|
23
|
+
if (filePathOrUrl.startsWith('file://')) {
|
|
24
|
+
resolvedPath = fileURLToPath(filePathOrUrl);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return unsafeHtml(ejs.render(template, data, { views: [path.dirname(resolvedPath)] }));
|
|
19
28
|
}
|