add filters to inline iterator
authorAdrian Oldham <adriann@visualthought.com.au>
Wed, 11 Jan 2012 03:39:55 +0000 (14:39 +1100)
committerTony Cook <tony@develop-help.com>
Wed, 11 Jan 2012 03:57:59 +0000 (14:57 +1100)
TonyC: add test and bump version

site/cgi-bin/modules/Generate.pm
t/t20gen.t

index 969118539b03d0d1d05153ab7e73b68fef0dcfc1..9c507293e105c404e55e985c3d8848c850524d30 100644 (file)
@@ -11,7 +11,7 @@ use BSE::Util::Iterate;
 use base 'BSE::ThumbLow';
 use base 'BSE::TagFormats';
 
-our $VERSION = "1.004";
+our $VERSION = "1.005";
 
 my $excerptSize = 300;
 
@@ -386,8 +386,11 @@ sub iter_all_kids_of {
 }
 
 sub iter_inlines {
-  my ($args, $acts, $name, $templater) = @_;
+  my ($self, $state, $args, $acts, $name, $templater) = @_;
+
+  my $filter = $self->_get_filter(\$args);
 
+  $state->{parentid} = undef;
   my @ids = map { split } DevHelp::Tags->get_parms($args, $acts, $templater);
   for my $id (@ids) {
     unless ($id =~ /^\d+$/) {
@@ -395,7 +398,9 @@ sub iter_inlines {
     }
   }
   @ids = grep /^\d+$/, @ids;
-  map Articles->getByPkey($_), @ids;
+  @ids == 1 and $state->{parentid} = $ids[0];
+
+  $self->_do_filter($filter, map Articles->getByPkey($_), @ids);
 }
 
 sub iter_gimages {
@@ -928,7 +933,11 @@ sub baseActs {
                    plural => 'allkids_of5',
                    nocache => 1,
                    state => 1 ), 
-     $art_it->make_iterator( \&iter_inlines, 'inline', 'inlines' ),
+     $art_it->make( code => [ iter_inlines => $self ],
+                   single => 'inline',
+                   plural => 'inlines',
+                   nocache => 1,
+                   state => 1 ), 
      gimage => 
      sub {
        my ($args, $acts, $func, $templater) = @_;
index d54f753b4954de16f02a02642b1776cebd540d6d..b9147f4621569a21f593f95551b82a2d0c646944 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use BSE::Test ();
-use Test::More tests=>144;
+use Test::More tests=>147;
 use File::Spec;
 use FindBin;
 BEGIN {
@@ -113,6 +113,13 @@ TEMPLATE
 OneTwoThree
 EXPECTED
 
+template_test "inlines filtered", $top, <<TEMPLATE, <<EXPECTED;
+<:iterator begin inlines @kidids filter: [title] =~ /^T/ :><:
+inline title:><:iterator end inlines:>
+TEMPLATE
+TwoThree
+EXPECTED
+
 template_test "ifancestor positive", $kids[0], <<TEMPLATE, <<EXPECTED;
 <:ifAncestor $parent->{id}:>Yes<:or:>No<:eif:>
 TEMPLATE