summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/listdirectives.pm
blob: 835e253886d67e2223bab034643c4823fa8d23bb (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. return $needsbuild;
  60. }
  61. sub preprocess (@) {
  62. my %params=@_;
  63. $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
  64. my @pluginlist;
  65. if (defined $params{generated}) {
  66. @pluginlist = @fulllist;
  67. }
  68. else {
  69. @pluginlist = @shortlist;
  70. }
  71. my $result = '<ul class="listdirectives">';
  72. foreach my $plugin (@pluginlist) {
  73. $result .= '<li class="listdirectives">';
  74. my $link=linkpage($config{directive_description_dir}."/".$plugin);
  75. add_depends($params{page}, $link, deptype("presence"));
  76. $result .= htmllink($params{page}, $params{destpage}, $link);
  77. $result .= '</li>';
  78. }
  79. $result .= "</ul>";
  80. return $result;
  81. }
  82. 1