]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/listpreprocessors.pm
plugin by willu
[ikiwiki.git] / IkiWiki / Plugin / listpreprocessors.pm
1 #!/usr/bin/perl
2 # Ikiwiki listpreprocessors plugin.
3 package IkiWiki::Plugin::listpreprocessors;
4
5 use warnings;
6 use strict;
7 use IkiWiki 2.00;
8
9 sub import { #{{{
10         hook(type => "getsetup", id => "listpreprocessors", call => \&getsetup);
11         hook(type => "checkconfig", id => "listpreprocessors", call => \&checkconfig);
12         hook(type => "needsbuild", id => "listpreprocessors", call => \&needsbuild);
13         hook(type => "preprocess", id => "listpreprocessors", call => \&preprocess);
14 } # }}}
15
16 sub getsetup () { #{{{
17         return
18                 plugin => {
19                         safe => 1,
20                         rebuild => undef,
21                 },
22                 preprocessor_description_dir => {
23                         type => "string",
24                         description => "The ikiwiki directory that contains plugin descriptions.",
25                         safe => 1,
26                         rebuild => 1,
27                 },
28 } #}}}
29
30 my @fullPluginList;
31 my @earlyPluginList;
32 my $pluginString;
33
34 sub checkconfig () { #{{{
35     if (!defined $config{plugin_description_dir}) {
36         $config{plugin_description_dir} = "ikiwiki/plugin/";
37     }
38
39     @earlyPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
40 } #}}}
41
42 sub needsbuild (@) { #{{{
43         my $needsbuild=shift;
44
45         @fullPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
46         $pluginString = join (' ', @earlyPluginList) . " : ". join (' ', @fullPluginList);
47
48         foreach my $page (keys %pagestate) {
49                 if (exists $pagestate{$page}{listpreprocessors}{shown}) {
50                         if ($pagestate{$page}{listpreprocessors}{shown} ne $pluginString) {
51                                 push @$needsbuild, $pagesources{$page};
52                         }
53                         if (exists $pagesources{$page} &&
54                                         grep { $_ eq $pagesources{$page} } @$needsbuild) {
55                                 # remove state, will be re-added if
56                                 # the [[!listpreprocessors]] is still there during the
57                                 # rebuild
58                                 delete $pagestate{$page}{listpreprocessors}{shown};
59                         }
60                 }
61         }
62 } # }}}
63
64 sub preprocess (@) { #{{{
65         my %params=@_;
66         
67         $pagestate{$params{destpage}}{listpreprocessors}{shown}=$pluginString;
68         
69         my @pluginlist;
70         
71         if (defined $params{generated}) {
72                 @pluginlist = @fullPluginList;
73         } else {
74                 @pluginlist = @earlyPluginList;
75         }
76         
77         my $result = '<ul class="listpreprocessors">';
78         
79         foreach my $plugin (@pluginlist) {
80                 $result .= '<li class="listpreprocessors">';
81                 $result .= htmllink($params{page}, $params{destpage}, IkiWiki::linkpage($config{plugin_description_dir} . $plugin));
82                 $result .= '</li>';
83         }
84         
85         $result .= "</ul>";
86
87         return $result;
88 } # }}}
89
90 1