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]]
3 > Good idea, I do see a few problems:
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
16 > (Maybe adding that is more involved than you want to go though..)
21 # Ikiwiki listplugins plugin.
22 package IkiWiki::Plugin::listplugins;
29 hook(type => "getsetup", id => "listplugins", call => \&getsetup);
30 hook(type => "needsbuild", id => "listplugins", call => \&needsbuild);
31 hook(type => "preprocess", id => "listplugins", call => \&preprocess);
34 sub getsetup () { #{{{
45 sub needsbuild (@) { #{{{
48 my @rawpluginlist = sort(IkiWiki::listplugins());
51 foreach my $plugin (@rawpluginlist) {
52 if ( exists $IkiWiki::hooks{preprocess}{$plugin} ) {
53 push(@pluginlist,$plugin);
57 $pluginString = join (' ', @pluginlist);
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};
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
69 delete $pagestate{$page}{listplugins}{shown};
75 sub preprocess (@) { #{{{
78 $pagestate{$params{destpage}}{listplugins}{shown}=$pluginString;
80 my $result = "<ul class=\"pluginlist\">";
82 foreach $thisPlugin (@pluginlist) {
83 $result .= "<li class=\"pluginlist\">$thisPlugin</li>";