commit | 300962667bbbb1aa3df159d36012947cbe3423f8 | [log] [tgz] |
---|---|---|
author | Greg Lowe <greg@vis.net.nz> | Tue Feb 03 13:16:31 2015 +1300 |
committer | Greg Lowe <greg@vis.net.nz> | Tue Feb 03 13:16:31 2015 +1300 |
tree | df2820f2db66b3dc0f93158c79e893de4208cbac | |
parent | 26e3044083a629c9bbb436a044d640eee219491a [diff] |
Bump version
A Dart library to parse and render mustache templates.
This library used dart:mirrors
, which are known to greatly increase the output size of a Dart app compiled to JavaScript with dart2js. We recommend that you only use this library for your server-side Dart code.
import 'package:mustache/mustache.dart' as mustache; main() { var source = '{{#names}}<div>{{lastname}}, {{firstname}}</div>{{/names}}'; var template = mustache.parse(source); var output = template.renderString({'names': [ {'firstname': 'Greg', 'lastname': 'Lowe'}, {'firstname': 'Bob', 'lastname': 'Johnson'} ]}); print(output); }
Template parse(String source, {bool lenient : false}); abstract class Template { String renderString(values, {bool lenient : false, bool htmlEscapeValues : true}); void render(values, StringSink sink, {bool lenient : false, bool htmlEscapeValues : true}); }
Once a template has been created it can be rendered any number of times.
Both parse and render throw a FormatException if there is a problem with the template or rendering the values.
When lenient mode is enabled tag names may use any characters, otherwise only a-z, A-Z, 0-9, underscore and minus. Lenient mode will also silently ignore nulls passed as values.
By default all variables are html escaped, this behaviour can be changed by passing htmlEscapeValues : false.
Variables {{var-name}} Sections {{#section}}Blah{{/section}} Inverse sections {{^section}}Blah{{/section}} Comments {{! Not output. }} Unescaped variables {{{var-name}}} and {{&var-name}}
See the mustache templates tutorial for more information.
Passing all mustache specification tests for interpolation, sections, inverted, comments. The following sections are not implemented: partials, lambdas and delimeters.
Lenient nulls in inverse sections - see commented out test. Partial tags {{>partial}} Allow functions as values (Lambdas) Set Delimiter tags