ikiwiki/IkiWiki/Setup/Standard.pm

98 lines
2.1 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
# Standard ikiwiki setup module.
# Parameters to import should be all the standard ikiwiki config stuff,
2006-04-21 18:39:59 +02:00
# plus an array of wrappers to set up.
package IkiWiki::Setup::Standard;
use warnings;
use strict;
sub import { #{{{
$IkiWiki::Setup::raw_setup=$_[1];
} #}}}
2008-07-26 18:46:31 +02:00
package IkiWiki::Setup;
2008-07-26 18:01:10 +02:00
sub dumpline ($$$) { #{{{
my $key=shift;
my $value=shift;
my $prefix=shift;
2008-07-26 18:46:31 +02:00
eval q{use Data::Dumper};
error($@) if $@;
local $Data::Dumper::Terse=1;
local $Data::Dumper::Indent=1;
local $Data::Dumper::Pad="\t";
local $Data::Dumper::Sortkeys=1;
local $Data::Dumper::Quotekeys=0;
2008-07-26 18:01:10 +02:00
my $dumpedvalue=Dumper($value);
chomp $dumpedvalue;
$dumpedvalue=~s/^\t//;
return "\t$prefix$key=$dumpedvalue,";
} #}}}
2008-07-26 18:46:31 +02:00
sub dumpvalues ($@) { #{{{
2008-07-26 18:01:10 +02:00
my $setup=shift;
my @ret;
while (@_) {
my $key=shift;
my %info=%{shift()};
push @ret, "\t# ".$info{description} if exists $info{description};
if (exists $setup->{$key} && defined $setup->{$key}) {
push @ret, dumpline($key, $setup->{$key}, "");
delete $setup->{$key};
}
elsif (exists $info{default}) {
push @ret, dumpline($key, $info{default}, "#");
}
elsif (exists $info{example}) {
push @ret, dumpline($key, $info{example}, "#");
}
}
return @ret;
} #}}}
2008-07-26 18:46:31 +02:00
sub dump ($) { #{{{
my $file=shift;
2008-07-26 18:01:10 +02:00
2008-07-26 18:46:31 +02:00
my %setup=(%config);
2008-07-26 18:01:10 +02:00
my @ret;
2008-07-26 18:46:31 +02:00
2008-07-26 18:01:10 +02:00
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 plugin";
2008-07-26 18:46:31 +02:00
push @ret, dumpvalues(\%setup, @s);
2008-07-26 18:01:10 +02:00
push @ret, "";
}
if (%setup) {
push @ret, "\t# other";
foreach my $key (sort keys %setup) {
push @ret, dumpline($key, $setup{$key}, "");
}
}
unshift @ret, "#!/usr/bin/perl
# Setup file for ikiwiki.
# Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
# build the wiki.
#
# Remember to re-run ikiwiki --setup any time you edit this file.
use IkiWiki::Setup::Standard {";
push @ret, "}";
2008-07-26 18:46:31 +02:00
open (OUT, ">", $file) || die "$file: $!";
print OUT "$_\n" foreach @ret;
close OUT;
} #}}}
1