Move sort hooks to the IkiWiki::SortSpec namespace

Also rename cmpspec_translate (internal function) to sortspec_translate
for consistency.
master
Simon McVittie 2010-04-03 13:57:38 +01:00
parent 75fd080465
commit 04a59b3c65
5 changed files with 13 additions and 9 deletions

View File

@ -37,7 +37,7 @@ our $DEPEND_LINKS=4;
# Optimisation.
use Memoize;
memoize("abs2rel");
memoize("cmpspec_translate");
memoize("sortspec_translate");
memoize("pagespec_translate");
memoize("template_file");
@ -1935,7 +1935,7 @@ sub add_link ($$) {
unless grep { $_ eq $link } @{$links{$page}};
}
sub cmpspec_translate ($) {
sub sortspec_translate ($) {
my $spec = shift;
my $code = "";
@ -1972,13 +1972,13 @@ sub cmpspec_translate ($) {
$code .= "-";
}
if (exists $IkiWiki::PageSpec::{"cmp_$word"}) {
if (exists $IkiWiki::SortSpec::{"cmp_$word"}) {
if (defined $params) {
push @data, $params;
$code .= "IkiWiki::PageSpec::cmp_$word(\@_, \$data[$#data])";
$code .= "IkiWiki::SortSpec::cmp_$word(\@_, \$data[$#data])";
}
else {
$code .= "IkiWiki::PageSpec::cmp_$word(\@_, undef)";
$code .= "IkiWiki::SortSpec::cmp_$word(\@_, undef)";
}
}
else {
@ -2095,7 +2095,7 @@ sub pagespec_match_list ($$;@) {
}
if (defined $params{sort}) {
my $f = cmpspec_translate($params{sort});
my $f = sortspec_translate($params{sort});
@candidates = sort { $f->($a, $b) } @candidates;
}
@ -2410,6 +2410,8 @@ sub match_ip ($$;@) {
}
}
package IkiWiki::SortSpec;
sub cmp_title {
IkiWiki::pagetitle(IkiWiki::basename($_[0]))
cmp

View File

@ -348,6 +348,8 @@ sub match_copyright ($$;@) {
IkiWiki::Plugin::meta::match("copyright", @_);
}
package IkiWiki::SortSpec;
sub cmp_meta_title {
IkiWiki::Plugin::meta::titlesort($_[0])
cmp

View File

@ -22,7 +22,7 @@ sub checkconfig () {
error $@ if $@;
}
package IkiWiki::PageSpec;
package IkiWiki::SortSpec;
sub cmp_title_natural {
Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($_[0])),

View File

@ -1114,7 +1114,7 @@ while "glob(*)" is not influenced by the contents of any page.
Similarly, it's possible to write plugins that add new functions as
[[ikiwiki/pagespec/sorting]] methods. To achieve this, add a function to
the IkiWiki::PageSpec package named `cmp_foo`, which will be used when sorting
the IkiWiki::SortSpec package named `cmp_foo`, which will be used when sorting
by `foo` or `foo(...)` is requested.
The function will be passed three or more parameters. The first two are

View File

@ -10,7 +10,7 @@ $config{srcdir}=$config{destdir}="/dev/null";
IkiWiki::checkconfig();
{
package IkiWiki::PageSpec;
package IkiWiki::SortSpec;
sub cmp_path { $_[0] cmp $_[1] }
}