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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Handlebars;
{ local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { };
render_ok(
{
helpers => {
noop => sub {
my ($context, $options) = @_;
return $options->{fn}->($context);
},
},
},
'<h1>{{title}}</h1><p>{{#noop}}{{body}}{{/noop}}</p>',
{ title => 'A', body => 'the first letter' },
'<h1>A</h1><p>the first letter</p>',
"noop helper"
);
render_ok(
{
helpers => {
list => sub {
my ($items, $options) = @_;
my $out = "<ul>";
for my $item (@$items) {
$out .= "<li>" . $options->{fn}->($item) . "</li>";
}
return $out . "</ul>";
},
},
},
'{{#list people}}{{firstName}} {{lastName}}{{/list}}',
{ people => [
{ firstName => 'Jesse', lastName => 'Luehrs' },
{ firstName => 'Shawn', lastName => 'Moore' },
{ firstName => 'Stevan', lastName => 'Little' },
] },
'<ul><li>Jesse Luehrs</li><li>Shawn Moore</li><li>Stevan Little</li></ul>',
"helpers with arguments"
);
}
done_testing;
|