From f220f103837a2130285826eaeb16356801e85357 Mon Sep 17 00:00:00 2001 From: Charlie Gorichanaz Date: Tue, 24 May 2011 22:03:28 -0500 Subject: [PATCH] NOT IN A WORKABLE STATE: Pushing to GitHub to consult with plugin author Signed-off-by: Charlie Gorichanaz --- LICENSE | 2 +- Makefile.PL | 2 +- README.markdown | 29 +++++++++++++--- plugins/Order/config.yaml | 4 ++- plugins/Order/lib/Order/Plugin.pm | 55 +++++++++++++++++++++++++++---- 5 files changed, 79 insertions(+), 13 deletions(-) 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..af2c1c8 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. @@ -13,6 +13,8 @@ Unarchive into your Movable Type directory. Use the provided template tags to collect and reorder template content. For example: +UPDATE THIS EXAMPLE TO USE DATEHEADER/FOOTER + @@ -113,7 +115,7 @@ set inside the `mt:OrderItem` tag. Set the `order_by` variable by using the `mt:SetVarBlock` tag or the `setvar="variable name"` global attribute on a tag inside the `mt:OrderItem`. -`mt:OrderItem` has one optional attribute: +`mt:OrderItem` has two optional attributes: ### `pin` ### @@ -157,13 +159,32 @@ 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 an `iso8601` timestamp, formatted `%Y-%m-%dT%H:%M:%SZ`. + + +## `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 an `iso8601` timestamp, formatted `%Y-%m-%dT%H:%M:%SZ`. + + # Changes # -## 1.1 in development ## +## 1.2 10 May 2011 ## + +* Added `unique` ordering option. + + +## 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..46181f2 100644 --- a/plugins/Order/config.yaml +++ b/plugins/Order/config.yaml @@ -5,10 +5,12 @@ 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 diff --git a/plugins/Order/lib/Order/Plugin.pm b/plugins/Order/lib/Order/Plugin.pm index ed8d737..c147499 100644 --- a/plugins/Order/lib/Order/Plugin.pm +++ b/plugins/Order/lib/Order/Plugin.pm @@ -52,7 +52,7 @@ sub _sort_group_ids { sub tag_order { my ($ctx, $args, $cond) = @_; - + my %groups = ( items => [] ); local $ctx->{__stash}{order_items} = \%groups; local $ctx->{__stash}{order_by_var} = $args->{by} || 'order_by'; @@ -67,7 +67,7 @@ sub tag_order { my $items = delete $groups{items}; my $sort = sort_function_for_args($args); my @objs = $sort->(@$items); - + # Inject the pinned groups from first place (0) to last (-1). for my $i (sort _sort_group_ids keys %groups) { my $items = $groups{$i}; @@ -84,7 +84,13 @@ sub tag_order { push @objs, $sort->(@$items); } } - + + # Mark said to put header/footer logic here, but I put further down + # so limiting and offsets could be taken care of first. We don't want + # to break styles dependent on the header and footer being in place. + + # But now I realize we lost the date information by the collapse... + # Collapse the transform. @objs = map { $_->[1] } @objs; @@ -100,6 +106,28 @@ sub tag_order { } } + # $objs[x] is OrderItem content + + # loop over items in @objs adding headers and footers where necessary + if ($ctx->stash('order_date_header') || $ctx->stash('order_date_footer')) { + MT::log("$#objs"); + MT::log($objs[0]); MT::log($objs[1]); MT::log($objs[2]); + + my $current_date; # hold date to compare against + + if ($ctx->stash('order_date_header')) { + # I don't know how to properly slurp() on the next line to get it to + # use the current order item's context. + # unshift(@objs, $ctx->stash('order_date_header')); + } + + } + + { + my $debug6 = 1; + MT::log('Order plugin ran at '.scalar localtime()) if ($debug6); + } + return q{} if !@objs; return join q{}, $ctx->stash('order_header'), @objs, $ctx->stash('order_footer'); @@ -121,9 +149,21 @@ sub tag_order_footer { return q{}; } -sub tag_order_item { +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) = @_; + my $group_id = defined $args->{pin} ? int $args->{pin} : 'items'; my $order_var = $ctx->stash('order_by_var'); @@ -133,10 +173,13 @@ sub tag_order_item { my $order_value = $ctx->var($order_var) || q{}; $order_value =~ s{ \A \s+ | \s+ \z }{}xmsg; - + + my $is_unique = defined $args->{unique} ? true : false; + my $groups = $ctx->stash('order_items'); my $group = ($groups->{$group_id} ||= []); - push @$group, [ $order_value, $output ]; + push @$group, [ $order_value, $output, $is_unique ]; + } 1;