ikiwiki/IkiWiki/Plugin/listdirectives.pm

99 lines
2.4 KiB
Perl
Raw Normal View History

2008-08-25 19:28:25 +02:00
#!/usr/bin/perl
# Ikiwiki listdirectives plugin.
package IkiWiki::Plugin::listdirectives;
2008-08-25 19:28:25 +02:00
use warnings;
use strict;
use IkiWiki 3.00;
2008-08-25 19:28:25 +02:00
sub import {
add_underlay("directives");
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 () {
2008-08-25 19:28:25 +02:00
return
plugin => {
safe => 1,
rebuild => undef,
2010-02-12 12:35:52 +01:00
section => "widget",
2008-08-25 19:28:25 +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:28:25 +02:00
my @fulllist;
my @shortlist;
my $pluginstring;
2008-08-25 19:28:25 +02:00
sub checkconfig () {
if (! defined $config{directive_description_dir}) {
2008-08-25 20:21:04 +02:00
$config{directive_description_dir} = "ikiwiki/directive";
}
else {
2008-08-25 20:21:04 +02:00
$config{directive_description_dir} =~ s/\/+$//;
}
}
2008-08-25 19:28:25 +02:00
sub needsbuild (@) {
2008-08-25 19:28:25 +02:00
my $needsbuild=shift;
@fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
@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) {
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} &&
grep { $_ eq $pagesources{$page} } @$needsbuild) {
2008-08-25 19:28:25 +02:00
# remove state, will be re-added if
# the [[!listdirectives]] is still there during the
2008-08-25 19:28:25 +02:00
# rebuild
delete $pagestate{$page}{listdirectives}{shown};
2008-08-25 19:28:25 +02:00
}
}
}
}
2008-08-25 19:28:25 +02:00
sub preprocess (@) {
2008-08-25 19:28:25 +02:00
my %params=@_;
$pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
2008-08-25 19:28:25 +02:00
my @pluginlist;
if (defined $params{generated}) {
@pluginlist = @fulllist;
}
else {
@pluginlist = @shortlist;
2008-08-25 19:28:25 +02:00
}
my $result = '<ul class="listdirectives">';
2008-08-25 19:28:25 +02:00
foreach my $plugin (@pluginlist) {
$result .= '<li class="listdirectives">';
2008-09-27 20:14:36 +02:00
my $link=linkpage($config{directive_description_dir}."/".$plugin);
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-08-25 19:28:25 +02:00
1