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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/blocks.t | 45 ++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) (limited to '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; diff --git a/t/blocks.t b/t/blocks.t index e34ef36..153a8a9 100644 --- a/t/blocks.t +++ b/t/blocks.t @@ -70,4 +70,49 @@ render_ok( "empty block" ); +{ local $TODO = "unimplemented"; +render_ok( + '{{#people}}{{name}}{{^}}{{none}}{{/people}}', + { + none => 'No people', + }, + 'No people', + "inverted block shorthand" +); + +render_ok( + '{{#people}}{{name}}{{^}}{{none}}{{/people}}', + { + none => 'No people', + people => [], + }, + 'No people', + "inverted block shorthand (empty array)" +); + +render_ok( + <<'TEMPLATE', +{{#people}} +{{name}} +{{^}} +{{none}} +{{/people}} +TEMPLATE + { + none => 'No people', + people => [ + 'Jesse Luehrs', + 'Shawn Moore', + 'Stevan Little', + ], + }, + <<'RENDERED', +Jesse Luehrs +Shawn Moore +Stevan Little +RENDERED + "inverted block shorthand (non-empty array)" +); +} + done_testing; -- cgit v1.2.3-54-g00ecf