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);
}
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});
$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(@_);
}
}
else {
- preprocess_trail(%params);
+ preprocess_trailitems(%params);
}
}
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;
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");
# 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]]');
);
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
);
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"));