diff options
author | http://www.cse.unsw.edu.au/~willu/ <http://www.cse.unsw.edu.au/~willu/@web> | 2008-08-21 09:58:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2008-08-21 09:58:25 -0400 |
commit | bb1addc292492a82086c6591f591832ca720a096 (patch) | |
tree | 2a6cd53f1303c608162fe8b6ba740db7776063e4 | |
parent | cb919de70f95995aec67565f6c28583229438747 (diff) |
New plugin to list available pre-processor commands
-rw-r--r-- | doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn b/doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn new file mode 100644 index 000000000..4ec9107e3 --- /dev/null +++ b/doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn @@ -0,0 +1,73 @@ +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]] + + #!/usr/bin/perl + # Ikiwiki listplugins plugin. + package IkiWiki::Plugin::listplugins; + + use warnings; + use strict; + use IkiWiki 2.00; + + sub import { #{{{ + hook(type => "getsetup", id => "listplugins", call => \&getsetup); + hook(type => "needsbuild", id => "listplugins", call => \&needsbuild); + hook(type => "preprocess", id => "listplugins", call => \&preprocess); + } # }}} + + sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => undef, + }, + } #}}} + + my @pluginlist; + my $pluginString; + + sub needsbuild (@) { #{{{ + my $needsbuild=shift; + + my @rawpluginlist = sort(IkiWiki::listplugins()); + @pluginlist = (); + + foreach my $plugin (@rawpluginlist) { + if ( exists $IkiWiki::hooks{preprocess}{$plugin} ) { + push(@pluginlist,$plugin); + } + } + + $pluginString = join (' ', @pluginlist); + + foreach my $page (keys %pagestate) { + if (exists $pagestate{$page}{listplugins}{shown}) { + if ($pagestate{$page}{listplugins}{shown} ne $pluginString) { + push @$needsbuild, $pagesources{$page}; + } + if (exists $pagesources{$page} && + grep { $_ eq $pagesources{$page} } @$needsbuild) { + # remove state, will be re-added if + # the version is still shown during the + # rebuild + delete $pagestate{$page}{listplugins}{shown}; + } + } + } + } # }}} + + sub preprocess (@) { #{{{ + my %params=@_; + + $pagestate{$params{destpage}}{listplugins}{shown}=$pluginString; + + my $result = "<ul class=\"pluginlist\">"; + my $thisPlugin; + foreach $thisPlugin (@pluginlist) { + $result .= "<li class=\"pluginlist\">$thisPlugin</li>"; + } + $result .= "</ul>"; + + return $result; + } # }}} + + 1 |