Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syumai/dejs
ejs template engine for deno.
https://github.com/syumai/dejs
deno ejs typescript
Last synced: 2 months ago
JSON representation
ejs template engine for deno.
- Host: GitHub
- URL: https://github.com/syumai/dejs
- Owner: syumai
- License: mit
- Created: 2018-12-27T19:08:55.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-30T01:25:31.000Z (over 1 year ago)
- Last Synced: 2024-09-29T07:21:07.475Z (2 months ago)
- Topics: deno, ejs, typescript
- Language: TypeScript
- Homepage:
- Size: 91.8 KB
- Stars: 143
- Watchers: 7
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-deno - dejs - Deno的ejs模板引擎。 (Uncategorized / Uncategorized)
- awesome-list - dejs
- awesome-deno-cn - @syumai/dejs
- awesome-deno - dejs - ejs template engine for deno. (Libraries)
- awesome-deno - dejs - Ejs template engine for deno.![GitHub stars](https://img.shields.io/github/stars/syumai/dejs?style=plastic) (Modules / Online Playgrounds)
- awesome-deno - dejs - Ejs template engine for deno. (Modules / Template engine)
README
# dejs
[![Build Status](https://github.com/syumai/dejs/workflows/test/badge.svg?branch=master)](https://github.com/syumai/dejs/actions)
- [ejs](https://ejs.co) template engine for
[deno](https://github.com/denoland/deno).## Features
### Supported
- <%= %> Output escaped value
- <%- %> Output raw value
- <%# %> Comment (nothing will be shown)
- <% %> Evaluate (use control flow like: if, for)
- include partial ejs template### Not supported
- All other features of ejs
## Usage
```ts
import * as dejs from "https://deno.land/x/[email protected]/mod.ts";
```- **`renderFile`** `(filePath: string, params: Params): Promise`
- renders from file, outputs Deno.Reader
- **`render`** `(body: string, params: Params): Promise`
- renders from string, outputs Deno.Reader
- **`renderFileToString`** `(filePath: string, params: Params): Promise`
- renders from file, outputs string
- **`renderToString`** `(body: string, params: Params): Promise`
- renders from string, outputs string
- **`compile`** `(reader: Reader): Promise`
- only compiles ejs and returns `Template(params: Params): string`
- use this to cache compiled result of ejs### Render from file
- template.ejs
```ejs
<% if (name) { %>
hello, <%= name %>!
<% } %>```
- index.ts
```ts
const { cwd, stdout, copy } = Deno;
import { renderFile } from "https://deno.land/x/dejs/mod.ts";const output = await renderFile(`${cwd()}/template.ejs`, {
name: "world",
});
await copy(output, stdout);
```- console
```sh
$ deno index.ts
hello, world!
```
### Render from string
```ts
const { cwd, stdout, copy } = Deno;
import { render } from "https://deno.land/x/dejs/mod.ts";const template = `
<% if (name) { %>
hello, <%= name %>!
<% } %>
`;const output = await render(template, {
name: "world",
});
await copy(output, stdout);
```### Include partial ejs template
- To include template from other file, use `include` function in ejs.
- `include` resolves views from relative path from **executed ts / js file**.
(not from ejs template file).
- This behavior may change in the future.#### Usage
```ejs
await include(filePath, params)
```#### Example
- views/header.ejs
```ejs
<%- title %>
```
- views/footer.ejs
```ejs
```
- views/main.ejs
```
<%- await include('views/header.ejs', { title: 'include example' }) %>hello, world!
<%- await include('views/footer.ejs') %>
```- index.ts
```ts
const { cwd, stdout, copy } = Deno;
import { renderFile } from "https://deno.land/x/dejs/mod.ts";const output = await renderFile(`${cwd()}/views/main.ejs`);
await copy(output, stdout);
```- console
```sh
$ deno index.tsinclude example
hello, world!
```
## Limitations
- backslashes at line end will removed.
## Development
### Update modules
- Please use [dem](https://github.com/syumai/dem)
```
dem update https://deno.land/[email protected]
```### Lint
- `make lint`
### Format
- `make fmt`
### Testing
- `make test`
## Author
syumai
## License
MIT