]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/listdirectives.pm
fe4aee3bbb8393a60941f32bd1092341ec8da230
[ikiwiki.git] / IkiWiki / Plugin / listdirectives.pm
1 #!/usr/bin/perl
2 # Ikiwiki listdirectives plugin.
3 package IkiWiki::Plugin::listdirectives;
4
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
8
9 sub import { #{{{
10         hook(type => "getsetup", id => "listdirectives", call => \&getsetup);
11         hook(type => "checkconfig", id => "listdirectives", call => \&checkconfig);
12         hook(type => "needsbuild", id => "listdirectives", call => \&needsbuild);
13         hook(type => "preprocess", id => "listdirectives", call => \&preprocess);
14 } # }}}
15
16 sub getsetup () { #{{{
17         return
18                 plugin => {
19                         safe => 1,
20                         rebuild => undef,
21                 },
22                 directive_description_dir => {
23                         type => "string",
24                         description => "directory in srcdir that contains PreprocessorDirective descriptions",
25                         example => "ikiwiki/plugin",
26                         safe => 1,
27                         rebuild => 1,
28                 },
29 } #}}}
30
31 my @fulllist;
32 my @earlylist;
33 my $pluginstring;
34
35 sub checkconfig () { #{{{
36         if (! defined $config{directive_description_dir}) {
37                 $config{directive_description_dir} = "ikiwiki/plugin";
38         }
39         else {
40                 $config{directive_description_dir}=~s/\/+$//;
41         }
42
43         @earlylist = sort( keys %{ $IkiWiki::hooks{preprocess} } );
44 } #}}}
45
46 sub needsbuild (@) { #{{{
47         my $needsbuild=shift;
48
49         @fulllist = sort( keys %{ $IkiWiki::hooks{preprocess} } );
50         $pluginstring = join (' ', @earlylist) . " : ". join (' ', @fulllist);
51
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 } # }}}
67
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 = @earlylist;
80         }
81         
82         my $result = '<ul class="listdirectives">';
83         
84         foreach my $plugin (@pluginlist) {
85                 $result .= '<li class="listdirectives">';
86                 $result .= htmllink($params{page}, $params{destpage},
87                         IkiWiki::linkpage($config{directive_description_dir}."/".$plugin));
88                 $result .= '</li>';
89         }
90         
91         $result .= "</ul>";
92
93         return $result;
94 } # }}}
95
96 1