#!/usr/bin/env perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Handlebars;
use Text::Xslate 'mark_raw';
render_ok(
{
helpers => {
link => sub {
my ($context, $object) = @_;
return mark_raw(
""
. $object->{text}
. ""
);
},
},
},
<<'TEMPLATE',
{{{link story}}}
TEMPLATE
{
story => {
url => 'http://example.com/',
text => "
It's an example!
",
},
},
<<'RENDERED',
It's an example!
RENDERED
"basic helpers"
);
render_ok(
{
helpers => {
link => sub {
my ($context, $text, $url) = @_;
return mark_raw(
"" . $text . ""
);
},
},
},
<<'TEMPLATE',
{{{link "See more..." story.url}}}
TEMPLATE
{
story => {
url => 'http://example.com/',
},
},
<<'RENDERED',
See more...
RENDERED
"helpers with literal args"
);
{ local $TODO = "unimplemented";
render_ok(
{
helpers => {
link => sub {
my ($context, $text, $options) = @_;
my @attrs;
for my $key (sort keys %$options) {
push @attrs, $key . '="' . $options->{$key} . '"';
}
return mark_raw(
"" . $text . ""
);
},
},
},
<<'TEMPLATE',
{{{link "See more..." href=story.url class="story"}}}
TEMPLATE
{
story => {
url => 'http://example.com/',
},
},
<<'RENDERED',
See more...
RENDERED
"helpers with literal args"
);
}
done_testing;