From e8a83edb85216a9f6978a99c77cc196db5cb4c44 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 5 Oct 2012 12:31:26 -0500 Subject: implement {{^}} as an alias for {{else}} --- t/block-helpers.t | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 't/block-helpers.t') diff --git a/t/block-helpers.t b/t/block-helpers.t index 961b2dc..ac6f54f 100644 --- a/t/block-helpers.t +++ b/t/block-helpers.t @@ -375,4 +375,98 @@ RENDERED ); } +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + + if (@$items) { + my $out = ''; + return $out; + } + else { + return '

' . $options->{inverse}->($context) . '

'; + } + }, + }, + }, + q[{{#list people}}{{name}}{{^}}Nobody's here{{/list}}], + { + people => [ + { name => 'Alan' }, + { name => 'Yehuda' }, + ], + }, + q[], + "helper with inverse" +); + +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + + if (@$items) { + my $out = ''; + return $out; + } + else { + return '

' . $options->{inverse}->($context) . '

'; + } + }, + }, + }, + q[{{#list people}}{{name}}{{^}}Nobody's here{{/list}}], + { + people => [], + }, + q[

Nobody's here

], + "helper with inverse (empty)" +); + +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + + if (@$items) { + my $out = ''; + return $out; + } + else { + return '

' . $options->{inverse}->($context) . '

'; + } + }, + }, + }, + q[{{#list people}}Hello{{^}}{{message}}{{/list}}], + { + people => [], + message => "Nobody's here", + }, + q[

Nobody's here

], + "helper with inverse (inverse has variables)" +); + done_testing; -- cgit v1.2.3-54-g00ecf