]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/listdirectives.pm
403 response may be a "not found" too
[git.ikiwiki.info.git] / IkiWiki / Plugin / listdirectives.pm
1 #!/usr/bin/perl
2 # Ikiwiki listdirectives plugin.
3 package IkiWiki::Plugin::listdirectives;
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
9 sub import {
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);
15 }
17 sub getsetup () {
18         return
19                 plugin => {
20                         safe => 1,
21                         rebuild => undef,
22                 },
23                 directive_description_dir => {
24                         type => "string",
25                         description => "directory in srcdir that contains directive descriptions",
26                         example => "ikiwiki/directive",
27                         safe => 1,
28                         rebuild => 1,
29                 },
30 }
32 my @fulllist;
33 my @shortlist;
34 my $pluginstring;
36 sub checkconfig () {
37         if (! defined $config{directive_description_dir}) {
38                 $config{directive_description_dir} = "ikiwiki/directive";
39         }
40         else {
41                 $config{directive_description_dir} =~ s/\/+$//;
42         }
43 }
45 sub needsbuild (@) {
46         my $needsbuild=shift;
48         @fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
49         @shortlist = grep { ! $IkiWiki::hooks{preprocess}{$_}{shortcut} } @fulllist;
50         $pluginstring = join(' ', @shortlist) . " : " . join(' ', @fulllist);
52         foreach my $page (keys %pagestate) {
53                 if (exists $pagestate{$page}{listdirectives}{shown}) {
54                         if ($pagestate{$page}{listdirectives}{shown} ne $pluginstring) {
55                                 push @$needsbuild, $pagesources{$page};
56                         }
57                         if (exists $pagesources{$page} &&
58                             grep { $_ eq $pagesources{$page} } @$needsbuild) {
59                                 # remove state, will be re-added if
60                                 # the [[!listdirectives]] is still there during the
61                                 # rebuild
62                                 delete $pagestate{$page}{listdirectives}{shown};
63                         }
64                 }
65         }
66 }
68 sub preprocess (@) {
69         my %params=@_;
70         
71         $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
72         
73         my @pluginlist;
74         
75         if (defined $params{generated}) {
76                 @pluginlist = @fulllist;
77         }
78         else {
79                 @pluginlist = @shortlist;
80         }
81         
82         my $result = '<ul class="listdirectives">';
83         
84         foreach my $plugin (@pluginlist) {
85                 $result .= '<li class="listdirectives">';
86                 my $link=linkpage($config{directive_description_dir}."/".$plugin);
87                 add_depends($params{page}, $link, deptype("presence"));
88                 $result .= htmllink($params{page}, $params{destpage}, $link);
89                 $result .= '</li>';
90         }
91         
92         $result .= "</ul>";
94         return $result;
95 }
97 1