commit | aba25f4db4d0952372a0b02a1851d565fc2349ba | [log] [tgz] |
---|---|---|
author | Greg Lowe <greg@vis.net.nz> | Fri Apr 05 16:50:38 2013 +1300 |
committer | Greg Lowe <greg@vis.net.nz> | Fri Apr 05 16:50:38 2013 +1300 |
tree | b44194a1792ca8c9471c13a42bd6e02021435cb9 | |
parent | 2a5879f92b1840f018cd13ad5e7617961e1cd2c7 [diff] |
update readme
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.render({'names': [ {'fistname': 'Greg', 'lastname': 'Lowe'}, {'fistname': 'Bob', 'lastname': 'Johnson'} ]}); print(output); }
Template parse(String source, {bool lenient : false}); abstract class Template { String render(values, {bool lenient : false}); }
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.
Variables {{var-name}} Sections {{#section}}Blah{{/section}} Inverse sections {{^section}}Blah{{/section}} Comments {{! Not output. }}
See the mustache templates tutorial for more information.
Escape tags {{{ ... }}}, and {{& ... }} Partial tags {{>partial}} Functions as values And maybe later: Incremental parser, and renderer (i.e. Stream based) Allow the incremental renderer to handle values which are Futures and Streams.