Skip to content

Commit

Permalink
NOT IN A WORKABLE STATE: Pushing to GitHub to consult with plugin author
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Gorichanaz <[email protected]>
  • Loading branch information
CNG committed May 25, 2011
1 parent 8f14966 commit f220f10
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use ExtUtils::MakeMaker;

WriteMakefile(
NAME => 'Order',
VERSION => '1.1',
VERSION => '1.2',
DISTNAME => 'Order',
);
29 changes: 25 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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

<mt:Order>

<mt:OrderHeader>
Expand Down Expand Up @@ -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` ###

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion plugins/Order/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 49 additions & 6 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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};
Expand All @@ -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;

Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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;
Expand Down

0 comments on commit f220f10

Please sign in to comment.