dejs
Features
Supported
- <%= %> Output escaped value
- <%- %> Output raw value
- <%# %> Comment (nothing will be shown)
- <% %> Evaluate (use control flow like: if, for)
Not supported
- All other features of ejs
Usage
import * as dejs from 'https://deno.land/x/dejs@0.1.1/dejs.ts';
renderFile(filePath: string, params: Params): Promise<Reader>
- render from file
render(body: string, params: Params): Promise<Reader>
- render from string
compile(reader: Reader): Promise<Template>
- only compiles ejs and returns
Template(params: Params): Reader
- use this to cache compiled result of ejs
- only compiles ejs and returns
Render from file
- template.ejs
<body>
<% if (name) { %>
<h1>hello, <%= name %>!</h1>
<% } %>
</body>
- index.ts
import { cwd, stdout, copy } from 'deno';
import { renderFile } from 'https://deno.land/x/dejs/dejs.ts';
(async () => {
const output = await renderFile(`${cwd()}/template.ejs`, {
name: 'world',
});
await copy(stdout, output);
})();
- console
$ deno index.ts
<body>
<h1>hello, world!</h1>
</body>
Render from string
import { cwd, stdout, copy } from 'deno';
import { render } from 'https://deno.land/x/dejs/dejs.ts';
const template = `<body>
<% if (name) { %>
<h1>hello, <%= name %>!</h1>
<% } %>
</body>`;
(async () => {
const output = await render(template, {
name: 'world',
});
await copy(stdout, output);
})();
Author
syumai
License
MIT