2.0.1 • Published 7 years ago

sugar-template v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

sugar-templateBuild Status

A simple template engine based on mustache.js.

Install

NPM

Usage

const sugar = require('sugar-template')

sugar.render(`{{title | uppercase}}`, { title: 'test' }) // --> 'TEST'
sugar.render(`{{#each user}}{{.}} {{/each}}`, {
    user: {
        name: 'Mike',
        age: 18,
        gender: 'M'
    }
})
// --> Mike 18 M

Syntax

  1. Expression, {{varialbe}}, starts with {{ and ends with }}.

  2. HTML escaping. Normal expression will be automatically escaped. So, use {{{varialbe}}} if you don't wanna escaping.

  3. Helpers. Almost like handlebars, {{#helper context}} {{/helper}}.

  4. Inline helpers. {{helper context}}.

  5. Filters. {{context | filter}}.

  6. Ignore Compile. {{=text=}}, text here will output without any change.

API

sugar.render(String: template, Object: data)

Render template to string.

sugar.parse(String: template)

Parse template to AST.

License

MIT

2.0.1

7 years ago

2.0.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago