All Projects → syumai → Dejs

syumai / Dejs

Licence: mit
ejs template engine for deno.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Dejs

Dynamodb Admin
GUI for DynamoDB Local or dynalite
Stars: ✭ 803 (+711.11%)
Mutual labels:  ejs
Node Chat One To One
Node.js socket-io based one to one chat engine
Stars: ✭ 47 (-52.53%)
Mutual labels:  ejs
Template.js
A javascript template engine, simple, easy & extras, support webpack, rollup, parcel, browserify, fis and gulp
Stars: ✭ 1,201 (+1113.13%)
Mutual labels:  ejs
Vuepress Plugin Comment
Comment plugin in vuepress, such as Gitalk, Valine...
Stars: ✭ 26 (-73.74%)
Mutual labels:  ejs
Friend.ly
A social media platform with a friend recommendation engine based on personality trait extraction
Stars: ✭ 41 (-58.59%)
Mutual labels:  ejs
Egg View Ejs
egg view plugin for ejs.
Stars: ✭ 54 (-45.45%)
Mutual labels:  ejs
Hexo Theme Vexo
🍟 Vexo is a Hexo theme inspired by Vue's official website.
Stars: ✭ 546 (+451.52%)
Mutual labels:  ejs
Root Config
Stars: ✭ 87 (-12.12%)
Mutual labels:  ejs
Community
a community based on Node.js
Stars: ✭ 44 (-55.56%)
Mutual labels:  ejs
Quebradev.github.io
Site do podcast perifatécnico QuebraDev
Stars: ✭ 73 (-26.26%)
Mutual labels:  ejs
Ideoxan
👩‍💻 Ideoxan is a free to use online tool to learn programming.
Stars: ✭ 29 (-70.71%)
Mutual labels:  ejs
Cmms
Computerized Maintenance Management System
Stars: ✭ 31 (-68.69%)
Mutual labels:  ejs
Nodetyped
Node.js Express Startup Seed with ES6, Typescript, SCSS, EJS, Nodemon, Bootstrap 4, TSLint, TypeDoc
Stars: ✭ 69 (-30.3%)
Mutual labels:  ejs
Html Webpack Template
a better default template for html-webpack-plugin
Stars: ✭ 818 (+726.26%)
Mutual labels:  ejs
Hibiki
🤖 The best all-in-one Discord bot! Automod, fun, music, utilities, and more. Customizable, easy-to-use, and fully translatable.
Stars: ✭ 86 (-13.13%)
Mutual labels:  ejs
Hexo Theme Anisina
🎨 A simple responsive , support qiniu image cdn theme for hexo https://haojen.github.io/
Stars: ✭ 746 (+653.54%)
Mutual labels:  ejs
Hexo Theme Volantis
A Wonderful Theme for Hexo https://volantis.js.org
Stars: ✭ 1,050 (+960.61%)
Mutual labels:  ejs
Poetries.github.io
博客,用于记录学习总结的地方。关注公众号「前端进阶之旅」,一起学习
Stars: ✭ 94 (-5.05%)
Mutual labels:  ejs
Generator Jhipster Quarkus
Quarkus blueprint for JHipster
Stars: ✭ 85 (-14.14%)
Mutual labels:  ejs
Nodejs Koa Blog
基于 Node.js Koa2 实战开发的一套完整的博客项目网站
Stars: ✭ 1,162 (+1073.74%)
Mutual labels:  ejs

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";

(async () => {
  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>`;

(async () => {
  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";

(async () => {
  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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].