]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn
edf71361b3a530037bbe62a51d0b9d806de6cfb6
[ikiwiki.git] / doc / todo / Add_a_plugin_to_list_available_pre-processor_commands.mdwn
1 I've found myself wanting to know which [[plugins]] are switched on so I know which pre-processor commands I can use.  The attached [[patch]] adds a new plugin that generates the list of available plugins. -- [[Will]]
2
3 > Good idea, I do see a few problems:
4
5 > - preprocessor directives do not necessarily have the same name as the
6 >   plugin that contains them (for example, the graphviz plugin adds a graph
7 >   directive). Won't keys `%{IkiWiki::hooks{preprocess}}` work?
8 > - "listplugins" is a bit misnamed since it only does preprocessor directives.
9 > - comment was copied from version plugin and still mentions version :-)
10 > - Seems like [[ikiwiki/formatting]] could benefit from including the
11 >   list.. however, just a list of preprocessor directive names is not
12 >   the most user-friendly thing that could be put on that page. It would
13 >   be nice if there were also a short description and maybe an example of
14 >   use. Seems like the place to include that info would be in the call
15 >   to `hook()`.
16 >   (Maybe adding that is more involved than you want to go though..)
17
18 > --[[Joey]]
19
20     #!/usr/bin/perl
21     # Ikiwiki listplugins plugin.
22     package IkiWiki::Plugin::listplugins;
23     
24     use warnings;
25     use strict;
26     use IkiWiki 2.00;
27     
28     sub import { #{{{
29         hook(type => "getsetup", id => "listplugins", call => \&getsetup);
30         hook(type => "needsbuild", id => "listplugins", call => \&needsbuild);
31         hook(type => "preprocess", id => "listplugins", call => \&preprocess);
32     } # }}}
33     
34     sub getsetup () { #{{{
35         return
36                 plugin => {
37                         safe => 1,
38                         rebuild => undef,
39                 },
40     } #}}}
41     
42     my @pluginlist;
43     my $pluginString;
44     
45     sub needsbuild (@) { #{{{
46         my $needsbuild=shift;
47     
48         my @rawpluginlist = sort(IkiWiki::listplugins());
49         @pluginlist = ();
50         
51         foreach my $plugin (@rawpluginlist) {
52                 if ( exists $IkiWiki::hooks{preprocess}{$plugin} ) {
53                         push(@pluginlist,$plugin);
54                 }
55         }
56     
57         $pluginString = join (' ', @pluginlist);
58     
59         foreach my $page (keys %pagestate) {
60                 if (exists $pagestate{$page}{listplugins}{shown}) {
61                         if ($pagestate{$page}{listplugins}{shown} ne $pluginString) {
62                                 push @$needsbuild, $pagesources{$page};
63                         }
64                         if (exists $pagesources{$page} &&
65                             grep { $_ eq $pagesources{$page} } @$needsbuild) {
66                                 # remove state, will be re-added if
67                                 # the version is still shown during the
68                                 # rebuild
69                                 delete $pagestate{$page}{listplugins}{shown};
70                         }
71                 }
72         }
73     } # }}}
74     
75     sub preprocess (@) { #{{{
76         my %params=@_;
77         
78         $pagestate{$params{destpage}}{listplugins}{shown}=$pluginString;
79         
80         my $result = "<ul class=\"pluginlist\">";
81         my $thisPlugin;
82         foreach $thisPlugin (@pluginlist) {
83                 $result .= "<li class=\"pluginlist\">$thisPlugin</li>";
84         }
85         $result .= "</ul>";
86         
87         return $result;
88     } # }}}
89     
90     1