2 # Ikiwiki listdirectives plugin.
3 package IkiWiki::Plugin::listdirectives;
10 add_underlay("directives");
11 hook(type => "getsetup", id => "listdirectives", call => \&getsetup);
12 hook(type => "checkconfig", id => "listdirectives", call => \&checkconfig);
13 hook(type => "needsbuild", id => "listdirectives", call => \&needsbuild);
14 hook(type => "preprocess", id => "listdirectives", call => \&preprocess);
17 sub getsetup () { #{{{
23 directive_description_dir => {
25 description => "directory in srcdir that contains directive descriptions",
26 example => "ikiwiki/directive",
36 sub checkconfig () { #{{{
37 if (! defined $config{directive_description_dir}) {
38 $config{directive_description_dir} = "ikiwiki/directive";
41 $config{directive_description_dir} =~ s/\/+$//;
44 @earlylist = sort keys %{$IkiWiki::hooks{preprocess}};
47 sub needsbuild (@) { #{{{
50 @fulllist = sort keys %{$IkiWiki::hooks{preprocess}};
51 $pluginstring = join(' ', @earlylist) . " : " . join(' ', @fulllist);
53 foreach my $page (keys %pagestate) {
54 if (exists $pagestate{$page}{listdirectives}{shown}) {
55 if ($pagestate{$page}{listdirectives}{shown} ne $pluginstring) {
56 push @$needsbuild, $pagesources{$page};
58 if (exists $pagesources{$page} &&
59 grep { $_ eq $pagesources{$page} } @$needsbuild) {
60 # remove state, will be re-added if
61 # the [[!listdirectives]] is still there during the
63 delete $pagestate{$page}{listdirectives}{shown};
69 sub preprocess (@) { #{{{
72 $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
76 if (defined $params{generated}) {
77 @pluginlist = @fulllist;
80 @pluginlist = @earlylist;
83 my $result = '<ul class="listdirectives">';
85 foreach my $plugin (@pluginlist) {
86 $result .= '<li class="listdirectives">';
87 my $link=linkpage($config{directive_description_dir}."/".$plugin);
88 add_depends($params{page}, $link);
89 $result .= htmllink($params{page}, $params{destpage}, $link);