From 52bbdbb1a5ce994c9afac253c1d9bfd94acf4d1d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 26 Jul 2008 19:10:11 -0400 Subject: [PATCH] load all plugins when generating setup --- IkiWiki.pm | 20 ++++++++++++++++++++ IkiWiki/Plugin/prettydate.pm | 4 ++-- IkiWiki/Setup/Standard.pm | 32 ++++++++++++++++++-------------- doc/plugins/write.mdwn | 5 ++--- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 4410fc985..a2b9a3e24 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -417,6 +417,26 @@ sub checkconfig () { #{{{ return 1; } #}}} +sub listplugins () { #{{{ + my %ret; + + foreach my $dir (@INC, $config{libdir}) { + next unless defined $dir; + foreach my $file (glob("$dir/IkiWiki/Plugin/*.pm")) { + my ($plugin)=$file=~/.*\/(.*)\.pm$/; + $ret{$plugin}=1; + } + } + foreach my $dir ($config{libdir}, "$installdir/lib/ikiwiki") { + next unless defined $dir; + foreach my $file (glob("$dir/plugins/*")) { + $ret{basename($file)}=1 if -x $file; + } + } + + return keys %ret; +} #}}} + sub loadplugins () { #{{{ if (defined $config{libdir}) { unshift @INC, possibly_foolish_untaint($config{libdir}); diff --git a/IkiWiki/Plugin/prettydate.pm b/IkiWiki/Plugin/prettydate.pm index 29330f29f..080317f06 100644 --- a/IkiWiki/Plugin/prettydate.pm +++ b/IkiWiki/Plugin/prettydate.pm @@ -54,8 +54,8 @@ sub getsetup () { #{{{ rebuild => 1, }, timetable => { - type => undef, # don't try to show in interface - default => '%X, %B %o, %Y', + type => "internal", + default => undef, description => "array of time descriptions", safe => 1, rebuild => 1, diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index b8ad09144..d8547ba5f 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -78,22 +78,26 @@ sub gendump ($) { #{{{ push @ret, "\t# basic setup"; push @ret, dumpvalues(\%setup, IkiWiki::getsetup()); - push @ret, ""; - # sort rcs plugin first - my @plugins=sort { - ($a eq $config{rcs}) <=> ($b eq $config{rcs}) - || - $a cmp $b - } keys %{$IkiWiki::hooks{getsetup}}; + # Load all plugins, so that all setup options are available. + my @plugins=sort(IkiWiki::listplugins()); + foreach my $plugin (@plugins) { + eval { IkiWiki::loadplugin($plugin) }; + if (exists $IkiWiki::hooks{checkconfig}{$plugin}{call}) { + my @s=eval { $IkiWiki::hooks{checkconfig}{$plugin}{call}->() }; + } + } + unshift @plugins, $config{rcs} if $config{rcs}; - foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) { - # use an array rather than a hash, to preserve order - my @s=$IkiWiki::hooks{getsetup}{$id}{call}->(); - return unless @s; - push @ret, "\t# $id".($id ne $config{rcs} ? " plugin" : ""); - push @ret, dumpvalues(\%setup, @s); - push @ret, ""; + foreach my $id (@plugins) { + my $title="\t# $id".($id ne $config{rcs} ? " plugin" : ""); + if (exists $IkiWiki::hooks{getsetup}{$id}{call}) { + # use an array rather than a hash, to preserve order + my @s=eval { $IkiWiki::hooks{getsetup}{$id}{call}->() }; + next unless @s; + push @ret, "", $title; + push @ret, dumpvalues(\%setup, @s); + } } unshift @ret, diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index faf164358..9a844ca06 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -390,9 +390,8 @@ describing the option. For example: }, * `type` can be "boolean", "string", "integer", "internal" (used for values - that are not user-visible) or `undef` (use for complex types). Note that - the type is the type of the leaf values; the `%config` option may be an - array or hash of these. + that are not user-visible). The type is the type of the leaf values; + the `%config` option may be an array or hash of these. * `default` should be set to the default value of the option, if any. * `example` can be set to an example value, which will not be used by default. * `description` is a short description of the option. -- 2.44.0