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;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-09-12 00:46:32 +02:00
|
|
|
add_underlay("directives");
|
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-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-25 19:28:25 +02:00
|
|
|
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-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-08-25 19:36:06 +02:00
|
|
|
my @fulllist;
|
2008-10-30 18:41:19 +01:00
|
|
|
my @shortlist;
|
2008-08-25 19:36:06 +02:00
|
|
|
my $pluginstring;
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-12-17 21:22:16 +01: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-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub needsbuild (@) {
|
2008-08-25 19:28:25 +02:00
|
|
|
my $needsbuild=shift;
|
|
|
|
|
2009-05-22 20:17:26 +02:00
|
|
|
@fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
|
2008-10-30 18:41:19 +01:00
|
|
|
@shortlist = grep { ! $IkiWiki::hooks{preprocess}{$_}{shortcut} } @fulllist;
|
|
|
|
$pluginstring = join(' ', @shortlist) . " : " . 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2008-08-25 19:28:25 +02:00
|
|
|
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 {
|
2008-10-30 18:41:19 +01:00
|
|
|
@pluginlist = @shortlist;
|
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-09-27 20:14:36 +02:00
|
|
|
my $link=linkpage($config{directive_description_dir}."/".$plugin);
|
2009-10-08 22:49:03 +02:00
|
|
|
add_depends($params{page}, $link, deptype("presence"));
|
2008-08-25 20:21:04 +02:00
|
|
|
$result .= htmllink($params{page}, $params{destpage}, $link);
|
2008-08-25 19:28:25 +02:00
|
|
|
$result .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= "</ul>";
|
|
|
|
|
|
|
|
return $result;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-25 19:28:25 +02:00
|
|
|
|
|
|
|
1
|