load all plugins when generating setup

master
Joey Hess 2008-07-26 19:10:11 -04:00
parent f892cc8c50
commit 52bbdbb1a5
4 changed files with 42 additions and 19 deletions

View File

@ -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});

View File

@ -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,

View File

@ -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,

View File

@ -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.