A simple template engine based on
mustache.js
.
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
-
Expression,
{{varialbe}}
, starts with{{
and ends with}}
. -
HTML escaping. Normal expression will be automatically escaped. So, use
{{{varialbe}}}
if you don't wanna escaping. -
Helpers. Almost like
handlebars
,{{#helper context}} {{/helper}}
. -
Inline helpers.
{{helper context}}
. -
Filters.
{{context | filter}}
. -
Ignore Compile.
{{=text=}}
,text
here will output without any change.
Render template to string.
Parse template to AST.
MIT