From 1c00717cb2737bde3870b2fe504f40bb7d215477 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 26 Jul 2008 15:34:38 -0400 Subject: [PATCH] can now dump fully functional setup files --- IkiWiki.pm | 65 ++++++++++++++++++++++++++++----------- IkiWiki/Setup.pm | 6 ++-- IkiWiki/Setup/Standard.pm | 8 ++++- ikiwiki.in | 10 +++--- 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 7b6c4d622..edbec77d6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -142,6 +142,27 @@ sub getsetup () { #{{{ safe => 0, # paranoia rebuild => 0, }, + wrappers => { + type => "string", + default => undef, + description => "definitions of wrappers to generate", + safe => 0, + rebuild => 0, + }, + wrapper => { + type => "internal", + default => undef, + description => "wrapper filename", + safe => 0, + rebuild => 0, + }, + wrappermode => { + type => "internal", + default => undef, + description => "mode of wrapper file", + safe => 0, + rebuild => 0, + }, templatedir => { type => "string", default => "$installdir/share/ikiwiki/templates", @@ -250,6 +271,14 @@ sub getsetup () { #{{{ rebuild => 0, }, + exclude => { + type => "string", + default => undef, + example => '\.wav$', + description => "regexp of source files to ignore", + safe => 0, # regexp + rebuild => 1, + }, wiki_file_prune_regexps => { type => "internal", default => [qr/(^|\/)\.\.(\/|$)/, qr/^\./, qr/\/\./, @@ -324,20 +353,6 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, - wrapper => { - type => "internal", - default => undef, - description => "wrapper file to generate", - safe => 0, - rebuild => 0, - }, - wrappermode => { - type => "internal", - default => undef, - description => "mode of wrapper file", - safe => 0, - rebuild => 0, - }, setup => { type => "internal", default => undef, @@ -345,13 +360,27 @@ sub getsetup () { #{{{ safe => 0, rebuild => 0, }, - plugin => { + default_plugins => { type => "internal", default => [qw{mdwn link inline htmlscrubber passwordauth openid signinedit lockedit conditional recentchanges parentlinks}], - description => "enabled plugins", - safe => 0, + description => "plugins to enable by default", + safe => 1, + rebuild => 1, + }, + add_plugins => { + type => "string", + default => [], + description => "plugins to add to the default configuration", + safe => 1, + rebuild => 1, + }, + disable_plugins => { + type => "string", + default => [], + description => "plugins to disable", + safe => 1, rebuild => 1, }, libdir => { @@ -434,7 +463,7 @@ sub loadplugins () { #{{{ unshift @INC, possibly_foolish_untaint($config{libdir}); } - loadplugin($_) foreach @{$config{plugin}}; + loadplugin($_) foreach @{$config{default_plugins}}, @{$config{add_plugins}}; run_hooks(getopt => sub { shift->() }); if (grep /^-/, @ARGV) { diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index b67d1a454..9c45a8baf 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -36,17 +36,15 @@ sub load ($) { # {{{ $raw_setup=undef; # Merge setup into existing config and untaint. - $setup{plugin}=$config{plugin}; if (exists $setup{add_plugins}) { - push @{$setup{plugin}}, @{$setup{add_plugins}}; - delete $setup{add_plugins}; + push @{$setup{add_plugins}}, @{$config{add_plugins}}; } if (exists $setup{exclude}) { push @{$config{wiki_file_prune_regexps}}, $setup{exclude}; } foreach my $c (keys %setup) { if (defined $setup{$c}) { - if (! ref $setup{$c}) { + if (! ref $setup{$c} || ref $setup{$c} eq 'Regexp') { $config{$c}=IkiWiki::possibly_foolish_untaint($setup{$c}); } elsif (ref $setup{$c} eq 'ARRAY') { diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index d88dc9e1c..ed4331d61 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -29,15 +29,21 @@ sub dumpline ($$$$) { #{{{ 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 ($@) { #{{{ diff --git a/ikiwiki.in b/ikiwiki.in index 70e44541c..8cb8a4769 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -28,7 +28,7 @@ sub getconfig () { #{{{ "refresh!" => \$config{refresh}, "post-commit" => \$config{post_commit}, "render=s" => \$config{render}, - "wrappers!" => \$config{wrappers}, + "wrappers!" => \$config{genwrappers}, "usedirs!" => \$config{usedirs}, "prefix-directives!" => \$config{prefix_directives}, "getctime" => \$config{getctime}, @@ -68,7 +68,7 @@ sub getconfig () { #{{{ $config{wrappermode}=possibly_foolish_untaint($_[1]) }, "plugin=s@" => sub { - push @{$config{plugin}}, $_[1]; + push @{$config{add_plugins}}, $_[1]; }, "disable-plugin=s@" => sub { push @{$config{disable_plugins}}, $_[1]; @@ -112,13 +112,15 @@ sub main () { #{{{ if ($config{setup}) { require IkiWiki::Setup; IkiWiki::Setup::load($config{setup}); - if (! $config{render} && ! $config{dumpsetup} && - (! $config{refresh} || $config{wrappers})) { + if (@{$config{wrappers}} && + ! $config{render} && ! $config{dumpsetup} && + (! $config{refresh} || $config{genwrappers})) { debug(gettext("generating wrappers..")); require IkiWiki::Wrapper; my %origconfig=(%config); my @wrappers=@{$config{wrappers}}; delete $config{wrappers}; + delete $config{genwrappers}; foreach my $wrapper (@wrappers) { %config=(%origconfig, rebuild => 0, -- 2.44.0