Skip to content

Commit

Permalink
Remove @foal/ejs
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicPoullain committed Aug 27, 2020
1 parent 2f11786 commit caa030c
Show file tree
Hide file tree
Showing 14 changed files with 2 additions and 2,521 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jobs:
run: cd packages/cli && npm run test
- name: Run unit tests of @foal/csrf
run: cd packages/csrf && npm run test
- name: Run unit tests of @foal/ejs
run: cd packages/ejs && npm run test
- name: Run unit tests of @foal/examples
run: cd packages/examples && npm run test
- name: Run unit tests of @foal/graphql
Expand Down
6 changes: 1 addition & 5 deletions docs/utilities/templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,4 @@ But the path can also be relative to the controller file. The `render` function
// | '- login.html
// '- login.controller.ts
render('./templates/login.html', { /* ... */ }, __dirname)
```

## The Legacy Package `@foal/ejs`

Previous versions of FoalTS (<v1.0.0) only accepted a certain format for template engines. The package `@foal/ejs` was an adapter of EJS for the framework. Since FoalTS now supports Express-compatible template engines, prefer using the `ejs` library directly in the future.
```
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"reflect-metadata": "~0.1.13"
},
"devDependencies": {
"@foal/ejs": "^1.11.0",
"@foal/internal-test": "^1.10.0",
"@types/mocha": "7.0.2",
"@types/node": "10.17.24",
Expand Down
19 changes: 0 additions & 19 deletions packages/core/src/common/utils/render.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,6 @@ describe('render', () => {
}
});

it('should render the template with the given template engine (renderToString).', async () => {
process.env.SETTINGS_TEMPLATE_ENGINE = '@foal/ejs';
const name = 'Foobar';
const expected = `Hello ${name}! How are you?`;
const actual = await render('./templates/template.ejs.html', { name }, __dirname);
ok(actual instanceof HttpResponseOK);
strictEqual(actual.body, expected);
});

it('should render the template with the given template engine (Express).', async () => {
process.env.SETTINGS_TEMPLATE_ENGINE = 'ejs';
const name = 'Foobar';
Expand All @@ -136,16 +127,6 @@ describe('render', () => {
strictEqual(actual.body, expected);
});

it('should throw errors returned by the given template engine (renderToString).', async () => {
process.env.SETTINGS_TEMPLATE_ENGINE = '@foal/ejs';
try {
await render('./templates/template.ejs.html', {}, __dirname);
throw new Error('An error should have been thrown');
} catch (error) {
strictEqual(error.message.includes('name is not defined'), true);
}
});

it('should throw errors returned by the given template engine (Express).', async () => {
process.env.SETTINGS_TEMPLATE_ENGINE = 'ejs';
try {
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/common/utils/render.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function render(templatePath: string, locals: object = {}, dirname?

const templateEngine = Config.get('settings.templateEngine', 'string');
if (templateEngine) {
const { renderToString, __express } = require(templateEngine);
const { __express } = require(templateEngine);
if (__express) {
return new Promise<HttpResponseOK>((resolve, reject) => {
__express(path, locals, (err: any, html: string) => {
Expand All @@ -53,9 +53,6 @@ export async function render(templatePath: string, locals: object = {}, dirname?
});
});
}
if (renderToString) {
return new HttpResponseOK(renderToString(template, locals));
}
throw new Error(`${templateEngine} is not a template engine compatible with FoalTS.`);
}

Expand Down
21 changes: 0 additions & 21 deletions packages/ejs/LICENSE

This file was deleted.

67 changes: 0 additions & 67 deletions packages/ejs/README.md

This file was deleted.

Loading

0 comments on commit caa030c

Please sign in to comment.