diff --git a/README.markdown b/README.markdown index 58c5eb1..e9f0914 100644 --- a/README.markdown +++ b/README.markdown @@ -18,7 +18,7 @@ example, to show the last 30 unique entries and ActionStreams items:
- +

@@ -56,6 +56,33 @@ example, to show the last 30 unique entries and ActionStreams items: +Another example illustrating handling of rows: An image gallery, ordered by the asset label, with a header and footer for each row of 3. + + + + + + + + + + + <$mt:AssetLabel$> + + +
+
" />
+
<$mt:AssetLabel$>
+
+ <$mt:AssetDescription convert_breaks="0" filters="__default__"$> +
+
+
+
# Template tags # @@ -194,8 +221,32 @@ A function tag that works like an `mt:Date` tag, for use within `mt:OrderDateHea and `mt:OrderDateFooter` blocks. Does not take a `utc` attribute. +## `items_per_row` ## + +This attribute of `mt:Order`sets how many iterations the Assets tag publishes before setting +the state that enables the `mt:OrderRowHeader` and `mt:OrderRowFooter` tags. + + +## `mt:OrderRowHeader` ## + +A container tag whose contents will be displayed before the `mt:OrderItem` in context +if it is the first item for a given row. Requires `items_per_row` integer attribute set inside the +`mt:Order` tag. + + +## `mt:OrderRowFooter` ## + +A container tag whose contents will be displayed after the `mt:OrderItem` in context +if it is the last item for a given row. Requires `items_per_row` integer attribute set inside the +`mt:Order` tag. + # Changes # +## 1.3 22 November 2011 ## + +* Added `itens_per_row` attribute to the `mt:Order` tag. +* Added `mt:OrderRowHeader` and `mt:OrderRowFooter` tags. + ## 1.2 10 October 2011 ## * Added `mt:OrderDateHeader` and `mt:OrderDateFooter` tags. diff --git a/plugins/Order/config.yaml b/plugins/Order/config.yaml index 737baa2..cf7e1b8 100644 --- a/plugins/Order/config.yaml +++ b/plugins/Order/config.yaml @@ -5,7 +5,7 @@ description: Collect sets of template output to order by a particular datum. author_name: Mark Paschal author_link: http://markpasc.org/mark/ plugin_link: http://plugins.movabletype.org/order/ -version: 1.2 +version: 1.3 tags: block: Order: $Order::Order::Plugin::tag_order @@ -14,5 +14,7 @@ tags: OrderFooter: $Order::Order::Plugin::tag_order_footer OrderDateHeader: $Order::Order::Plugin::tag_order_date_header OrderDateFooter: $Order::Order::Plugin::tag_order_date_footer + OrderRowHeader: $Order::Order::Plugin::tag_order_row_header + OrderRowFooter: $Order::Order::Plugin::tag_order_row_footer function: OrderDate: $Order::Order::Plugin::_hdlr_order_date diff --git a/plugins/Order/lib/Order/Plugin.pm b/plugins/Order/lib/Order/Plugin.pm index a48085c..0e5922e 100644 --- a/plugins/Order/lib/Order/Plugin.pm +++ b/plugins/Order/lib/Order/Plugin.pm @@ -57,6 +57,8 @@ sub tag_order { local $ctx->{__stash}{order_by_var} = $args->{by} || 'order_by'; local $ctx->{__stash}{order_header} = q{}; local $ctx->{__stash}{order_footer} = q{}; + local $ctx->{__stash}{order_row_header} = q{}; + local $ctx->{__stash}{order_row_footer} = q{}; # Build, but ignore the full build value. defined($ctx->slurp($args, $cond)) @@ -133,6 +135,24 @@ sub tag_order { # Collapse the transform. @objs = map { $_->[1] } @objs; + # Insert the row header and footers + my $per_row = $args->{'items_per_row'} || 0; + if ($per_row) { + my $order_row_header = $ctx->stash('order_row_header') || ''; + my $order_row_footer = $ctx->stash('order_row_footer') || ''; + $in_position = $per_row - 1; + my $row_count = 0; + my $total_count = @objs; + my $insert = $order_row_footer . $order_row_header; + while ($in_position < $total_count - 1) { + @objs = array_insert_after_position ( \@objs, $in_position, $insert); + $in_position += $per_row + 1; + $total_count += 1; + } + unshift(@objs,$order_row_header) if ($order_row_header); + push(@objs,$order_row_footer) if ($order_row_footer); + } + return q{} if !@objs; return join q{}, $ctx->stash('order_header'), @objs, $ctx->stash('order_footer'); @@ -166,6 +186,40 @@ sub tag_order_date_footer { return q{}; } +sub tag_order_row_header { + my ($ctx, $args, $cond) = @_; + my $output = $ctx->slurp($args, $cond) + or return; + $ctx->stash('order_row_header', $output); + return q{}; +} + +sub tag_order_row_footer { + my ($ctx, $args, $cond) = @_; + my $output = $ctx->slurp($args, $cond) + or return; + $ctx->stash('order_row_footer', $output); + return q{}; +} + +# insert element into an arbitrary position of an array +sub array_insert_after_position { + my ($inArray, $inPosition, $inElement) = @_; + my @res = (); + my @after = (); + my $arrayLength = int @{$inArray}; + + if ($inPosition < 0) { @after = @{$inArray}; } + else { + if ($inPosition >= $arrayLength) { $inPosition = $arrayLength - 1; } + if ($inPosition < $arrayLength - 1) { @after = @{$inArray}[($inPosition+1)..($arrayLength-1)]; } + } + + push (@res, @{$inArray}[0..$inPosition], $inElement, @after); + + return @res; +} + sub tag_order_item { my ($ctx, $args, $cond) = @_;