ejst

1.0.2 • Public • Published

ejst

A embedded javascript template engine for nodejs.

  • Auto cache template file to improving performance
  • Include feature

Installation

$ npm install ejst --save

Usage

Render string template

const ejst = require('ejst')
 
// render HTML string
let str = ejst.render('<h5><%=title%></h5>', { title: 'Hello' })
console.log(str)

Render file template

<!--index.html-->
<div>
  <div class="dialog">
    <% if(typeof title === 'string'){ %>
    <div class="dialog__hd">
      <strong class="dialog__title"><%=title%></strong>
    </div>
    <% } %>
    <div class="dialog__bd"><%=content%></div>
    <div class="dialog__ft">
    <% for(var i = 0; i < buttons.length; i++){ %>
      <%=include('./examples/include.html', {button: buttons[i]})%>
    <% } %>
    </div>
  </div>
</div>
<!--include.html-->
<a href="javascript:;" class="dialog__btn dialog__btn_<%=button.type%>"><%=button.label%></a>
const ejst = require('ejst')
 
// render HTML file
let data = {
  title: 'Question',
  content: 'Are you sure?',
  buttons: [{ label: 'Yes', type: 'green' }, { label: 'No', type: 'gray' }]
}
 
let str = ejst.renderFile('./examples/index.html', data)
console.log(str)

Include

<div>
  <% for(var i = 0; i < buttons.length; i++){ %>
    <%=include('./examples/include.html', {button: buttons[i]})%>
  <% } %>
</div>

License

MIT

Package Sidebar

Install

npm i ejst

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

5.53 kB

Total Files

7

Last publish

Collaborators

  • alex.wei