mustache 0.1.1 copy "mustache: ^0.1.1" to clipboard
mustache: ^0.1.1 copied to clipboard

outdatedDart 1 only

Mustache template library

Mustache templates #

A Dart library to parse and render mustache templates.

Build Status

Example #

	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);
	}

API #


Template parse(String source, {bool lenient : false});

abstract class Template {
	String renderString(values, {bool lenient : false});
	void render(values, StringSink sink, {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.

Supported #

 Variables             {{var-name}}
 Sections              {{#section}}Blah{{/section}}
 Inverse sections      {{^section}}Blah{{/section}}
 Comments              {{! Not output. }}

See the mustache templates tutorial for more information.

To do #

Escape tags {{{ ... }}}, and {{& ... }}
Partial tags {{>partial}}
Allow functions as values (See mustache docs)
Collect some test files, make a test harness to compare the output against another mustache lib.
15
likes
0
pub points
61%
popularity

Publisher

unverified uploader

Mustache template library

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on mustache