commit | 35fe6de078c7f0bb8f471c30052039bdd6db44b4 | [log] [tgz] |
---|---|---|
author | Greg Lowe <greg@vis.net.nz> | Sat Apr 06 21:46:59 2013 +1300 |
committer | Greg Lowe <greg@vis.net.nz> | Sat Apr 06 21:46:59 2013 +1300 |
tree | f54699818f574b08cd168658b1f2ca639258529c | |
parent | 935a544a6f98bd1ba1455a0301057b0277efac59 [diff] |
Trim whitespace from tag names
A Dart library to parse and render mustache templates.
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.
Trim whitespace in tag names {{ firstname }} == {{firstname}} Dotted names {{person.firstname}} == {{#person}}{{firstname}}{{/person}} Partial tags {{>partial}} Allow functions as values (See mustache docs) Pass all tests in mustache spec