• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ejs template engine for deno.

dejs

Build Status

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

import * as dejs from "https://deno.land/x/[email protected]/mod.ts";
  • renderFile (filePath: string, params: Params): Promise<Deno.Reader>
    • renders from file, outputs Deno.Reader
  • render (body: string, params: Params): Promise<Deno.Reader>
    • renders from string, outputs Deno.Reader
  • renderFileToString (filePath: string, params: Params): Promise<string>
    • renders from file, outputs string
  • renderToString (body: string, params: Params): Promise<string>
    • renders from string, outputs string
  • compile (reader: Reader): Promise<Template>
    • only compiles ejs and returns Template(params: Params): string
    • use this to cache compiled result of ejs

Render from file

  • template.ejs
<body>
  <% if (name) { %>
    <h1>hello, <%= name %>!</h1>
  <% } %>
</body>
  • index.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
$ deno index.ts
<body>

    <h1>hello, world!</h1>

</body>

Render from string

const { cwd, stdout, copy } = Deno;
import { render } from "https://deno.land/x/dejs/mod.ts";

const template = `<body>
  <% if (name) { %>
    <h1>hello, <%= name %>!</h1>
  <% } %>
</body>`;

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

await include(filePath, params)

Example

  • views/header.ejs
<html>
<head>
  <title><%- title %></title>
</head>
<body>
  • views/footer.ejs
</body>
</html>
  • views/main.ejs
<%- await include('views/header.ejs', { title: 'include example' }) %>
<h1>hello, world!</h1>
<%- await include('views/footer.ejs') %>
  • index.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
$ deno index.ts
<html>
<head>
  <title>include example</title>
</head>
<body>
<h1>hello, world!</h1>
</body>
</html>

Limitations

  • backslashes at line end will removed.

Development

Update modules

  • Please use dem
dem update https://deno.land/[email protected]

Lint

  • make lint

Format

  • make fmt

Testing

  • make test

Author

syumai

License

MIT

More Repositories

1

workers

Go package to run an HTTP server on Cloudflare Workers.
Go
614
star
2

dinatra

Sinatra like light weight web app framework for deno.
TypeScript
413
star
3

dem

A module version manager for Deno.
TypeScript
61
star
4

trollo

Simple Trello clone implemented with Vue.js and Vuex
Vue
47
star
5

worker-template-tinygo

A template for starting a Cloudflare Worker project with tinygo.
Go
32
star
6

deno-libs

Simple commands implemented for deno.
TypeScript
30
star
7

go-image-proxy-worker

A Cloudflare Worker application which serves patched version of imageproxy.
JavaScript
26
star
8

sed-awk-hands-on-ja

Go
25
star
9

workers-playground

my playground for Cloudflare Workers.
JavaScript
22
star
10

denoio

denoio is a Go package to bind Deno and Go(Wasm)'s I/O interfaces.
TypeScript
21
star
11

go-jpostcode

a Go package to find Japanese address data from Japanese postal code
Go
20
star
12

syumaigen

A CLI tool to generate syumai's avatar image
Go
20
star
13

gpgsync

The Go Playground with coedit mode.
JavaScript
19
star
14

go-hyperscript

hyperscript implementation in Go.
Go
18
star
15

emotter

A web app to post emoji implemented in connect-go and connect-web.
TypeScript
16
star
16

denoboard

message board application implemented in Deno
TypeScript
16
star
17

sunmi-namecard-printer

Name card printer app for Sunmi devices.
TypeScript
15
star
18

go-wasm-todo-list

ToDo List App implemented in Go + WebAssembly.
JavaScript
14
star
19

sandboxed-eval

iframe-sandboxed eval working on the browser.
JavaScript
14
star
20

goplayground-vim

A Vim plugin to add commands to call The Go Playground from Vim.
TypeScript
13
star
21

hono-middleware-go

A package to write Hono middleware in Go or TinyGo.
JavaScript
13
star
22

go-wasm-sizes

compare WebAssembly build size depends on imported package.
Makefile
12
star
23

vue-native-custom-transformer-plugin

Custom transformer plugin for vue-native
JavaScript
12
star
24

deno-deploy-scale-image

image scaling app built on Deno Deploy and Go WebAssembly.
TypeScript
12
star
25

longify

A command to output longified ascii art.
Go
11
star
26

wee-chat

Sample Chat app implemented in Weex and WebSocket
JavaScript
10
star
27

denoget

A tool to install executable deno script.
TypeScript
10
star
28

go-playground-addons

Chrome Extension for the Go Playground
TypeScript
9
star
29

react-sidebar-layout

TypeScript
8
star
30

ffmpeg-device-list-parser

Parser of FFmpeg device list - written in Node.js
JavaScript
8
star
31

goplayground-js

The Go Playground API client for JavaScript written in TypeScript.
TypeScript
7
star
32

emo

a CLI tool to find emojis with fuzzy-find window.
Go
7
star
33

printpdf

A utility to print page to PDF using chromedp.
Go
7
star
34

cli

Small CLI tools
JavaScript
6
star
35

genericsutil

utilities for Go 1.18 generics.
Go
6
star
36

protocat

A CLI tool to concatenate multiple proto files into a single file.
Go
6
star
37

deno-wasm-playground

TypeScript
5
star
38

syum.ai

A web app hosted on syum.ai
Go
5
star
39

tinyutil

utilities for tinygo + Wasm.
JavaScript
5
star
40

worker-template-go

A template for starting a Cloudflare Worker project with Go.
Go
5
star
41

go-wasm-gzipper

JavaScript
5
star
42

marp-pages-example

A Cloudflare Pages application which renders Marp slides without static site generation.
TypeScript
5
star
43

gospec-previewer

A simple web application to preview specified version of Go Language Specification.
TypeScript
5
star
44

til

Today I learned
WebAssembly
4
star
45

hono-esbuild-bundler-middleware

esbuild Bundler Middleware for Hono
TypeScript
4
star
46

uuidgenseeded

A CLI tool to generate UUID with seed text.
Go
4
star
47

go-wasm-playground

JavaScript
4
star
48

tcpstudy

Go
4
star
49

social.syum.ai

Wildebeest server served on social.syum.ai
TypeScript
3
star
50

proconutil

Go utils for programming contests
Go
3
star
51

go-dayjs

day.js wrapper package for Go based on goja.
Go
3
star
52

vue-native-example-app

Example app of Vue Native with https://github.com/syumai/vue-native-custom-transformer-plugin
Vue
3
star
53

hyper-reversi

Reversi game implemented in Hyperapp
JavaScript
3
star
54

gorunner

gorunner runs Go script in safe WebAssembly environment using Node.js
Go
3
star
55

react-vue-native-chat

[WIP] This is sample implementation of chat app with react-vue-native-scripts
JavaScript
2
star
56

syumai

Profile page of syumai
2
star
57

tt

A test runner for deno based on go test.
TypeScript
2
star
58

go-playground-custom

A customized version of The Go Playground with rich features.
JavaScript
2
star
59

deno-docker

Docker image to run deno in safe place.
Dockerfile
2
star
60

webpacker-docker-example

Example application of RoR with webpacker 3 and docker-compose
Ruby
2
star
61

binpack

TypeScript
2
star
62

runa

A utility to convert characters and code points
Go
2
star
63

go117-generics-investigation

A set of code to investigate generic code works with Go 1.17.
Go
1
star
64

go-wasm-counter

Example counter app written in go. This app runs on browser with wasm build.
JavaScript
1
star
65

followfilter

Find twitter followers or followees who has a name with specified keyword.
Go
1
star
66

goja-cli

A CLI tool to run goja in terminal.
Go
1
star
67

zenn

Articles for Zenn
1
star
68

heroku-config-bot

Herokuサーバの環境変数を設定してくれるSlack bot
JavaScript
1
star
69

file-zipper

Utility for downloading multiple files as zip
JavaScript
1
star
70

study-compilerbook

C
1
star
71

gear360pano

Docker image of gear360pano https://github.com/ultramango/gear360pano
1
star
72

sunmi-receiptline-printer

WIP - An app for Sunmi devices to print recepit written in receiptline.
TypeScript
1
star
73

ditherer

A CLI tool to convert PNG into dithered image.
JavaScript
1
star
74

vue-synched-columns

Synchronized multiple columns implemented in Vue.js.
JavaScript
1
star
75

asset-prefix-example

JavaScript
1
star
76

postmail

CLI tool to send email using LOGIN auth
Go
1
star
77

embed-example

An example of web application using Go 1.16's embed.
TypeScript
1
star
78

vue-fade-carousel

Carousel with fade animation implemented in Vue.js
Vue
1
star
79

go-generics

an experimental implementation of Go's Generics packages based on the Proposal document.
Go
1
star
80

go-jsutil

A set of utilities for Go programs which communicate with JavaScript via syscall/js.
Go
1
star
81

sd-cloudflare-examples

TypeScript
1
star
82

syumai.deno.dev

TypeScript
1
star