Viewing version 0.1.8. Open the latest package page.

mustache

0.1.8

Mustache template library

Download archive

Readme

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, 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.

Supported

 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.

To do

Lenient nulls in inverse sections - see commented out test.
Partial tags   {{>partial}}
Allow functions as values (Lambdas)
Set Delimiter tags
Changelog

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'mustache:0.1.8'
pubspec.yaml
name: mustache
version: 0.1.8
author: Greg Lowe <greg@vis.net.nz>
description: Mustache template library
homepage: https://github.com/xxgreg/mustache
environment:
  sdk: ">=0.8.10+6 <2.0.0"
dev_dependencies:
  unittest: ">=0.9.0 <0.10.0"

Version history

VersionPublishedArchiveSHA-256
0.1.0Cached · Upstream SHA-256 matchedDownloaded4ab6fb…bbb413
0.1.1Cached · Upstream SHA-256 matchedDownload55219fab…283bb3
0.1.2Cached · Upstream SHA-256 matchedDownload86679efa…5e7720
0.1.3Cached · Upstream SHA-256 matchedDownload92a2fcee…825cf8
0.1.4Cached · Upstream SHA-256 matchedDownload04c94972…0ab0ad
0.1.5Cached · Upstream SHA-256 matchedDownload2d2be5b6…5dd5c0
0.1.6Cached · Upstream SHA-256 matchedDownloadca8409d6…577b2d
0.1.7Cached · Upstream SHA-256 matchedDownloade17a32ba…4756be
0.1.8Cached · Upstream SHA-256 matchedDownload0752264e…6ead77
0.2.0Cached · Upstream SHA-256 matchedDownloadf80eeec4…9702f3
0.2.0+1Cached · Upstream SHA-256 matchedDownloaddd91018f…41528b
0.2.1Cached · Upstream SHA-256 matchedDownloadae6f8e4f…9c4f53
0.2.2Cached · Upstream SHA-256 matchedDownload79b9addd…7fb3a2
0.2.3Cached · Upstream SHA-256 matchedDownload0f3d176a…01cf1b
0.2.4Cached · Upstream SHA-256 matchedDownloadfd345452…6f5f46
0.2.5Cached · Upstream SHA-256 matchedDownloada74fb5f2…510297
0.2.5+1Cached · Upstream SHA-256 matchedDownloadf3b958a5…fa40fe
1.0.0Cached · Upstream SHA-256 matchedDownloadccc823f8…e5d116
1.0.1Cached · Upstream SHA-256 matchedDownload3e5b7462…811be5
1.0.2Cached · Upstream SHA-256 matchedDownload959cbf25…4c21c2
1.1.0Cached · Upstream SHA-256 matchedDownloadbe6cde6e…dcd543
1.1.1Cached · Upstream SHA-256 matchedDownloadee510068…878cd8

Dependencies

No direct dependencies declared.