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?
9 >>> Er, yeah - that's a much better solution. :)
11 > - "listplugins" is a bit misnamed since it only does preprocessor directives.
13 >>> Yes. Initially this was going to list all enabled plugins. Then when searching
14 >>> for enabled plugins I changed my mind and decided that a list of pre-processor
15 >>> directives was more useful. I'll fix that too.
17 > - comment was copied from version plugin and still mentions version :-)
21 > - Seems like [[ikiwiki/formatting]] could benefit from including the
22 > list.. however, just a list of preprocessor directive names is not
23 > the most user-friendly thing that could be put on that page. It would
24 > be nice if there were also a short description and maybe an example of
25 > use. Seems like the place to include that info would be in the call
27 > (Maybe adding that is more involved than you want to go though..)
31 >> Adding a whole new hook for a usage example is more effort than I
32 >> wanted to go to. I was thinking of either:
34 >> - Adding a configuration for a wiki directory. If a matching page is in the
35 >> specified wiki directory then the plugin name gets turned into a link to that
37 >> - Adding configuration for an external URL. Each plugin name is added as
38 >> a link to the plugin name appended to the URL.
40 >>The first option is easier to navigate and wouldn't produce broken links,
41 >>but requires all the plugin documentation to be local. The second option
42 >>can link back to the main IkiWiki site, but if you have any non-standard
43 >>plugins then you'll get broken links.
45 >>Hrm. After listing all of that, maybe your idea with the hooks is the better
46 >>solution. I'll think about it some more. -- [[Will]]
49 # Ikiwiki listplugins plugin.
50 package IkiWiki::Plugin::listplugins;
57 hook(type => "getsetup", id => "listplugins", call => \&getsetup);
58 hook(type => "needsbuild", id => "listplugins", call => \&needsbuild);
59 hook(type => "preprocess", id => "listplugins", call => \&preprocess);
62 sub getsetup () { #{{{
73 sub needsbuild (@) { #{{{
76 my @rawpluginlist = sort(IkiWiki::listplugins());
79 foreach my $plugin (@rawpluginlist) {
80 if ( exists $IkiWiki::hooks{preprocess}{$plugin} ) {
81 push(@pluginlist,$plugin);
85 $pluginString = join (' ', @pluginlist);
87 foreach my $page (keys %pagestate) {
88 if (exists $pagestate{$page}{listplugins}{shown}) {
89 if ($pagestate{$page}{listplugins}{shown} ne $pluginString) {
90 push @$needsbuild, $pagesources{$page};
92 if (exists $pagesources{$page} &&
93 grep { $_ eq $pagesources{$page} } @$needsbuild) {
94 # remove state, will be re-added if
95 # the version is still shown during the
97 delete $pagestate{$page}{listplugins}{shown};
103 sub preprocess (@) { #{{{
106 $pagestate{$params{destpage}}{listplugins}{shown}=$pluginString;
108 my $result = "<ul class=\"pluginlist\">";
110 foreach $thisPlugin (@pluginlist) {
111 $result .= "<li class=\"pluginlist\">$thisPlugin</li>";