summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/listdirectives.pm
blob: 4023ed7d75fd4b2582b7fe00265a5ac6a449619c (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. },
  20. directive_description_dir => {
  21. type => "string",
  22. description => "directory in srcdir that contains directive descriptions",
  23. example => "ikiwiki/directive",
  24. safe => 1,
  25. rebuild => 1,
  26. },
  27. }
  28. my @fulllist;
  29. my @shortlist;
  30. my $pluginstring;
  31. sub checkconfig () {
  32. if (! defined $config{directive_description_dir}) {
  33. $config{directive_description_dir} = "ikiwiki/directive";
  34. }
  35. else {
  36. $config{directive_description_dir} =~ s/\/+$//;
  37. }
  38. }
  39. sub needsbuild (@) {
  40. my $needsbuild=shift;
  41. @fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
  42. @shortlist = grep { ! $IkiWiki::hooks{preprocess}{$_}{shortcut} } @fulllist;
  43. $pluginstring = join(' ', @shortlist) . " : " . join(' ', @fulllist);
  44. foreach my $page (keys %pagestate) {
  45. if (exists $pagestate{$page}{listdirectives}{shown}) {
  46. if ($pagestate{$page}{listdirectives}{shown} ne $pluginstring) {
  47. push @$needsbuild, $pagesources{$page};
  48. }
  49. if (exists $pagesources{$page} &&
  50. grep { $_ eq $pagesources{$page} } @$needsbuild) {
  51. # remove state, will be re-added if
  52. # the [[!listdirectives]] is still there during the
  53. # rebuild
  54. delete $pagestate{$page}{listdirectives}{shown};
  55. }
  56. }
  57. }
  58. }
  59. sub preprocess (@) {
  60. my %params=@_;
  61. $pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
  62. my @pluginlist;
  63. if (defined $params{generated}) {
  64. @pluginlist = @fulllist;
  65. }
  66. else {
  67. @pluginlist = @shortlist;
  68. }
  69. my $result = '<ul class="listdirectives">';
  70. foreach my $plugin (@pluginlist) {
  71. $result .= '<li class="listdirectives">';
  72. my $link=linkpage($config{directive_description_dir}."/".$plugin);
  73. add_depends($params{page}, $link, presence => 1);
  74. $result .= htmllink($params{page}, $params{destpage}, $link);
  75. $result .= '</li>';
  76. }
  77. $result .= "</ul>";
  78. return $result;
  79. }
  80. 1