-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples copied from README, fixed README
- Loading branch information
1 parent
8f12449
commit a08bb7d
Showing
5 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:mustache/mustache.dart'; | ||
|
||
main() { | ||
var source = ''' | ||
{{# names }} | ||
<div>{{ lastname }}, {{ firstname }}</div> | ||
{{/ names }} | ||
{{^ names }} | ||
<div>No names.</div> | ||
{{/ names }} | ||
{{! I am a comment. }} | ||
'''; | ||
|
||
var template = new Template(source, name: 'template-filename.html'); | ||
|
||
var output = template.renderString({'names': [ | ||
{'firstname': 'Greg', 'lastname': 'Lowe'}, | ||
{'firstname': 'Bob', 'lastname': 'Johnson'} | ||
]}); | ||
|
||
print(output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:mustache/mustache.dart'; | ||
|
||
main() { | ||
var t = new Template('{{ foo }}'); | ||
var lambda = (_) => 'bar'; | ||
var output = t.renderString({'foo': lambda}); // bar | ||
print(output); | ||
|
||
t = new Template('{{# foo }}hidden{{/ foo }}'); | ||
lambda = (_) => 'shown'; | ||
output = t.renderString({'foo': lambda}); // shown | ||
print(output); | ||
|
||
t = new Template('{{# foo }}oi{{/ foo }}'); | ||
lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
output = t.renderString({'foo': lambda}); // <b>OI</b> | ||
print(output); | ||
|
||
t = new Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
output = t.renderString({'foo': lambda, 'bar': 'pub'}); // <b>PUB</b> | ||
print(output); | ||
|
||
t = new Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
lambda = (LambdaContext ctx) => '<b>${ctx.renderString().toUpperCase()}</b>'; | ||
output = t.renderString({'foo': lambda, 'bar': 'pub'}); // <b>PUB</b> | ||
print(output); | ||
|
||
t = new Template('{{# foo }}{{bar}}{{/ foo }}'); | ||
lambda = (LambdaContext ctx) => ctx.renderSource(ctx.source + '{{cmd}}'); | ||
output = t.renderString({'foo': lambda, 'bar': 'pub', 'cmd': 'build'}); // pub build | ||
print(output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:mustache/mustache.dart'; | ||
|
||
main() { | ||
var template = new Template('{{ author.name }}'); | ||
var output = template.renderString({'author': {'name': 'Greg Lowe'}}); | ||
print(output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:mustache/mustache.dart'; | ||
|
||
main() { | ||
var partial = new Template('{{ foo }}', name: 'partial'); | ||
|
||
var resolver = (String name) { | ||
if (name == 'partial-name') { // Name of partial tag. | ||
return partial; | ||
} | ||
}; | ||
|
||
var t = new Template('{{> partial-name }}', partialResolver: resolver); | ||
|
||
var output = t.renderString({'foo': 'bar'}); // bar | ||
print(output); | ||
} |