add current to the loop variable for .for in templates
authorTony Cook <tony@develop-help.com>
Sat, 2 Mar 2013 00:24:50 +0000 (11:24 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 2 Mar 2013 00:24:50 +0000 (11:24 +1100)
site/cgi-bin/modules/Squirrel/Template.pm
site/cgi-bin/modules/Squirrel/Template/Processor.pm
t/020-templater/040-original.t

index 2c0d75b6cf7b3593c9ab5af320700e75ba0c5387..89592335464fe8ac0ecc1912d970c06d6d965e4e 100644 (file)
@@ -20,7 +20,7 @@ BEGIN {
 
 use constant DEBUG_GET_PARMS => 0;
 
-our $VERSION = "1.025";
+our $VERSION = "1.026";
 
 my %compile_cache;
 
@@ -921,6 +921,10 @@ prev, next - the previous or next element respectively, if any.
 
 list - the list argument to C<.for>.
 
+=item *
+
+current - the current item in the iteration.
+
 =back
 
 =head2 params
index 3bed4796b0437a82e47aa1e53ccf9206c5c29e9b..c8b548c0684032c8c41ad4b36abb6704e024c808 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use Squirrel::Template::Constants qw(:node);
 use Scalar::Util ();
 
-our $VERSION = "1.020";
+our $VERSION = "1.021";
 
 use constant ACTS => 0;
 use constant TMPLT => 1;
@@ -278,6 +278,7 @@ sub _process_for {
   my @result;
   for my $current (@$list) {
     $scope->{$name} = $current;
+    $loop{current} = $current;
     push @result, $self->process($node->[NODE_FOR_CONTENT]);
     ++$index;
   }
index 9e5a93cf82cdedce23cc6d020f61ec8e007de38f..4869b62f203da40ad04292e22c93655d3967eacc 100644 (file)
@@ -556,13 +556,13 @@ IN
 IN
   template_test(<<IN, <<OUT, "simple .for", \%acts, "", \%vars);
 <:.for x in [ "a" .. "d" ] -:>
-Value: <:= x :> Index: <:= loop.index :> Count: <:= loop.count:> Prev: <:= loop.prev :> Next: <:= loop.next :> Even: <:= loop.even :> Odd: <:= loop.odd :> Parity: <:= loop.parity :> is_first: <:= loop.is_first :> is_last: <:= loop.is_last :>-
+Value: <:= x :> Index: <:= loop.index :> Count: <:= loop.count:> Prev: <:= loop.prev :> Next: <:= loop.next :> Even: <:= loop.even :> Odd: <:= loop.odd :> Parity: <:= loop.parity :> is_first: <:= loop.is_first :> is_last: <:= loop.is_last :> Current by index: <:= loop.current :>-
 <:.end-:>
 IN
-Value: a Index: 0 Count: 1 Prev:  Next: b Even:  Odd: 1 Parity: odd is_first: 1 is_last: -
-Value: b Index: 1 Count: 2 Prev: a Next: c Even: 1 Odd:  Parity: even is_first:  is_last: -
-Value: c Index: 2 Count: 3 Prev: b Next: d Even:  Odd: 1 Parity: odd is_first:  is_last: -
-Value: d Index: 3 Count: 4 Prev: c Next:  Even: 1 Odd:  Parity: even is_first:  is_last: 1-
+Value: a Index: 0 Count: 1 Prev:  Next: b Even:  Odd: 1 Parity: odd is_first: 1 is_last:  Current by index: a-
+Value: b Index: 1 Count: 2 Prev: a Next: c Even: 1 Odd:  Parity: even is_first:  is_last:  Current by index: b-
+Value: c Index: 2 Count: 3 Prev: b Next: d Even:  Odd: 1 Parity: odd is_first:  is_last:  Current by index: c-
+Value: d Index: 3 Count: 4 Prev: c Next:  Even: 1 Odd:  Parity: even is_first:  is_last: 1 Current by index: d-
 OUT
   template_test(<<IN, <<OUT, "simple .if", \%acts, "", \%vars);
 <:.if "a" eq "b" :>FAIL<:.else:>SUCCESS<:.end:>