From 49db5f5704835b7336c67ecf4ba14a5a5f3a8527 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 28 Sep 2012 17:33:47 -0500 Subject: remove test numbers --- t/helpers.t | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 t/helpers.t (limited to 't/helpers.t') diff --git a/t/helpers.t b/t/helpers.t new file mode 100644 index 0000000..55b3b5a --- /dev/null +++ b/t/helpers.t @@ -0,0 +1,47 @@ +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 +# Text::Xslate->new has a "function" parameter for registering helpers +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' }, + ] }, + ), + '', +); + +done_testing; -- cgit v1.2.3-54-g00ecf