Skip to content
This repository was archived by the owner on Oct 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ example, to show the last 30 unique entries and ActionStreams items:
<mt:OrderHeader>
<div class="site-activity">
</mt:OrderHeader>

<mt:OrderDateHeader>
<div id="one_day">
<p class="date"><mt:OrderDate format="%B %e, %Y"></p>
Expand Down Expand Up @@ -56,6 +56,33 @@ example, to show the last 30 unique entries and ActionStreams items:

</mt:Order>

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:Order sort_order="ascend" items_per_row="3">
<mt:OrderRowHeader>
<div class="gallery">
</mt:OrderRowHeader>

<mt:OrderRowFooter>
</div>
</mt:OrderRowFooter>

<mt:Assets type="image" tag="$gallery_tag">
<mt:OrderItem>

<mt:setvarblock name="order_by">
<$mt:AssetLabel$>
</mt:setvarblock>

<dl>
<dt><img src="<$mt:AssetThumbnailURL width="144"$>" /></dt>
<dt><$mt:AssetLabel$></dt>
<dd>
<$mt:AssetDescription convert_breaks="0" filters="__default__"$>
</dd>
</dl>
</mt:OrderItem></mt:Assets>
</mt:Order>

# Template tags #

Expand Down Expand Up @@ -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.
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,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
Expand All @@ -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
54 changes: 54 additions & 0 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) = @_;

Expand Down