summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/listpreprocessors.pm
blob: ae5e1a7c4079a529bb0d013be874070b6ff89b76 (plain)
  1. #!/usr/bin/perl
  2. # Ikiwiki listpreprocessors plugin.
  3. package IkiWiki::Plugin::listpreprocessors;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. sub import { #{{{
  8. hook(type => "getsetup", id => "listpreprocessors", call => \&getsetup);
  9. hook(type => "checkconfig", id => "listpreprocessors", call => \&checkconfig);
  10. hook(type => "needsbuild", id => "listpreprocessors", call => \&needsbuild);
  11. hook(type => "preprocess", id => "listpreprocessors", call => \&preprocess);
  12. } # }}}
  13. sub getsetup () { #{{{
  14. return
  15. plugin => {
  16. safe => 1,
  17. rebuild => undef,
  18. },
  19. preprocessor_description_dir => {
  20. type => "string",
  21. description => "The ikiwiki directory that contains plugin descriptions.",
  22. safe => 1,
  23. rebuild => 1,
  24. },
  25. } #}}}
  26. my @fullPluginList;
  27. my @earlyPluginList;
  28. my $pluginString;
  29. sub checkconfig () { #{{{
  30. if (!defined $config{plugin_description_dir}) {
  31. $config{plugin_description_dir} = "ikiwiki/plugin/";
  32. }
  33. @earlyPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
  34. } #}}}
  35. sub needsbuild (@) { #{{{
  36. my $needsbuild=shift;
  37. @fullPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
  38. $pluginString = join (' ', @earlyPluginList) . " : ". join (' ', @fullPluginList);
  39. foreach my $page (keys %pagestate) {
  40. if (exists $pagestate{$page}{listpreprocessors}{shown}) {
  41. if ($pagestate{$page}{listpreprocessors}{shown} ne $pluginString) {
  42. push @$needsbuild, $pagesources{$page};
  43. }
  44. if (exists $pagesources{$page} &&
  45. grep { $_ eq $pagesources{$page} } @$needsbuild) {
  46. # remove state, will be re-added if
  47. # the [[!listpreprocessors]] is still there during the
  48. # rebuild
  49. delete $pagestate{$page}{listpreprocessors}{shown};
  50. }
  51. }
  52. }
  53. } # }}}
  54. sub preprocess (@) { #{{{
  55. my %params=@_;
  56. $pagestate{$params{destpage}}{listpreprocessors}{shown}=$pluginString;
  57. my @pluginlist;
  58. if (defined $params{generated}) {
  59. @pluginlist = @fullPluginList;
  60. } else {
  61. @pluginlist = @earlyPluginList;
  62. }
  63. my $result = '<ul class="listpreprocessors">';
  64. foreach my $plugin (@pluginlist) {
  65. $result .= '<li class="listpreprocessors">';
  66. $result .= htmllink($params{page}, $params{destpage}, IkiWiki::linkpage($config{plugin_description_dir} . $plugin));
  67. $result .= '</li>';
  68. }
  69. $result .= "</ul>";
  70. return $result;
  71. } # }}}
  72. 1