diff options
author | Simon McVittie <smcv@debian.org> | 2011-11-12 21:37:28 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2011-11-12 21:37:28 +0000 |
commit | d70ba7cff3fc6cc78ea2f8eb0713212478ab6ba7 (patch) | |
tree | 6e8b98b163d0493b89d15658dc77206ab9b7bbe0 | |
parent | 74b1b2761ac21e73376d714503aad326dd6f8fec (diff) | |
download | ikiwiki-d70ba7cff3fc6cc78ea2f8eb0713212478ab6ba7.tar ikiwiki-d70ba7cff3fc6cc78ea2f8eb0713212478ab6ba7.tar.gz |
Split trail directive into trailitems, trailoptions
-rw-r--r-- | IkiWiki/Plugin/trail.pm | 86 | ||||
-rwxr-xr-x | t/trail.t | 15 |
2 files changed, 46 insertions, 55 deletions
diff --git a/IkiWiki/Plugin/trail.pm b/IkiWiki/Plugin/trail.pm index 098b98607..5ee152155 100644 --- a/IkiWiki/Plugin/trail.pm +++ b/IkiWiki/Plugin/trail.pm @@ -12,9 +12,10 @@ use IkiWiki 3.00; sub import { hook(type => "getsetup", id => "trail", call => \&getsetup); hook(type => "needsbuild", id => "trail", call => \&needsbuild); - hook(type => "preprocess", id => "trail", call => \&preprocess_trail, scan => 1); + 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); } @@ -103,23 +104,9 @@ sub needsbuild (@) { my $scanned = 0; -sub preprocess_trail (@) { +sub preprocess_trailoptions (@) { 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{sortthese} = 'path' unless exists $params{sortthese}; - $params{reversethese} = 'no' unless exists $params{reversethese}; - if (exists $params{circular}) { $pagestate{$params{page}}{trail}{circular} = IkiWiki::yesno($params{circular}); @@ -133,47 +120,19 @@ sub preprocess_trail (@) { $pagestate{$params{page}}{trail}{reverse} = $params{reverse}; } - if (exists $params{pages}) { - push @{$pagestate{$params{page}}{trail}{contents}}, - ["pagespec" => $params{pages}, $params{sortthese}, - IkiWiki::yesno($params{reversethese})]; - } - - if (exists $params{pagenames}) { - my @list = map { [link => $_] } split ' ', $params{pagenames}; - push @{$pagestate{$params{page}}{trail}{contents}}, @list; - } - return ""; } sub preprocess_trailinline (@) { my %params = @_; - if (exists $params{sort}) { - $params{sortthese} = $params{sort}; - delete $params{sort}; - } - else { + if (! exists $params{sort}) { # sort in the same order as [[plugins/inline]]'s default - $params{sortthese} = 'age'; - } - - if (exists $params{reverse}) { - $params{reversethese} = $params{reverse}; - delete $params{reverse}; - } - - if (exists $params{trailsort}) { - $params{sort} = $params{trailsort}; - } - - if (exists $params{trailreverse}) { - $params{reverse} = $params{trailreverse}; + $params{sort} = 'age'; } if (defined wantarray) { - scalar preprocess_trail(%params); + scalar preprocess_trailitems(%params); if (IkiWiki->can("preprocess_inline")) { return IkiWiki::preprocess_inline(@_); @@ -183,7 +142,7 @@ sub preprocess_trailinline (@) { } } else { - preprocess_trail(%params); + preprocess_trailitems(%params); } } @@ -211,6 +170,37 @@ sub preprocess_trailitem (@) { 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; @@ -35,16 +35,16 @@ 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", '[[!trail pagenames="add/a add/b add/c add/d add/e"]]'); +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", '[[!trail pages="del/*" sort=title]]'); +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", '[[!trail pagenames="self_referential" circular=yes]]'); +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"); @@ -64,8 +64,8 @@ writefile("sorting/linked2.mdwn", "t/tmp/in", "linked2"); # for trail. We change it later. writefile("sorting.mdwn", "t/tmp/in", '[[!traillink linked]] ' . - '[[!trail pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' . - '[[!trail pagenames="beginning middle end"]] ' . + '[[!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]]'); @@ -83,7 +83,8 @@ EOF ); writefile("wind_in_the_willows.mdwn", "t/tmp/in", <<EOF -[[!trail circular=yes sort=title pages="ratty or badger or mr_toad"]] +[[!trailoptions circular=yes sort=title]] +[[!trailitems pages="ratty or badger or mr_toad"]] [[!trailitem moley]] EOF ); @@ -183,7 +184,7 @@ ok(unlink("t/tmp/in/del/e.mdwn")); writefile("sorting.mdwn", "t/tmp/in", readfile("t/tmp/in/sorting.mdwn") . - '[[!trailinline pages="doesnt_exist" trailsort="title" trailreverse="yes"]]'); + '[[!trailoptions sort="title" reverse="yes"]]'); ok(! system("$command -refresh")); |