Replace [[!trailinline]] directive with [[!inline trail=yes]]
authorSimon McVittie <smcv@debian.org>
Sun, 18 Mar 2012 17:11:05 +0000 (17:11 +0000)
committerSimon McVittie <smcv@debian.org>
Sun, 18 Mar 2012 17:11:05 +0000 (17:11 +0000)
IkiWiki/Plugin/inline.pm
IkiWiki/Plugin/trail.pm
doc/examples/blog/posts.mdwn
doc/ikiwiki/directive/inline.mdwn
doc/ikiwiki/directive/trailinline.mdwn [deleted file]
doc/plugins/trail.mdwn
t/trail.t

index 159cc5def01d59aaa3f532cbb4fea14ab52f6435..3dc410c276b62b85e2930b7eea4d63c0e66349da 100644 (file)
@@ -19,7 +19,7 @@ sub import {
        hook(type => "checkconfig", id => "inline", call => \&checkconfig);
        hook(type => "sessioncgi", id => "inline", call => \&sessioncgi);
        hook(type => "preprocess", id => "inline", 
        hook(type => "checkconfig", id => "inline", call => \&checkconfig);
        hook(type => "sessioncgi", id => "inline", call => \&sessioncgi);
        hook(type => "preprocess", id => "inline", 
-               call => \&IkiWiki::preprocess_inline);
+               call => \&IkiWiki::preprocess_inline, scan => 1);
        hook(type => "pagetemplate", id => "inline",
                call => \&IkiWiki::pagetemplate_inline);
        hook(type => "format", id => "inline", call => \&format, first => 1);
        hook(type => "pagetemplate", id => "inline",
                call => \&IkiWiki::pagetemplate_inline);
        hook(type => "format", id => "inline", call => \&format, first => 1);
@@ -155,6 +155,23 @@ sub preprocess_inline (@) {
        if (! exists $params{pages} && ! exists $params{pagenames}) {
                error gettext("missing pages parameter");
        }
        if (! exists $params{pages} && ! exists $params{pagenames}) {
                error gettext("missing pages parameter");
        }
+
+       if (! defined wantarray) {
+               # Running in scan mode: only do the essentials
+
+               if (yesno($params{trail}) && IkiWiki::Plugin::trail->can("preprocess_trailitems")) {
+                       # default to sorting age, the same as inline itself,
+                       # but let the params override that
+                       IkiWiki::Plugin::trail::preprocess_trailitems(sort => 'age', %params);
+               }
+
+               return;
+       }
+
+       if (yesno($params{trail}) && IkiWiki::Plugin::trail->can("preprocess_trailitems")) {
+               scalar IkiWiki::Plugin::trail::preprocess_trailitems(sort => 'age', %params);
+       }
+
        my $raw=yesno($params{raw});
        my $archive=yesno($params{archive});
        my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
        my $raw=yesno($params{raw});
        my $archive=yesno($params{archive});
        my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
index 5ee152155187d718d314bb70776ff2ecb8503c6b..4f309ea2ec68d47ecea074a879b4ff3669e4c38e 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # Copyright © 2008-2011 Joey Hess
 #!/usr/bin/perl
 # Copyright © 2008-2011 Joey Hess
-# Copyright © 2009-2011 Simon McVittie <http://smcv.pseudorandom.co.uk/>
+# Copyright © 2009-2012 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;
 # Licensed under the GNU GPL, version 2, or any later version published by the
 # Free Software Foundation
 package IkiWiki::Plugin::trail;
@@ -13,7 +13,6 @@ 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 => "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 => "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);
@@ -123,29 +122,6 @@ sub preprocess_trailoptions (@) {
        return "";
 }
 
        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;
 sub preprocess_trailitem (@) {
        my $link = shift;
        shift;
index 6e9a3f001a05313e3e57a66d429eaf646ecbdc07..2bd0f1d6f218b8b842f7f0d8e6a417c9a4114c37 100644 (file)
@@ -1,3 +1,3 @@
 Here is a full list of posts to the [[blog|index]].
 
 Here is a full list of posts to the [[blog|index]].
 
-[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes]]
+[[!inline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes trail=yes]]
index 22c18d9a18714556591b0ac574736a291e4360cf..4b11e599737819036f7b8bbe40a2ed2292e456af 100644 (file)
@@ -117,5 +117,10 @@ Here are some less often needed parameters:
   [[SubPage/LinkingRules]] as in a [[ikiwiki/WikiLink]]), and they are inlined
   in exactly the order given: the `sort` and `pages` parameters cannot be used
   in conjunction with this one.
   [[SubPage/LinkingRules]] as in a [[ikiwiki/WikiLink]]), and they are inlined
   in exactly the order given: the `sort` and `pages` parameters cannot be used
   in conjunction with this one.
+* `trail` - If the [[!iki plugins/trail desc=trail]] plugin is enabled, turn
+  the inlined pages into a trail with next/previous links, by passing the same
+  options to [[ikiwiki/directive/trailitems]]. The `skip` and `show` options
+  are ignored by the trail, so the next/previous links traverse through
+  all matching pages.
 
 [[!meta robots="noindex, follow"]]
 
 [[!meta robots="noindex, follow"]]
diff --git a/doc/ikiwiki/directive/trailinline.mdwn b/doc/ikiwiki/directive/trailinline.mdwn
deleted file mode 100644 (file)
index e32fb34..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-The `trailinline` directive is provided by the
-[[!iki plugins/trail desc=trail]]
-plugin. It is equivalent to combining [[ikiwiki/directive/trailitems]] and
-[[ikiwiki/directive/inline]] directives with the same options.
-
-A typical use is to navigate through all posts in a blog:
-
-      \[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes
-        feedshow=10 quick=yes]]
-
-[[!meta robots="noindex, follow"]]
index 406d40246af505397c2f39bddf6909f64b879dd8..14b97e35aab4f877cb242fe42af21ac71043ef12 100644 (file)
@@ -3,8 +3,7 @@
 
 This plugin provides the [[ikiwiki/directive/trailoptions]],
 [[ikiwiki/directive/traillink]], [[ikiwiki/directive/trailitem]],
 
 This plugin provides the [[ikiwiki/directive/trailoptions]],
 [[ikiwiki/directive/traillink]], [[ikiwiki/directive/trailitem]],
-[[ikiwiki/directive/trailitems]]
-and [[ikiwiki/directive/trailinline]] [[directives|ikiwiki/directive]].
+and [[ikiwiki/directive/trailitems]] [[directives|ikiwiki/directive]].
 
 It's sometimes useful to have "trails" of pages in a wiki where each
 page links to the next and/or previous page. For instance, you could use
 
 It's sometimes useful to have "trails" of pages in a wiki where each
 page links to the next and/or previous page. For instance, you could use
@@ -24,15 +23,16 @@ entire trail.
 
 Pages can be included in a trail in various ways:
 
 
 Pages can be included in a trail in various ways:
 
-* The [[ikiwiki/directive/trailinline]] directive sets up an [[inline]],
-  and at the same time adds the matching pages (from `pages` or `pagenames`)
-  to the trail. One use is to navigate through all posts in a blog:
+* The [[ikiwiki/directive/inline]] directive with `trail="yes"` sets up an
+  [[inline]], and at the same time adds the matching pages (from `pages` or
+  `pagenames`) to the trail. One use is to navigate through all posts in
+  a blog:
 
 
-        \[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes
-          feedshow=10 quick=yes]]
+        \[[!inline pages="page(./posts/*) and !*/Discussion" archive=yes
+          feedshow=10 quick=yes trail=yes]]
 
 
-  This directive only works if the [[!iki plugins/inline desc=inline]]
-  plugin is also enabled.
+  This only works if the trail and [[!iki plugins/inline desc=inline]]
+  plugins are both enabled.
 
 * The [[ikiwiki/directive/trailitems]] directive has optional `pages` and
   `pagenames` options which behave the same as in [[inline]], but don't
 
 * The [[ikiwiki/directive/trailitems]] directive has optional `pages` and
   `pagenames` options which behave the same as in [[inline]], but don't
index 0cf50ddc1cdb8aead5d655da59a4e70b077c9894..17fe543109cc2ac8490ea8e034789225a017d5cc 100755 (executable)
--- a/t/trail.t
+++ b/t/trail.t
@@ -60,13 +60,13 @@ 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");
 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.
+# This initially uses the default sort order: age for the inline, and path
+# for trailitems. 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"]] ' .
 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"]] ' .
+       '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' .
        '[[!traillink linked2]]');
 
 writefile("meme.mdwn", "t/tmp/in", <<EOF
        '[[!traillink linked2]]');
 
 writefile("meme.mdwn", "t/tmp/in", <<EOF