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