-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathlambdas.dart
33 lines (27 loc) · 1.19 KB
/
lambdas.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'package:mustache/mustache.dart';
main() {
var t = new Template('{{ foo }}');
Function 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);
}