2008-08-25 19:28:25 +02:00
|
|
|
#!/usr/bin/perl
|
2008-08-25 19:38:44 +02:00
|
|
|
# Ikiwiki listdirectives plugin.
|
|
|
|
package IkiWiki::Plugin::listdirectives;
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki 2.00;
|
|
|
|
|
|
|
|
sub import { #{{{
|
2008-08-25 19:38:44 +02:00
|
|
|
hook(type => "getsetup", id => "listdirectives", call => \&getsetup);
|
|
|
|
hook(type => "checkconfig", id => "listdirectives", call => \&checkconfig);
|
|
|
|
hook(type => "needsbuild", id => "listdirectives", call => \&needsbuild);
|
|
|
|
hook(type => "preprocess", id => "listdirectives", call => \&preprocess);
|
2008-08-25 19:28:25 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub getsetup () { #{{{
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-08-25 19:38:44 +02:00
|
|
|
directive_description_dir => {
|
2008-08-25 19:28:25 +02:00
|
|
|
type => "string",
|
2008-08-25 20:21:04 +02:00
|
|
|
description => "directory in srcdir that contains directive descriptions",
|
|
|
|
example => "ikiwiki/directive",
|
2008-08-25 19:28:25 +02:00
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
} #}}}
|
|
|
|
|
2008-08-25 19:36:06 +02:00
|
|
|
my @fulllist;
|
|
|
|
my @earlylist;
|
|
|
|
my $pluginstring;
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
sub checkconfig () { #{{{
|
2008-08-25 19:38:44 +02:00
|
|
|
if (! defined $config{directive_description_dir}) {
|
2008-08-25 20:21:04 +02:00
|
|
|
$config{directive_description_dir} = "ikiwiki/directive";
|
2008-08-25 19:36:06 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-08-25 20:21:04 +02:00
|
|
|
$config{directive_description_dir} =~ s/\/+$//;
|
2008-08-25 19:36:06 +02:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-08-25 20:21:04 +02:00
|
|
|
@earlylist = sort keys %{$IkiWiki::hooks{preprocess}};
|
2008-08-25 19:28:25 +02:00
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub needsbuild (@) { #{{{
|
|
|
|
my $needsbuild=shift;
|
|
|
|
|
2008-08-25 20:21:04 +02:00
|
|
|
@fulllist = sort keys %{$IkiWiki::hooks{preprocess}};
|
|
|
|
$pluginstring = join(' ', @earlylist) . " : " . join(' ', @fulllist);
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
foreach my $page (keys %pagestate) {
|
2008-08-25 19:38:44 +02:00
|
|
|
if (exists $pagestate{$page}{listdirectives}{shown}) {
|
|
|
|
if ($pagestate{$page}{listdirectives}{shown} ne $pluginstring) {
|
2008-08-25 19:28:25 +02:00
|
|
|
push @$needsbuild, $pagesources{$page};
|
|
|
|
}
|
|
|
|
if (exists $pagesources{$page} &&
|
2008-08-25 19:36:06 +02:00
|
|
|
grep { $_ eq $pagesources{$page} } @$needsbuild) {
|
2008-08-25 19:28:25 +02:00
|
|
|
# remove state, will be re-added if
|
2008-08-25 19:38:44 +02:00
|
|
|
# the [[!listdirectives]] is still there during the
|
2008-08-25 19:28:25 +02:00
|
|
|
# rebuild
|
2008-08-25 19:38:44 +02:00
|
|
|
delete $pagestate{$page}{listdirectives}{shown};
|
2008-08-25 19:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
|
2008-08-25 19:38:44 +02:00
|
|
|
$pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
my @pluginlist;
|
|
|
|
|
|
|
|
if (defined $params{generated}) {
|
2008-08-25 19:36:06 +02:00
|
|
|
@pluginlist = @fulllist;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
@pluginlist = @earlylist;
|
2008-08-25 19:28:25 +02:00
|
|
|
}
|
|
|
|
|
2008-08-25 19:38:44 +02:00
|
|
|
my $result = '<ul class="listdirectives">';
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
foreach my $plugin (@pluginlist) {
|
2008-08-25 19:38:44 +02:00
|
|
|
$result .= '<li class="listdirectives">';
|
2008-08-25 20:21:04 +02:00
|
|
|
my $link=IkiWiki::linkpage($config{directive_description_dir}."/".$plugin);
|
|
|
|
add_depends($params{page}, $link);
|
|
|
|
$result .= htmllink($params{page}, $params{destpage}, $link);
|
2008-08-25 19:28:25 +02:00
|
|
|
$result .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= "</ul>";
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|