<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Ikiwiki listdirectives plugin.
package IkiWiki::Plugin::listdirectives;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	add_underlay("directives");
	hook(type =&gt; "getsetup", id =&gt; "listdirectives", call =&gt; \&amp;getsetup);
	hook(type =&gt; "checkconfig", id =&gt; "listdirectives", call =&gt; \&amp;checkconfig);
	hook(type =&gt; "needsbuild", id =&gt; "listdirectives", call =&gt; \&amp;needsbuild);
	hook(type =&gt; "preprocess", id =&gt; "listdirectives", call =&gt; \&amp;preprocess);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; undef,
			section =&gt; "widget",
		},
		directive_description_dir =&gt; {
			type =&gt; "string",
			description =&gt; "directory in srcdir that contains directive descriptions",
			example =&gt; "ikiwiki/directive",
			safe =&gt; 1,
			rebuild =&gt; 1,
		},
}

my @fulllist;
my @shortlist;
my $pluginstring;

sub checkconfig () {
	if (! defined $config{directive_description_dir}) {
		$config{directive_description_dir} = "ikiwiki/directive";
	}
	else {
		$config{directive_description_dir} =~ s/\/+$//;
	}
}

sub needsbuild (@) {
	my $needsbuild=shift;

	@fulllist = grep { ! /^_/ } sort keys %{$IkiWiki::hooks{preprocess}};
	@shortlist = grep { ! $IkiWiki::hooks{preprocess}{$_}{shortcut} } @fulllist;
	$pluginstring = join(' ', @shortlist) . " : " . join(' ', @fulllist);

	foreach my $page (keys %pagestate) {
		if (exists $pagestate{$page}{listdirectives}{shown}) {
			if ($pagestate{$page}{listdirectives}{shown} ne $pluginstring) {
				push @$needsbuild, $pagesources{$page};
			}
			if (exists $pagesources{$page} &amp;&amp;
			    grep { $_ eq $pagesources{$page} } @$needsbuild) {
				# remove state, will be re-added if
				# the [[!listdirectives]] is still there during the
				# rebuild
				delete $pagestate{$page}{listdirectives}{shown};
			}
		}
	}

	return $needsbuild;
}

sub preprocess (@) {
	my %params=@_;
	
	$pagestate{$params{destpage}}{listdirectives}{shown}=$pluginstring;
	
	my @pluginlist;
	
	if (defined $params{generated}) {
		@pluginlist = @fulllist;
	}
	else {
		@pluginlist = @shortlist;
	}
	
	my $result = '&lt;ul class="listdirectives"&gt;';
	
	foreach my $plugin (@pluginlist) {
		$result .= '&lt;li class="listdirectives"&gt;';
		my $link=linkpage($config{directive_description_dir}."/".$plugin);
		add_depends($params{page}, $link, deptype("presence"));
		$result .= htmllink($params{page}, $params{destpage}, $link);
		$result .= '&lt;/li&gt;';
	}
	
	$result .= "&lt;/ul&gt;";

	return $result;
}

1
</pre></body></html>