From: Joey Hess Date: Sat, 17 Apr 2010 16:50:23 +0000 (-0400) Subject: Merge remote branch 'davrieb/autotag' into autotag X-Git-Tag: 3.20100427~62^2~28 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=54f600af14bf6dc067ffc30ec6f22d517001fe99;p=ikiwiki.git Merge remote branch 'davrieb/autotag' into autotag Conflicts: IkiWiki.pm IkiWiki/Plugin/tag.pm --- 54f600af14bf6dc067ffc30ec6f22d517001fe99 diff --cc IkiWiki.pm index b37b1f344,966a3bbc6..2f26a16ce --- a/IkiWiki.pm +++ b/IkiWiki.pm @@@ -14,17 -14,17 +14,18 @@@ use open qw{:utf8 :std} use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %pagestate %wikistate %renderedfiles %oldrenderedfiles %pagesources %destsources %depends %depends_simple %hooks - %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks}; - %forcerebuild %loaded_plugins %autofiles %del_hash}; ++ %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks ++ %autofiles %del_hash}; use Exporter q{import}; our @EXPORT = qw(hook debug error template htmlpage deptype add_depends pagespec_match pagespec_match_list bestlink htmllink readfile writefile pagetype srcfile pagename - displaytime will_render gettext urlto targetpage + displaytime will_render gettext ngettext urlto targetpage add_underlay pagetitle titlepage linkpage newpagefile - inject add_link + inject add_link add_autofile %config %links %pagestate %wikistate %renderedfiles - %pagesources %destsources); + %pagesources %destsources %typedlinks); our $VERSION = 3.00; # plugin interface version, next is ikiwiki version our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE @@@ -1949,77 -1893,32 +1950,101 @@@ sub add_link ($$;$) push @{$links{$page}}, $link unless grep { $_ eq $link } @{$links{$page}}; + + if (defined $type) { + $typedlinks{$page}{$type}{$link} = 1; + } +} + +sub sortspec_translate ($$) { + my $spec = shift; + my $reverse = shift; + + my $code = ""; + my @data; + while ($spec =~ m{ + \s* + (-?) # group 1: perhaps negated + \s* + ( # group 2: a word + \w+\([^\)]*\) # command(params) + | + [^\s]+ # or anything else + ) + \s* + }gx) { + my $negated = $1; + my $word = $2; + my $params = undef; + + if ($word =~ m/^(\w+)\((.*)\)$/) { + # command with parameters + $params = $2; + $word = $1; + } + elsif ($word !~ m/^\w+$/) { + error(sprintf(gettext("invalid sort type %s"), $word)); + } + + if (length $code) { + $code .= " || "; + } + + if ($negated) { + $code .= "-"; + } + + if (exists $IkiWiki::SortSpec::{"cmp_$word"}) { + if (defined $params) { + push @data, $params; + $code .= "IkiWiki::SortSpec::cmp_$word(\$data[$#data])"; + } + else { + $code .= "IkiWiki::SortSpec::cmp_$word(undef)"; + } + } + else { + error(sprintf(gettext("unknown sort type %s"), $word)); + } + } + + if (! length $code) { + # undefined sorting method... sort arbitrarily + return sub { 0 }; + } + + if ($reverse) { + $code="-($code)"; + } + + no warnings; + return eval 'sub { '.$code.' }'; } + sub add_autofile ($$) { + my $autofile=shift; + my $plugin=shift; + + if (srcfile($autofile, 1)) { + return 0; + } + + my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir}); + + if ((!defined $file) || + (exists $pagestate{$page}{$plugin}{autofile_deleted})) { + return 0; + } + + if (exists $del_hash{$file}) { + $pagestate{$page}{$plugin}{autofile_deleted}=1; + return 0; + } + + $autofiles{$file}=$plugin; + return 1; + } + sub pagespec_translate ($) { my $spec=shift; diff --cc IkiWiki/Plugin/tag.pm index 7a85874f6,fdd63d637..9e6f417bf --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@@ -69,8 -94,13 +92,12 @@@ sub preprocess_tag (@) foreach my $tag (keys %params) { $tag=linkpage($tag); - $tags{$page}{$tag}=1; - ++ + # hidden WikiLink + add_link($page, tagpage($tag), 'tag'); ++ + # add tagpage if necessary + gentag($tag); - - # hidden WikiLink - add_link($page, tagpage($tag)); } return "";