]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/listdirectives.pm
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[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                         section => "widget",
23                 },
24                 directive_description_dir => {
25                         type => "string",
26                         description => "directory in srcdir that contains directive descriptions",
27                         example => "ikiwiki/directive",
28                         safe => 1,
29                         rebuild => 1,
30                 },
31 }
33 my @fulllist;
34 my @shortlist;
35 my $pluginstring;
37 sub checkconfig () {
38         if (! defined $config{directive_description_dir}) {
39                 $config{directive_description_dir} = "ikiwiki/directive";
40         }
41         else {
42                 $config{directive_description_dir} =~ s/\/+$//;
43         }
44 }
46 sub needsbuild (@) {
47         my $needsbuild=shift;
49         @fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
50         @shortlist = grep { ! $IkiWiki::hooks{preprocess}{$_}{shortcut} } @fulllist;
51         $pluginstring = join(' ', @shortlist) . " : " . 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};
57                         }
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
62                                 # rebuild
63                                 delete $pagestate{$page}{listdirectives}{shown};
64                         }
65                 }
66         }
67 }
69 sub preprocess (@) {
70         my %params=@_;
71         
72         $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
73         
74         my @pluginlist;
75         
76         if (defined $params{generated}) {
77                 @pluginlist = @fulllist;
78         }
79         else {
80                 @pluginlist = @shortlist;
81         }
82         
83         my $result = '<ul class="listdirectives">';
84         
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, deptype("presence"));
89                 $result .= htmllink($params{page}, $params{destpage}, $link);
90                 $result .= '</li>';
91         }
92         
93         $result .= "</ul>";
95         return $result;
96 }
98 1