@prairielearn/html-ejs 1.1.19 → 2.0.1

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/.mocharc.cjs ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ require: ['tsx'],
3
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @prairielearn/html-ejs
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 901fce8: Upgrade all JavaScript dependencies
8
+ - Updated dependencies [901fce8]
9
+ - @prairielearn/html@4.0.1
10
+
11
+ ## 2.0.0
12
+
13
+ ### Major Changes
14
+
15
+ - 4f30b7e: Publish as native ESM
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [4f30b7e]
20
+ - @prairielearn/html@4.0.0
21
+
3
22
  ## 1.1.19
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -9,14 +9,14 @@ If you have an EJS partial that you'd like to use inside of an `html` tagged tem
9
9
  Hello, <%= name %>!
10
10
  ```
11
11
 
12
- ```js
12
+ ```ts
13
13
  import { html } from '@prairielearn/html';
14
14
  import { renderEjs } from '@prairielearn/html-ejs';
15
15
 
16
16
  console.log(
17
17
  html`
18
18
  <div>Hello, world!</div>
19
- <div>${renderEjs(__filename, "<%- include('./hello'); %>", { name: 'Anjali' })}</div>
19
+ <div>${renderEjs(import.meta.url, "<%- include('./hello'); %>", { name: 'Anjali' })}</div>
20
20
  `.toString(),
21
21
  );
22
22
  ```
package/dist/index.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.renderEjs = void 0;
7
- const ejs_1 = __importDefault(require("ejs"));
8
- const path_1 = __importDefault(require("path"));
9
- const url_1 = require("url");
10
- const html_1 = require("@prairielearn/html");
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import ejs from 'ejs';
4
+ import { unsafeHtml } from '@prairielearn/html';
11
5
  /**
12
6
  * This is a shim to allow for the use of EJS templates inside of HTML tagged
13
7
  * template literals.
@@ -20,14 +14,13 @@ const html_1 = require("@prairielearn/html");
20
14
  * @param data Any data to be made available to the template.
21
15
  * @returns The rendered EJS.
22
16
  */
23
- function renderEjs(filePathOrUrl, template, data = {}) {
17
+ export function renderEjs(filePathOrUrl, template, data = {}) {
24
18
  let resolvedPath = filePathOrUrl;
25
19
  // This allows for us to pass `import.meta.url` to this function in ES Modules
26
20
  // environments where `__filename` is not available.
27
21
  if (filePathOrUrl.startsWith('file://')) {
28
- resolvedPath = (0, url_1.fileURLToPath)(filePathOrUrl);
22
+ resolvedPath = fileURLToPath(filePathOrUrl);
29
23
  }
30
- return (0, html_1.unsafeHtml)(ejs_1.default.render(template, data, { views: [path_1.default.dirname(resolvedPath)] }));
24
+ return unsafeHtml(ejs.render(template, data, { views: [path.dirname(resolvedPath)] }));
31
25
  }
32
- exports.renderEjs = renderEjs;
33
26
  //# 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;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,CAAC;QACxC,YAAY,GAAG,IAAA,mBAAa,EAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAuB,MAAM,oBAAoB,CAAC;AACrE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,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,CAAC;QACxC,YAAY,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\n\nimport ejs from 'ejs';\n\nimport { unsafeHtml, type HtmlSafeString } from '@prairielearn/html';\n/**\n * This is a shim to allow for the use of EJS templates inside of HTML tagged\n * template literals.\n *\n * The resulting string is assumed to be appropriately escaped and will be used\n * verbatim in the resulting HTML.\n *\n * @param filePathOrUrl The path or file URL of the file from which relative includes should be resolved.\n * @param template The raw EJS template string.\n * @param data Any data to be made available to the template.\n * @returns The rendered EJS.\n */\nexport function renderEjs(filePathOrUrl: string, template: string, data: any = {}): HtmlSafeString {\n let resolvedPath = filePathOrUrl;\n\n // This allows for us to pass `import.meta.url` to this function in ES Modules\n // environments where `__filename` is not available.\n if (filePathOrUrl.startsWith('file://')) {\n resolvedPath = fileURLToPath(filePathOrUrl);\n }\n\n return unsafeHtml(ejs.render(template, data, { views: [path.dirname(resolvedPath)] }));\n}\n"]}
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chai_1 = require("chai");
4
- const index_1 = require("./index");
1
+ import { assert } from 'chai';
2
+ import { renderEjs } from './index.js';
5
3
  describe('renderEjs', () => {
6
4
  it('renders EJS template without data', () => {
7
- chai_1.assert.equal((0, index_1.renderEjs)(__filename, '<p>Hello</p>', {}).toString(), '<p>Hello</p>');
5
+ assert.equal(renderEjs(import.meta.url, '<p>Hello</p>', {}).toString(), '<p>Hello</p>');
8
6
  });
9
7
  it('renders EJS template with data', () => {
10
- chai_1.assert.equal((0, index_1.renderEjs)(__filename, '<p>Hello <%= name %></p>', { name: 'Divya' }).toString(), '<p>Hello Divya</p>');
8
+ assert.equal(renderEjs(import.meta.url, '<p>Hello <%= name %></p>', { name: 'Divya' }).toString(), '<p>Hello Divya</p>');
11
9
  });
12
10
  });
13
11
  //# sourceMappingURL=index.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAE9B,mCAAoC;AAEpC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,aAAM,CAAC,KAAK,CAAC,IAAA,iBAAS,EAAC,UAAU,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,cAAc,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,aAAM,CAAC,KAAK,CACV,IAAA,iBAAS,EAAC,UAAU,EAAE,0BAA0B,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,EAC/E,oBAAoB,CACrB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,cAAc,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,KAAK,CACV,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,0BAA0B,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,EACpF,oBAAoB,CACrB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert } from 'chai';\n\nimport { renderEjs } from './index.js';\n\ndescribe('renderEjs', () => {\n it('renders EJS template without data', () => {\n assert.equal(renderEjs(import.meta.url, '<p>Hello</p>', {}).toString(), '<p>Hello</p>');\n });\n\n it('renders EJS template with data', () => {\n assert.equal(\n renderEjs(import.meta.url, '<p>Hello <%= name %></p>', { name: 'Divya' }).toString(),\n '<p>Hello Divya</p>',\n );\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@prairielearn/html-ejs",
3
- "version": "1.1.19",
3
+ "version": "2.0.1",
4
+ "type": "module",
4
5
  "main": "dist/index.js",
5
6
  "repository": {
6
7
  "type": "git",
@@ -10,19 +11,19 @@
10
11
  "scripts": {
11
12
  "build": "tsc",
12
13
  "dev": "tsc --watch --preserveWatchOutput",
13
- "test": "mocha --no-config --require tsx src/index.test.ts"
14
+ "test": "mocha src/**/*.test.ts"
14
15
  },
15
16
  "dependencies": {
16
- "@prairielearn/html": "^3.1.7",
17
- "ejs": "^3.1.9"
17
+ "@prairielearn/html": "^4.0.1",
18
+ "ejs": "^3.1.10"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@prairielearn/tsconfig": "^0.0.0",
21
22
  "@types/ejs": "^3.1.5",
22
- "@types/node": "^20.12.2",
23
- "chai": "^4.4.1",
23
+ "@types/node": "^20.12.11",
24
+ "chai": "^5.1.1",
24
25
  "mocha": "^10.4.0",
25
- "tsx": "^4.7.1",
26
- "typescript": "^5.4.3"
26
+ "tsx": "^4.10.2",
27
+ "typescript": "^5.4.5"
27
28
  }
28
29
  }
package/src/index.test.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { assert } from 'chai';
2
2
 
3
- import { renderEjs } from './index';
3
+ import { renderEjs } from './index.js';
4
4
 
5
5
  describe('renderEjs', () => {
6
6
  it('renders EJS template without data', () => {
7
- assert.equal(renderEjs(__filename, '<p>Hello</p>', {}).toString(), '<p>Hello</p>');
7
+ assert.equal(renderEjs(import.meta.url, '<p>Hello</p>', {}).toString(), '<p>Hello</p>');
8
8
  });
9
9
 
10
10
  it('renders EJS template with data', () => {
11
11
  assert.equal(
12
- renderEjs(__filename, '<p>Hello <%= name %></p>', { name: 'Divya' }).toString(),
12
+ renderEjs(import.meta.url, '<p>Hello <%= name %></p>', { name: 'Divya' }).toString(),
13
13
  '<p>Hello Divya</p>',
14
14
  );
15
15
  });
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- import ejs from 'ejs';
2
1
  import path from 'path';
3
2
  import { fileURLToPath } from 'url';
4
3
 
4
+ import ejs from 'ejs';
5
+
5
6
  import { unsafeHtml, type HtmlSafeString } from '@prairielearn/html';
6
7
  /**
7
8
  * This is a shim to allow for the use of EJS templates inside of HTML tagged