my $dumpedvalue;
if ($type eq 'boolean' || $type eq 'integer') {
+ # avoid quotes
$dumpedvalue=$value;
}
+ elsif ($type eq 'string' && ref $value eq 'ARRAY' && @$value &&
+ ! grep { /[^-A-Za-z0-9_]/ } @$value) {
+ # dump simple array as qw{}
+ $dumpedvalue="[qw{ ".join(" ", @$value)." }]";
+ }
else {
$dumpedvalue=Dumper($value);
chomp $dumpedvalue;
$dumpedvalue=~s/^\t//;
}
- return "\t$prefix$key=$dumpedvalue,";
+ return "\t$prefix$key => $dumpedvalue,";
} #}}}
sub dumpvalues ($@) { #{{{
return @ret;
} #}}}
-sub dump ($) { #{{{
- my $file=IkiWiki::possibly_foolish_untaint(shift);
-
+sub gendump ($) { #{{{
+ my $description=shift;
my %setup=(%config);
my @ret;
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}};
+
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";
+ push @ret, "\t# $id".($id ne $config{rcs} ? " plugin" : "");
push @ret, dumpvalues(\%setup, @s);
push @ret, "";
}
- 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 {";
+ unshift @ret,
+ "#!/usr/bin/perl",
+ "# $description",
+ "#",
+ "# 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, "}";
- open (OUT, ">", $file) || die "$file: $!";
- print OUT "$_\n" foreach @ret;
- close OUT;
+ return @ret;
} #}}}
1