]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge tag '3.20120202' into trail3-integrated
authorSimon McVittie <smcv@debian.org>
Sun, 18 Mar 2012 15:31:41 +0000 (15:31 +0000)
committerSimon McVittie <smcv@debian.org>
Sun, 18 Mar 2012 15:31:41 +0000 (15:31 +0000)
IkiWiki/Plugin/trail.pm [new file with mode: 0644]
auto-blog.setup
doc/examples/blog/posts.mdwn
doc/style.css
doc/templates.mdwn
t/trail.t [new file with mode: 0755]
templates/page.tmpl
templates/trails.tmpl [new file with mode: 0644]
themes/actiontabs/style.css
themes/blueview/style.css

diff --git a/IkiWiki/Plugin/trail.pm b/IkiWiki/Plugin/trail.pm
new file mode 100644 (file)
index 0000000..5ee1521
--- /dev/null
@@ -0,0 +1,477 @@
+#!/usr/bin/perl
+# Copyright © 2008-2011 Joey Hess
+# Copyright © 2009-2011 Simon McVittie <http://smcv.pseudorandom.co.uk/>
+# Licensed under the GNU GPL, version 2, or any later version published by the
+# Free Software Foundation
+package IkiWiki::Plugin::trail;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+       hook(type => "getsetup", id => "trail", call => \&getsetup);
+       hook(type => "needsbuild", id => "trail", call => \&needsbuild);
+       hook(type => "preprocess", id => "trailoptions", call => \&preprocess_trailoptions, scan => 1);
+       hook(type => "preprocess", id => "trailinline", call => \&preprocess_trailinline, scan => 1);
+       hook(type => "preprocess", id => "trailitem", call => \&preprocess_trailitem, scan => 1);
+       hook(type => "preprocess", id => "trailitems", call => \&preprocess_trailitems, scan => 1);
+       hook(type => "preprocess", id => "traillink", call => \&preprocess_traillink, scan => 1);
+       hook(type => "pagetemplate", id => "trail", call => \&pagetemplate);
+}
+
+=head1 Page state
+
+If a page C<$T> is a trail, then it can have
+
+=over
+
+=item * C<$pagestate{$T}{trail}{contents}>
+
+Reference to an array of lists each containing either:
+
+=over
+
+=item * C<[link, "link"]>
+
+A link specification, pointing to the same page that C<[[link]]> would select
+
+=item * C<[pagespec, "posts/*", "age", 0]>
+
+A match by pagespec; the third array element is the sort order and the fourth
+is whether to reverse sorting
+
+=back
+
+=item * C<$pagestate{$T}{trail}{sort}>
+
+A [[ikiwiki/pagespec/sorting]] order; if absent or undef, the trail is in
+the order given by the links that form it
+
+=item * C<$pagestate{$T}{trail}{circular}>
+
+True if this trail is circular (i.e. going "next" from the last item is
+allowed, and takes you back to the first)
+
+=item * C<$pagestate{$T}{trail}{reverse}>
+
+True if C<sort> is to be reversed.
+
+=back
+
+If a page C<$M> is a member of a trail C<$T>, then it has
+
+=over
+
+=item * C<$pagestate{$M}{trail}{item}{$T}[0]>
+
+The page before this one in C<$T> at the last rebuild, or undef.
+
+=item * C<$pagestate{$M}{trail}{item}{$T}[1]>
+
+The page after this one in C<$T> at the last refresh, or undef.
+
+=back
+
+=cut
+
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => undef,
+               },
+}
+
+sub needsbuild (@) {
+       my $needsbuild=shift;
+       foreach my $page (keys %pagestate) {
+               if (exists $pagestate{$page}{trail}) {
+                       if (exists $pagesources{$page} &&
+                           grep { $_ eq $pagesources{$page} } @$needsbuild) {
+                               # Remove state, it will be re-added
+                               # if the preprocessor directive is still
+                               # there during the rebuild. {item} is the
+                               # only thing that's added for items, not
+                               # trails, and it's harmless to delete that -
+                               # the item is being rebuilt anyway.
+                               delete $pagestate{$page}{trail};
+                       }
+               }
+       }
+       return $needsbuild;
+}
+
+my $scanned = 0;
+
+sub preprocess_trailoptions (@) {
+       my %params = @_;
+
+       if (exists $params{circular}) {
+               $pagestate{$params{page}}{trail}{circular} =
+                       IkiWiki::yesno($params{circular});
+       }
+
+       if (exists $params{sort}) {
+               $pagestate{$params{page}}{trail}{sort} = $params{sort};
+       }
+
+       if (exists $params{reverse}) {
+               $pagestate{$params{page}}{trail}{reverse} = $params{reverse};
+       }
+
+       return "";
+}
+
+sub preprocess_trailinline (@) {
+       my %params = @_;
+
+       if (! exists $params{sort}) {
+               # sort in the same order as [[plugins/inline]]'s default
+               $params{sort} = 'age';
+       }
+
+       if (defined wantarray) {
+               scalar preprocess_trailitems(%params);
+
+               if (IkiWiki->can("preprocess_inline")) {
+                       return IkiWiki::preprocess_inline(@_);
+               }
+               else {
+                       error("trailinline directive requires the inline plugin");
+               }
+       }
+       else {
+               preprocess_trailitems(%params);
+       }
+}
+
+sub preprocess_trailitem (@) {
+       my $link = shift;
+       shift;
+
+       # avoid collecting everything in the preprocess stage if we already
+       # did in the scan stage
+       if (defined wantarray) {
+               return "" if $scanned;
+       }
+       else {
+               $scanned = 1;
+       }
+
+       my %params = @_;
+       my $trail = $params{page};
+
+       $link = linkpage($link);
+
+       add_link($params{page}, $link, 'trail');
+       push @{$pagestate{$params{page}}{trail}{contents}}, [link => $link];
+
+       return "";
+}
+
+sub preprocess_trailitems (@) {
+       my %params = @_;
+
+       # avoid collecting everything in the preprocess stage if we already
+       # did in the scan stage
+       if (defined wantarray) {
+               return "" if $scanned;
+       }
+       else {
+               $scanned = 1;
+       }
+
+       # trail members from a pagespec ought to be in some sort of order,
+       # and path is a nice obvious default
+       $params{sort} = 'path' unless exists $params{sort};
+       $params{reverse} = 'no' unless exists $params{reverse};
+
+       if (exists $params{pages}) {
+               push @{$pagestate{$params{page}}{trail}{contents}},
+                       ["pagespec" => $params{pages}, $params{sort},
+                               IkiWiki::yesno($params{reverse})];
+       }
+
+       if (exists $params{pagenames}) {
+               my @list = map { [link =>  $_] } split ' ', $params{pagenames};
+               push @{$pagestate{$params{page}}{trail}{contents}}, @list;
+       }
+
+       return "";
+}
+
+sub preprocess_traillink (@) {
+       my $link = shift;
+       shift;
+
+       my %params = @_;
+       my $trail = $params{page};
+
+       $link =~ qr{
+                       (?:
+                               ([^\|]+)        # 1: link text
+                               \|              # followed by |
+                       )?                      # optional
+
+                       (.+)                    # 2: page to link to
+               }x;
+
+       my $linktext = $1;
+       $link = linkpage($2);
+
+       add_link($params{page}, $link, 'trail');
+
+       # avoid collecting everything in the preprocess stage if we already
+       # did in the scan stage
+       my $already;
+       if (defined wantarray) {
+               $already = $scanned;
+       }
+       else {
+               $scanned = 1;
+       }
+
+       push @{$pagestate{$params{page}}{trail}{contents}}, [link => $link] unless $already;
+
+       if (defined $linktext) {
+               $linktext = pagetitle($linktext);
+       }
+
+       if (exists $params{text}) {
+               $linktext = $params{text};
+       }
+
+       if (defined $linktext) {
+               return htmllink($trail, $params{destpage},
+                       $link, linktext => $linktext);
+       }
+
+       return htmllink($trail, $params{destpage}, $link);
+}
+
+# trail => [member1, member2]
+my %trail_to_members;
+# member => { trail => [prev, next] }
+# e.g. if %trail_to_members = (
+#      trail1 => ["member1", "member2"],
+#      trail2 => ["member0", "member1"],
+# )
+#
+# then $member_to_trails{member1} = {
+#      trail1 => [undef, "member2"],
+#      trail2 => ["member0", undef],
+# }
+my %member_to_trails;
+
+# member => 1
+my %rebuild_trail_members;
+
+sub trails_differ {
+       my ($old, $new) = @_;
+
+       foreach my $trail (keys %$old) {
+               if (! exists $new->{$trail}) {
+                       return 1;
+               }
+               my ($old_p, $old_n) = @{$old->{$trail}};
+               my ($new_p, $new_n) = @{$new->{$trail}};
+               $old_p = "" unless defined $old_p;
+               $old_n = "" unless defined $old_n;
+               $new_p = "" unless defined $new_p;
+               $new_n = "" unless defined $new_n;
+               if ($old_p ne $new_p) {
+                       return 1;
+               }
+               if ($old_n ne $new_n) {
+                       return 1;
+               }
+       }
+
+       foreach my $trail (keys %$new) {
+               if (! exists $old->{$trail}) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+my $done_prerender = 0;
+
+my %origsubs;
+
+sub prerender {
+       return if $done_prerender;
+
+       $origsubs{render_backlinks} = \&IkiWiki::render_backlinks;
+       inject(name => "IkiWiki::render_backlinks", call => \&render_backlinks);
+
+       %trail_to_members = ();
+       %member_to_trails = ();
+
+       foreach my $trail (keys %pagestate) {
+               next unless exists $pagestate{$trail}{trail}{contents};
+
+               my $members = [];
+               my @contents = @{$pagestate{$trail}{trail}{contents}};
+
+               foreach my $c (@contents) {
+                       if ($c->[0] eq 'pagespec') {
+                               push @$members, pagespec_match_list($trail,
+                                       $c->[1], sort => $c->[2],
+                                       reverse => $c->[3]);
+                       }
+                       elsif ($c->[0] eq 'link') {
+                               my $best = bestlink($trail, $c->[1]);
+                               push @$members, $best if length $best;
+                       }
+               }
+
+               if (defined $pagestate{$trail}{trail}{sort}) {
+                       # re-sort
+                       @$members = pagespec_match_list($trail, 'internal(*)',
+                               list => $members,
+                               sort => $pagestate{$trail}{trail}{sort});
+               }
+
+               if (IkiWiki::yesno $pagestate{$trail}{trail}{reverse}) {
+                       @$members = reverse @$members;
+               }
+
+               # uniquify
+               my %seen;
+               my @tmp;
+               foreach my $member (@$members) {
+                       push @tmp, $member unless $seen{$member};
+                       $seen{$member} = 1;
+               }
+               $members = [@tmp];
+
+               for (my $i = 0; $i <= $#$members; $i++) {
+                       my $member = $members->[$i];
+                       my $prev;
+                       $prev = $members->[$i - 1] if $i > 0;
+                       my $next = $members->[$i + 1];
+
+                       add_depends($member, $trail);
+
+                       $member_to_trails{$member}{$trail} = [$prev, $next];
+               }
+
+               if ((scalar @$members) > 1 && $pagestate{$trail}{trail}{circular}) {
+                       $member_to_trails{$members->[0]}{$trail}[0] = $members->[$#$members];
+                       $member_to_trails{$members->[$#$members]}{$trail}[1] = $members->[0];
+               }
+
+               $trail_to_members{$trail} = $members;
+       }
+
+       foreach my $member (keys %pagestate) {
+               if (exists $pagestate{$member}{trail}{item} &&
+                       ! exists $member_to_trails{$member}) {
+                       $rebuild_trail_members{$member} = 1;
+                       delete $pagestate{$member}{trailitem};
+               }
+       }
+
+       foreach my $member (keys %member_to_trails) {
+               if (! exists $pagestate{$member}{trail}{item}) {
+                       $rebuild_trail_members{$member} = 1;
+               }
+               else {
+                       if (trails_differ($pagestate{$member}{trail}{item},
+                                       $member_to_trails{$member})) {
+                               $rebuild_trail_members{$member} = 1;
+                       }
+               }
+
+               $pagestate{$member}{trail}{item} = $member_to_trails{$member};
+       }
+
+       $done_prerender = 1;
+}
+
+# This is called at about the right time that we can hijack it to render
+# extra pages.
+sub render_backlinks ($) {
+       my $blc = shift;
+
+       foreach my $member (keys %rebuild_trail_members) {
+               next unless exists $pagesources{$member};
+
+               IkiWiki::render($pagesources{$member}, sprintf(gettext("building %s, its previous or next page has changed"), $member));
+       }
+
+       $origsubs{render_backlinks}($blc);
+}
+
+sub title_of ($) {
+       my $page = shift;
+       if (defined ($pagestate{$page}{meta}{title})) {
+               return $pagestate{$page}{meta}{title};
+       }
+       return pagetitle(IkiWiki::basename($page));
+}
+
+my $recursive = 0;
+
+sub pagetemplate (@) {
+       my %params = @_;
+       my $page = $params{page};
+       my $template = $params{template};
+
+       if ($template->query(name => 'trails') && ! $recursive) {
+               prerender();
+
+               $recursive = 1;
+               my $inner = template("trails.tmpl", blind_cache => 1);
+               IkiWiki::run_hooks(pagetemplate => sub {
+                               shift->(%params, template => $inner)
+                       });
+               $template->param(trails => $inner->output);
+               $recursive = 0;
+       }
+
+       if ($template->query(name => 'trailloop')) {
+               prerender();
+
+               my @trails;
+
+               # sort backlinks by page name to have a consistent order
+               foreach my $trail (sort keys %{$member_to_trails{$page}}) {
+
+                       my $members = $trail_to_members{$trail};
+                       my ($prev, $next) = @{$member_to_trails{$page}{$trail}};
+                       my ($prevurl, $nexturl, $prevtitle, $nexttitle);
+
+                       if (defined $prev) {
+                               add_depends($params{destpage}, $prev);
+                               $prevurl = urlto($prev, $page);
+                               $prevtitle = title_of($prev);
+                       }
+
+                       if (defined $next) {
+                               add_depends($params{destpage}, $next);
+                               $nexturl = urlto($next, $page);
+                               $nexttitle = title_of($next);
+                       }
+
+                       push @trails, {
+                               prevpage => $prev,
+                               prevtitle => $prevtitle,
+                               prevurl => $prevurl,
+                               nextpage => $next,
+                               nexttitle => $nexttitle,
+                               nexturl => $nexturl,
+                               trailpage => $trail,
+                               trailtitle => title_of($trail),
+                               trailurl => urlto($trail, $page),
+                       };
+               }
+
+               $template->param(trailloop => \@trails);
+       }
+}
+
+1;
index 0eb83ded614a2b4e2b2397bf8d2db897984317db..5617daf9e6a30dece748037dd6bebcfa8550dda6 100644 (file)
@@ -36,7 +36,7 @@ IkiWiki::Setup::Automator->import(
        cgiurl => "http://$domain/~$ENV{USER}/$wikiname_short/ikiwiki.cgi",
        cgi_wrapper => "$ENV{HOME}/public_html/$wikiname_short/ikiwiki.cgi",
        adminemail => "$ENV{USER}\@$domain",
-       add_plugins => [qw{goodstuff websetup comments blogspam calendar sidebar}],
+       add_plugins => [qw{goodstuff websetup comments blogspam calendar sidebar trail}],
        disable_plugins => [qw{}],
        libdir => "$ENV{HOME}/.ikiwiki",
        rss => 1,
index 08e014838008bc1c31adb7ccbc2cc69980ec390b..6e9a3f001a05313e3e57a66d429eaf646ecbdc07 100644 (file)
@@ -1,3 +1,3 @@
 Here is a full list of posts to the [[blog|index]].
 
-[[!inline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes]]
+[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes]]
index 7bbfe5d2a8b76bd682817b4e3c60aebd74aee93b..35a133198afc470668629b842f58679195852011 100644 (file)
@@ -501,3 +501,38 @@ a.openid_large_btn:focus {
 .fileupload-content .ui-progressbar-value {
        background: url(ikiwiki/images/pbar-ani.gif);
 }
+
+.trail {
+       display: block;
+       clear: both;
+       position: relative;
+}
+
+.trailprev {
+       display: block;
+       text-align: left;
+       position: absolute;
+       top: 0%;
+       left: 3%;
+       width: 30%;
+}
+
+.trailup {
+       display: block;
+       text-align: center;
+       margin-left: 35%;
+       margin-right: 35%;
+}
+
+.trailnext {
+       display: block;
+       text-align: right;
+       position: absolute;
+       top: 0%;
+       width: 30%;
+       right: 3%;
+}
+
+.trailsep {
+       display: none;
+}
index d189fa073468dce570508c2d5fefa2c6b5c0afb6..43bf9ee51e6d1d10c11a98ccff8719dfa0a62376 100644 (file)
@@ -80,6 +80,8 @@ Here is a full list of the template files used:
 * `autotag.tmpl` - Filled in by the tag plugin to make tag pages.
 * `calendarmonth.tmpl`, `calendaryear.tmpl` - Used by ikiwiki-calendar to
   make calendar archive pages.
+* `trails.tmpl` - Used by the trail plugin to generate links on each page
+  that is a member of a trail.
 * `editpage.tmpl`, `editconflict.tmpl`, `editcreationconflict.tmpl`,
   `editfailedsave.tmpl`, `editpagegone.tmpl`, `pocreatepage.tmpl`,
   `editcomment.tmpl` `commentmoderation.tmpl`, `renamesummary.tmpl`,
diff --git a/t/trail.t b/t/trail.t
new file mode 100755 (executable)
index 0000000..0cf50dd
--- /dev/null
+++ b/t/trail.t
@@ -0,0 +1,233 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use IkiWiki;
+
+my $blob;
+
+ok(! system("rm -rf t/tmp"));
+ok(! system("mkdir t/tmp"));
+
+# Use a rather stylized template to override the default rendering, to make
+# it easy to search for the desired results
+writefile("templates/trails.tmpl", "t/tmp/in", <<EOF
+<TMPL_LOOP TRAILLOOP>
+<TMPL_IF __FIRST__><nav></TMPL_IF>
+<div>
+trail=<TMPL_VAR TRAILPAGE> n=<TMPL_VAR NEXTPAGE> p=<TMPL_VAR PREVPAGE>
+</div>
+<div>
+<TMPL_IF PREVURL>
+<a href="<TMPL_VAR PREVURL>">&lt; <TMPL_VAR PREVTITLE></a>
+</TMPL_IF> |
+<a href="<TMPL_VAR TRAILURL>">^ <TMPL_VAR TRAILTITLE> ^</a>
+| <TMPL_IF NEXTURL>
+<a href="<TMPL_VAR NEXTURL>"><TMPL_VAR NEXTTITLE> &gt;</a>
+</TMPL_IF>
+</div>
+<TMPL_IF __LAST__></nav></TMPL_IF>
+</TMPL_LOOP>
+EOF
+);
+writefile("badger.mdwn", "t/tmp/in", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
+writefile("mushroom.mdwn", "t/tmp/in", "content of mushroom");
+writefile("snake.mdwn", "t/tmp/in", "content of snake");
+writefile("ratty.mdwn", "t/tmp/in", "content of ratty");
+writefile("mr_toad.mdwn", "t/tmp/in", "content of mr toad");
+writefile("add.mdwn", "t/tmp/in", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
+writefile("add/b.mdwn", "t/tmp/in", "b");
+writefile("add/d.mdwn", "t/tmp/in", "d");
+writefile("del.mdwn", "t/tmp/in", '[[!trailitems pages="del/*" sort=title]]');
+writefile("del/a.mdwn", "t/tmp/in", "a");
+writefile("del/b.mdwn", "t/tmp/in", "b");
+writefile("del/c.mdwn", "t/tmp/in", "c");
+writefile("del/d.mdwn", "t/tmp/in", "d");
+writefile("del/e.mdwn", "t/tmp/in", "e");
+writefile("self_referential.mdwn", "t/tmp/in", '[[!trailitems pagenames="self_referential" circular=yes]]');
+writefile("sorting/linked.mdwn", "t/tmp/in", "linked");
+writefile("sorting/a/b.mdwn", "t/tmp/in", "a/b");
+writefile("sorting/a/c.mdwn", "t/tmp/in", "a/c");
+writefile("sorting/z/a.mdwn", "t/tmp/in", "z/a");
+writefile("sorting/beginning.mdwn", "t/tmp/in", "beginning");
+writefile("sorting/middle.mdwn", "t/tmp/in", "middle");
+writefile("sorting/end.mdwn", "t/tmp/in", "end");
+writefile("sorting/new.mdwn", "t/tmp/in", "new");
+writefile("sorting/old.mdwn", "t/tmp/in", "old");
+writefile("sorting/ancient.mdwn", "t/tmp/in", "ancient");
+# These three need to be in the appropriate age order
+ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
+ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
+ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
+writefile("sorting/linked2.mdwn", "t/tmp/in", "linked2");
+# This initially uses the default sort order: age for trailinline, and path
+# for trail. We change it later.
+writefile("sorting.mdwn", "t/tmp/in",
+       '[[!traillink linked]] ' .
+       '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
+       '[[!trailitems pagenames="beginning middle end"]] ' .
+       '[[!trailinline pages="sorting/old or sorting/ancient or sorting/new"]] ' .
+       '[[!traillink linked2]]');
+
+writefile("meme.mdwn", "t/tmp/in", <<EOF
+[[!trail]]
+* [[!traillink badger]]
+* [[!traillink badger text="This is a link to badger, with a title"]]
+* [[!traillink That_is_the_badger|badger]]
+* [[!traillink badger]]
+* [[!traillink mushroom]]
+* [[!traillink mushroom]]
+* [[!traillink snake]]
+* [[!traillink snake]]
+EOF
+);
+
+writefile("wind_in_the_willows.mdwn", "t/tmp/in", <<EOF
+[[!trailoptions circular=yes sort=title]]
+[[!trailitems pages="ratty or badger or mr_toad"]]
+[[!trailitem moley]]
+EOF
+);
+
+ok(! system("make -s ikiwiki.out"));
+
+my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin trail -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
+
+ok(! system($command));
+
+ok(! system("$command -refresh"));
+
+$blob = readfile("t/tmp/out/meme.html");
+ok($blob =~ /<a href="(\.\/)?badger.html">badger<\/a>/m);
+ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
+ok($blob =~ /<a href="(\.\/)?badger.html">That is the badger<\/a>/m);
+
+$blob = readfile("t/tmp/out/badger.html");
+ok($blob =~ /^trail=meme n=mushroom p=$/m);
+ok($blob =~ /^trail=wind_in_the_willows n=mr_toad p=ratty$/m);
+
+ok(! -f "t/tmp/out/moley.html");
+
+$blob = readfile("t/tmp/out/mr_toad.html");
+ok($blob !~ /^trail=meme/m);
+ok($blob =~ /^trail=wind_in_the_willows n=ratty p=badger$/m);
+# meta title is respected for pages that have one
+ok($blob =~ /">&lt; The Breezy Badger<\/a>/m);
+# pagetitle for pages that don't
+ok($blob =~ /">ratty &gt;<\/a>/m);
+
+$blob = readfile("t/tmp/out/ratty.html");
+ok($blob !~ /^trail=meme/m);
+ok($blob =~ /^trail=wind_in_the_willows n=badger p=mr_toad$/m);
+
+$blob = readfile("t/tmp/out/mushroom.html");
+ok($blob =~ /^trail=meme n=snake p=badger$/m);
+ok($blob !~ /^trail=wind_in_the_willows/m);
+
+$blob = readfile("t/tmp/out/snake.html");
+ok($blob =~ /^trail=meme n= p=mushroom$/m);
+ok($blob !~ /^trail=wind_in_the_willows/m);
+
+$blob = readfile("t/tmp/out/self_referential.html");
+ok($blob =~ /^trail=self_referential n= p=$/m);
+
+$blob = readfile("t/tmp/out/add/b.html");
+ok($blob =~ /^trail=add n=add\/d p=$/m);
+$blob = readfile("t/tmp/out/add/d.html");
+ok($blob =~ /^trail=add n= p=add\/b$/m);
+ok(! -f "t/tmp/out/add/a.html");
+ok(! -f "t/tmp/out/add/c.html");
+ok(! -f "t/tmp/out/add/e.html");
+
+$blob = readfile("t/tmp/out/del/a.html");
+ok($blob =~ /^trail=del n=del\/b p=$/m);
+$blob = readfile("t/tmp/out/del/b.html");
+ok($blob =~ /^trail=del n=del\/c p=del\/a$/m);
+$blob = readfile("t/tmp/out/del/c.html");
+ok($blob =~ /^trail=del n=del\/d p=del\/b$/m);
+$blob = readfile("t/tmp/out/del/d.html");
+ok($blob =~ /^trail=del n=del\/e p=del\/c$/m);
+$blob = readfile("t/tmp/out/del/e.html");
+ok($blob =~ /^trail=del n= p=del\/d$/m);
+
+$blob = readfile("t/tmp/out/sorting/linked.html");
+ok($blob =~ m{^trail=sorting n=sorting/a/b p=$}m);
+$blob = readfile("t/tmp/out/sorting/a/b.html");
+ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m);
+$blob = readfile("t/tmp/out/sorting/a/c.html");
+ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m);
+$blob = readfile("t/tmp/out/sorting/z/a.html");
+ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/a/c$}m);
+$blob = readfile("t/tmp/out/sorting/beginning.html");
+ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/z/a$}m);
+$blob = readfile("t/tmp/out/sorting/middle.html");
+ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/beginning$}m);
+$blob = readfile("t/tmp/out/sorting/end.html");
+ok($blob =~ m{^trail=sorting n=sorting/new p=sorting/middle$}m);
+$blob = readfile("t/tmp/out/sorting/new.html");
+ok($blob =~ m{^trail=sorting n=sorting/old p=sorting/end$}m);
+$blob = readfile("t/tmp/out/sorting/old.html");
+ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/new$}m);
+$blob = readfile("t/tmp/out/sorting/ancient.html");
+ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/old$}m);
+$blob = readfile("t/tmp/out/sorting/linked2.html");
+ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m);
+
+# Make some changes and refresh
+
+writefile("add/a.mdwn", "t/tmp/in", "a");
+writefile("add/c.mdwn", "t/tmp/in", "c");
+writefile("add/e.mdwn", "t/tmp/in", "e");
+ok(unlink("t/tmp/in/del/a.mdwn"));
+ok(unlink("t/tmp/in/del/c.mdwn"));
+ok(unlink("t/tmp/in/del/e.mdwn"));
+
+writefile("sorting.mdwn", "t/tmp/in",
+       readfile("t/tmp/in/sorting.mdwn") .
+       '[[!trailoptions sort="title" reverse="yes"]]'); 
+
+ok(! system("$command -refresh"));
+
+$blob = readfile("t/tmp/out/add/a.html");
+ok($blob =~ /^trail=add n=add\/b p=$/m);
+$blob = readfile("t/tmp/out/add/b.html");
+ok($blob =~ /^trail=add n=add\/c p=add\/a$/m);
+$blob = readfile("t/tmp/out/add/c.html");
+ok($blob =~ /^trail=add n=add\/d p=add\/b$/m);
+$blob = readfile("t/tmp/out/add/d.html");
+ok($blob =~ /^trail=add n=add\/e p=add\/c$/m);
+$blob = readfile("t/tmp/out/add/e.html");
+ok($blob =~ /^trail=add n= p=add\/d$/m);
+
+$blob = readfile("t/tmp/out/del/b.html");
+ok($blob =~ /^trail=del n=del\/d p=$/m);
+$blob = readfile("t/tmp/out/del/d.html");
+ok($blob =~ /^trail=del n= p=del\/b$/m);
+ok(! -f "t/tmp/out/del/a.html");
+ok(! -f "t/tmp/out/del/c.html");
+ok(! -f "t/tmp/out/del/e.html");
+
+$blob = readfile("t/tmp/out/sorting/old.html");
+ok($blob =~ m{^trail=sorting n=sorting/new p=$}m);
+$blob = readfile("t/tmp/out/sorting/new.html");
+ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/old$}m);
+$blob = readfile("t/tmp/out/sorting/middle.html");
+ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/new$}m);
+$blob = readfile("t/tmp/out/sorting/linked2.html");
+ok($blob =~ m{^trail=sorting n=sorting/linked p=sorting/middle$}m);
+$blob = readfile("t/tmp/out/sorting/linked.html");
+ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/linked2$}m);
+$blob = readfile("t/tmp/out/sorting/end.html");
+ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m);
+$blob = readfile("t/tmp/out/sorting/a/c.html");
+ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/end$}m);
+$blob = readfile("t/tmp/out/sorting/beginning.html");
+ok($blob =~ m{^trail=sorting n=sorting/a/b p=sorting/a/c$}m);
+$blob = readfile("t/tmp/out/sorting/a/b.html");
+ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/beginning$}m);
+$blob = readfile("t/tmp/out/sorting/ancient.html");
+ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m);
+$blob = readfile("t/tmp/out/sorting/z/a.html");
+ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m);
+
+ok(! system("rm -rf t/tmp"));
index 8659018a05fef3d2915287e66dcf23b6140b65aa..770ac2399ba36b6e1513379db6e00ab87e6c2f98 100644 (file)
 <TMPL_IF FEEDLINKS><TMPL_VAR FEEDLINKS></TMPL_IF>
 <TMPL_IF RELVCS><TMPL_VAR RELVCS></TMPL_IF>
 <TMPL_IF META><TMPL_VAR META></TMPL_IF>
+<TMPL_LOOP TRAILLOOP>
+<TMPL_IF PREVPAGE>
+<link rel="prev" href="<TMPL_VAR PREVURL>" title="<TMPL_VAR PREVTITLE>" />
+</TMPL_IF>
+<link rel="up" href="<TMPL_VAR TRAILURL>" title="<TMPL_VAR TRAILTITLE>" />
+<TMPL_IF NEXTPAGE>
+<link rel="next" href="<TMPL_VAR NEXTURL>" title="<TMPL_VAR NEXTTITLE>" />
+</TMPL_IF>
+</TMPL_LOOP>
 </head>
 <body>
 
 <TMPL_IF HTML5></nav><TMPL_ELSE></div></TMPL_IF>
 </TMPL_IF>
 
+<TMPL_VAR TRAILS>
+
 <TMPL_IF HTML5></section><TMPL_ELSE></div></TMPL_IF>
 
 <TMPL_IF SIDEBAR>
diff --git a/templates/trails.tmpl b/templates/trails.tmpl
new file mode 100644 (file)
index 0000000..54c0460
--- /dev/null
@@ -0,0 +1,23 @@
+<TMPL_LOOP TRAILLOOP>
+<TMPL_IF __FIRST__><TMPL_IF HTML5><nav class="trails"><TMPL_ELSE><div class="trails"></TMPL_IF></TMPL_IF>
+<div class="trail">
+<TMPL_IF PREVPAGE>
+<span class="trailprev">
+<span class="trailarrow">←</span>
+<a href="<TMPL_VAR PREVURL>"><TMPL_VAR PREVTITLE></a>
+<span class="trailsep">|</span>
+</span>
+</TMPL_IF>
+<span class="trailup">
+<a href="<TMPL_VAR TRAILURL>"><TMPL_VAR TRAILTITLE></a>
+</span>
+<TMPL_IF NEXTPAGE>
+<span class="trailnext">
+<span class="trailsep">|</span>
+<a href="<TMPL_VAR NEXTURL>"><TMPL_VAR NEXTTITLE></a>
+<span class="trailarrow">→</span>
+</span>
+</TMPL_IF>
+</div>
+<TMPL_IF __LAST__><TMPL_IF HTML5></nav><TMPL_ELSE></div></TMPL_IF></TMPL_IF>
+</TMPL_LOOP>
index 749d9b21e1ca9c1efae9195f04d07242388557e7..26cdc1e86613648fb9b86320702c3314a952e29c 100644 (file)
@@ -142,3 +142,8 @@ div.recentchanges {
        padding: 0 0 0 2ex;
        border-color: #999;
 }
+
+.trails {
+       /* allow space for the action tabs */
+       margin-bottom: 2em;
+}
index c07d1cdfa4b305e8a336575c6c0ac5cc9626fda3..32f4b32eae5d28be68e978a8c6cc3d1c2403e4e1 100644 (file)
@@ -197,18 +197,23 @@ body {
        font-weight: bold;
 }
 
-.pageheader .header .title, .pageheader .header .parentlinks, .pageheader .actions ul li, .pageheader .header span, .pageheader #otherlanguages ul li {
+.pageheader .header .title, .pageheader .header .parentlinks, .pageheader .actions ul li, .pageheader .header span, .pageheader #otherlanguages ul li, .trailprev, .trailnext, .trailup {
        padding: 0.25em 0.25em 0.25em 0.25em;
        background-image: url('background_darkness.png');
        background-repeat: repeat;
        color: white;
 }
 
-.pageheader .header span a, .pageheader .actions ul li a, .pageheader .header .parentlinks a, .pageheader #otherlanguages ul li a {
+.pageheader .header span a, .pageheader .actions ul li a, .pageheader .header .parentlinks a, .pageheader #otherlanguages ul li a, .pageheader a {
+       font-weight: bold;
        color: white;
        text-decoration: none;
 }
 
+.trailprev, .trailnext, .trailup {
+       margin-top: 0.5em;
+}
+
 .pageheader .actions {
        text-align: right;
        vertical-align: bottom;