1.0.1 • Published 9 years ago
stml v1.0.1
Super Type Markup Language
Lightweight JavaScript template engine for better cleaner code.
Install
$ npm install stml
# Or
$ yarn add stmlUsage
import fs from 'fs'
import path from 'path'
import stml from 'stml'
const src = fs.readFileSync(path.join(__dirname, 'template.html'))
const dest = stml.compile(src, {
  locals: {
    entries: ['James', 'John', 'Tom']
  },
  filename: path.join(__dirname, 'template.html')
})
console.log(dest)API
| Name | Type | Default | Description | 
|---|---|---|---|
| locals | Object | The options to pass params to template. | |
| filename | String | The absolute path souce filename when extends is declared. | |
| expressionOpen | String | '{' | Expression statement open syntax. | 
| expressionClose | String | '}' | Expression statement close syntax. | 
| blockOpen | String | '<%' | Block statement open syntax. | 
| blockClose | String | '%>' | Block statement close syntax. | 
Syntax
expression statement
Use jsx syntax for expression statement.
<div>{ name }</div> <!-- escape -->
<div>{- name }</div> <!-- unescape -->block statement
Use jsp syntax for block statement.
<% if (entries.length) { %>
  <ul>
    <% entries.forEach(function(entry){ %>
      <li>{ entry }</li>
    <% }) %>
  </ul>
<% } %>extends statement
Use jsp syntax for extends statement.
<% extends 'header.html' %>License
Released under the MIT license.