diff --git a/LICENSE b/LICENSE index 2f290a2..7217050 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Order 1.1 for Movable Type +Order 1.2 for Movable Type Copyright 2008-2009 Six Apart, Ltd. All rights reserved. diff --git a/Makefile.PL b/Makefile.PL index 77983d7..046ad70 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -2,6 +2,6 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Order', - VERSION => '1.1', + VERSION => '1.2', DISTNAME => 'Order', ); diff --git a/README.markdown b/README.markdown index 2f2802c..58c5eb1 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -# Order 1.1 for Movable Type # +# Order 1.2 for Movable Type # Collect sets of template output to order by a particular datum. @@ -11,32 +11,45 @@ Unarchive into your Movable Type directory. # Usage # Use the provided template tags to collect and reorder template content. For -example: +example, to show the last 30 unique entries and ActionStreams items: - +
- + +
+

+ + + +
+ + + - + - - - - - - - - - + + + + + + + <$mt:StreamActionDate format="%Y%m%d%H%M%S"$> + +

">_16.png" width="12" height="12"> " class="actionlink">

+
+
+
+
@@ -157,13 +170,38 @@ even an `mt:OrderItem` pinned to the front with the `pin="0"` attribute. Contains template content that is displayed at the end of the `mt:Order` loop, as long as there are `mt:OrderItem`s to display. -Content from an `mt:OrderFooter` is shown after the last `mt:OrderItem`, or +Content from an `mt:OrderFooter` is shown after the last `mt:OrderItem`, even an `mt:OrderItem` pinned to the end with the `pin="-1"` attribute. +## `mt:OrderDateHeader` ## + +A container tag whose contents will be displayed before the `mt:OrderItem` in context +if it is the first item for a given day. Requires `order_by` variable set inside the +`mt:OrderItem` tag to be a timestamp formatted `%Y%m%d%H%M%S`. + + +## `mt:OrderDateFooter` ## + +A container tag whose contents will be displayed after the `mt:OrderItem` in context +if it is the last item for a given day. Requires `order_by` variable set inside the +`mt:OrderItem` tag to be a timestamp formatted `%Y%m%d%H%M%S`. + + +## `mt:OrderDate` ## + +A function tag that works like an `mt:Date` tag, for use within `mt:OrderDateHeader` +and `mt:OrderDateFooter` blocks. Does not take a `utc` attribute. + + # Changes # -## 1.1 in development ## +## 1.2 10 October 2011 ## + +* Added `mt:OrderDateHeader` and `mt:OrderDateFooter` tags. +* Added `mt:OrderDate` tag. + +## 1.1 10 June 2010 ## * Added `mt:OrderHeader` and `mt:OrderFooter` tags. * Added `shuffle` ordering option. diff --git a/plugins/Order/config.yaml b/plugins/Order/config.yaml index 4616a1f..737baa2 100644 --- a/plugins/Order/config.yaml +++ b/plugins/Order/config.yaml @@ -5,10 +5,14 @@ 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.1 +version: 1.2 tags: block: Order: $Order::Order::Plugin::tag_order OrderItem: $Order::Order::Plugin::tag_order_item OrderHeader: $Order::Order::Plugin::tag_order_header OrderFooter: $Order::Order::Plugin::tag_order_footer + OrderDateHeader: $Order::Order::Plugin::tag_order_date_header + OrderDateFooter: $Order::Order::Plugin::tag_order_date_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 ed8d737..a48085c 100644 --- a/plugins/Order/lib/Order/Plugin.pm +++ b/plugins/Order/lib/Order/Plugin.pm @@ -1,4 +1,3 @@ - package Order::Plugin; sub _natural_sort { @@ -85,9 +84,6 @@ sub tag_order { } } - # Collapse the transform. - @objs = map { $_->[1] } @objs; - if (my $offset = $args->{offset}) { # Delete the first $offset items. splice @objs, 0, $offset; @@ -100,6 +96,43 @@ sub tag_order { } } + if ($ctx->stash('order_date_header') || $ctx->stash('order_date_footer')) { + # loop over items in @objs adding headers and footers where necessary + my $builder = $ctx->stash('builder'); + my ($yesterday, $tomorrow) = ('00000000')x2; + my $i = 0; + for my $o (@objs) { + my $today = substr $o->[0], 0, 8; + my $tomorrow = $today; + my $footer = 0; + if (defined $objs[$i+1]) { + $tomorrow = substr($objs[$i+1]->[0], 0, 8); + $footer = $today ne $tomorrow; + } else { + $footer++; + } + my $header = $today ne $yesterday; + local $ctx->{current_timestamp} = $o->[0]; + my ($h_html, $f_html) = ('')x2; + if ($header && $ctx->stash('order_date_header')) { + my $result = $builder->build($ctx, $ctx->stash('order_date_header'), {}); + return $ctx->error( $builder->errstr ) unless defined $result; + $h_html = $result; + } + if ($footer && $ctx->stash('order_date_footer')) { + my $result = $builder->build($ctx, $ctx->stash('order_date_footer'), {}); + return $ctx->error( $builder->errstr ) unless defined $result; + $f_html = $result; + } + $objs[$i][1] = $h_html.$o->[1].$f_html; + $yesterday = $today; + $i++; + } + } + + # Collapse the transform. + @objs = map { $_->[1] } @objs; + return q{} if !@objs; return join q{}, $ctx->stash('order_header'), @objs, $ctx->stash('order_footer'); @@ -121,6 +154,18 @@ sub tag_order_footer { return q{}; } +sub tag_order_date_header { + my ($ctx, $args, $cond) = @_; + $ctx->stash('order_date_header', $ctx->stash('tokens')); + return q{}; +} + +sub tag_order_date_footer { + my ($ctx, $args, $cond) = @_; + $ctx->stash('order_date_footer', $ctx->stash('tokens')); + return q{}; +} + sub tag_order_item { my ($ctx, $args, $cond) = @_; @@ -136,8 +181,18 @@ sub tag_order_item { my $groups = $ctx->stash('order_items'); my $group = ($groups->{$group_id} ||= []); - push @$group, [ $order_value, $output ]; + push @$group, [ $order_value, $output]; } -1; +sub _hdlr_order_date { + my ($ctx, $args) = @_; + # Order dates are already UTC (or at least shouldn't be messed with after ordering). + if ($args->{utc}) { + my $tag = $ctx->stash('tag'); + return $ctx->error(qq{The mt:$tag doesn't support a utc attribute: items were already ordered by these dates, so can't readjust them for UTC after the fact.}); + } + return $ctx->_hdlr_date($args); +} + +1;