From 3b27f46a2bd3ce3d2a5a1b3f13b3c68f6a41e9ec Mon Sep 17 00:00:00 2001 From: Shawn M Moore Date: Tue, 25 Sep 2012 17:20:21 -0400 Subject: Custom helper blocks --- t/004-helpers.t | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 t/004-helpers.t (limited to 't') diff --git a/t/004-helpers.t b/t/004-helpers.t new file mode 100644 index 0000000..3d39755 --- /dev/null +++ b/t/004-helpers.t @@ -0,0 +1,45 @@ +use strict; +use warnings; +use Test::More; +use Text::Xslate; + +my $tx = Text::Xslate->new(syntax => 'Handlebars'); + +# XXX I'm not sure how helpers should be registered in Perl +# in JS, it's global which is crappy +Handlebars->registerHelper(noop => sub { + my ($context, $options) = @_; + return $options->{fn}->($context); +}); + +is( + $tx->render_string( + '

{{title}}

{{#noop}}{{body}}{{/noop}}

', + { title => 'A', body => 'the first letter' }, + ), + '

A

the first letter

', +); + +Handlebars->registerHelper(list => sub { + my ($items, $options) = @_; + my $out = ""; +}); + +is( + $tx->render_string( + '{{#list people}}{{firstName}} {{lastName}}{{/list}}', + { people => [ + { firstName => 'Jesse', lastName => 'Luehrs' }, + { firstName => 'Shawn', lastName => 'Moore' }, + { firstName => 'Stevan', lastName => 'Little' }, + ] }, + ), + '', +); + -- cgit v1.2.3-54-g00ecf