stml

1.0.1 • Public • Published

Super Type Markup Language

Lightweight JavaScript template engine for better cleaner code.

Travis branch Coveralls branch npm npm

Install

$ npm install stml
# Or
$ yarn add stml

Usage

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.

Readme

Keywords

Package Sidebar

Install

npm i stml

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • chikara