Viewing version 0.1.6. Open the latest package page.
mustache
0.1.6Mustache template library
Readme
Mustache templates
A Dart library to parse and render mustache templates.
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.6'pubspec.yaml
name: mustache
version: 0.1.6
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
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | ed4ab6fb…bbb413 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | 55219fab…283bb3 |
| 0.1.2 | Cached · Upstream SHA-256 matched | Download | 86679efa…5e7720 |
| 0.1.3 | Cached · Upstream SHA-256 matched | Download | 92a2fcee…825cf8 |
| 0.1.4 | Cached · Upstream SHA-256 matched | Download | 04c94972…0ab0ad |
| 0.1.5 | Cached · Upstream SHA-256 matched | Download | 2d2be5b6…5dd5c0 |
| 0.1.6 | Cached · Upstream SHA-256 matched | Download | ca8409d6…577b2d |
| 0.1.7 | Cached · Upstream SHA-256 matched | Download | e17a32ba…4756be |
| 0.1.8 | Cached · Upstream SHA-256 matched | Download | 0752264e…6ead77 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | f80eeec4…9702f3 |
| 0.2.0+1 | Cached · Upstream SHA-256 matched | Download | dd91018f…41528b |
| 0.2.1 | Cached · Upstream SHA-256 matched | Download | ae6f8e4f…9c4f53 |
| 0.2.2 | Cached · Upstream SHA-256 matched | Download | 79b9addd…7fb3a2 |
| 0.2.3 | Cached · Upstream SHA-256 matched | Download | 0f3d176a…01cf1b |
| 0.2.4 | Cached · Upstream SHA-256 matched | Download | fd345452…6f5f46 |
| 0.2.5 | Cached · Upstream SHA-256 matched | Download | a74fb5f2…510297 |
| 0.2.5+1 | Cached · Upstream SHA-256 matched | Download | f3b958a5…fa40fe |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | ccc823f8…e5d116 |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | 3e5b7462…811be5 |
| 1.0.2 | Cached · Upstream SHA-256 matched | Download | 959cbf25…4c21c2 |
| 1.1.0 | Cached · Upstream SHA-256 matched | Download | be6cde6e…dcd543 |
| 1.1.1 | Cached · Upstream SHA-256 matched | Download | ee510068…878cd8 |
Dependencies
No direct dependencies declared.