tagline |
---|
logic-less templates |
{{=<%% %%>=}}
A mustache parser and renderer written in Lua with the aim of producing the exact same output as mustache.js on the same template + cjson-encoded view. For full syntax of mustache see the mustache manual.
- syntax:
- html-escaped values:
{{var}}
- unescaped values:
{{{var}}}
or{{& var}}
- sections:
{{#var}} ... {{/var}}
- inverted sections:
{{^var}} ... {{/var}}
- comments:
{{! ... }}
- partials:
{{>name}}
- set delimiters:
{{=<% %>=}}
- scoped vars:
a.b.c
wherevervar
is expected.
- html-escaped values:
- semantics:
- compatible with mustache.js as to what constitutes a non-false value,
in particular
''
,0
and'0'
are considered false. - compatibile with [cjson] as to what is considered an array and what is a hashmap, in particular sparse arrays that contain no other keys are seen as lists and their non-nil elements are iterated.
- section lambdas
f(text, render)
and value lambdasf()
are supported.
- compatible with mustache.js as to what constitutes a non-false value,
in particular
- rendering:
- passes all mustache.js tests.
- preserves the indentation of standalone partials.
- escapes
&
,>
,<
,"
,'
,/
,,
=` like mustache.js.
- other:
- error reporting with line and column number information.
- dump tool for debugging compiled templates.
- text position info for all tokens (can be used for syntax highlighting).
mustache.render(template, (compile and) render a template [view], [partials], [write], [d1, d2], [escape_func]) -> s
mustache.compile(template, compile a template to bytecode [d1, d2]) -> template
mustache.dump(template, dump bytecode (for debugging) [d1, d2], [print])
(Compile and) render a template. Args:
template
- the template, in compiled or in string form.view
- the template view.partials
- either{name -> template}
orfunction(name) -> template
write
- afunction(s)
to output the rendered pieces to.d1, d2
- initial set delimiters.escape_func
- the escape function for{{var}}
substitutions.
Compile a template to bytecode (if not already compiled).
Dump the template bytecode (for debugging).