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