commit | b17787e799d7f16cad593f5aee2e2c1ed244dc99 | [log] [tgz] |
---|---|---|
author | Yoryos Valotasios <valotas@gmail.com> | Wed Aug 28 21:16:27 2013 |
committer | Yoryos Valotasios <valotas@gmail.com> | Wed Aug 28 21:16:27 2013 |
tree | 074c3ba37ebbad36245990c3e2518a2d6e652233 | |
parent | 726f1bcbdd1b803908a82ec71ada3e6982de0627 [diff] |
Version 0.0.19
A simple implementation of Mustache for the Dart language. This project started as an excuse for exploring the language itself, but the final result, passes happily all the mustache specs. If you want to have a look at how it works, just check the tests. For more info, just read further.
In order to use the library, just add it to your pubspec.yalm as a dependency
dependencies: mustache4dart: any
and you are good to go. You can use the render toplevel function to render your template. For example:
var salutation = render('Hello {{name}}!', {'name': 'Bob'}); print(salutation); //shoud print Hello Bob!
mustache4dart will look at your given object for operators, fields or methods. For example, if you give the template {{firstname}}
for rendering, mustache4dart will try the followings
[]
operator with firstname
as the parameterfirstname
firstname
firstname
getFirstname
in each case the first valid value will be used.
As a sidenote, you will get the best performance if you provide a proper implementation of the []
operator.
mustache4dart support partials but it needs somehow to know how to find a partial. You can do that by providing a function that returns a template given a name:
String partialProvider(String partialName) => "this is the partial with name: ${partialName}"; expect(render('[{{>p}}]', null, partial: partialProvider), '[this is the partial with name: p]'));
If you have a template that you are going to reuse with different contextes you can compile it to a function using the toplevel function compile:
var salut = compile('Hello {{name}}!'); print(salut({'name': 'Alice'})); //should print Hello Alice!
At the moment the project is under heavy development but pass all the Mustache specs. If you want to run the tests yourself, just do what drone.io does, or to put it by another way, do the following:
git clone git://github.com/valotas/mustache4dart.git git submodule init git submodule update pub install test/run.sh
If you found a bug, just create a new issue or even better fork and issue a pull request with you fix.
The library will follow a semantic versioning and until a final release of the language will be followed by the latest dart language it has been tested against. For example 0.0.7+0.4.1.0 means that the libraries version is 0.0.7 and has been tested against dart version 0.4.1.0
You can find most of the mustache implementations at the mustache homepage. Apart from them, there is another implementation for the dartlang that can be found at https://github.com/xxgreg/mustache