From 04a59b3c65e8e60805b6ed6d11d448b1d5babe64 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 3 Apr 2010 13:57:38 +0100 Subject: [PATCH] Move sort hooks to the IkiWiki::SortSpec namespace Also rename cmpspec_translate (internal function) to sortspec_translate for consistency. --- IkiWiki.pm | 14 ++++++++------ IkiWiki/Plugin/meta.pm | 2 ++ IkiWiki/Plugin/sortnaturally.pm | 2 +- doc/plugins/write.mdwn | 2 +- t/pagespec_match_list.t | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 7547f1751..d716e8b39 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index e8cc1e392..cd7d0d127 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -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 diff --git a/IkiWiki/Plugin/sortnaturally.pm b/IkiWiki/Plugin/sortnaturally.pm index 0023f31f9..f498820a5 100644 --- a/IkiWiki/Plugin/sortnaturally.pm +++ b/IkiWiki/Plugin/sortnaturally.pm @@ -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])), diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 06c8f8e44..b67142230 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -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 diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t index 743ae4637..68112f5c0 100755 --- a/t/pagespec_match_list.t +++ b/t/pagespec_match_list.t @@ -10,7 +10,7 @@ $config{srcdir}=$config{destdir}="/dev/null"; IkiWiki::checkconfig(); { - package IkiWiki::PageSpec; + package IkiWiki::SortSpec; sub cmp_path { $_[0] cmp $_[1] } } -- 2.32.0.93.g670b81a890