X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/409e62021c5c05e0184a61d0692697c10a0b8283..62cd2e0a5d0127a13cc9af792191bcbceb36e387:/IkiWiki/Setup/Standard.pm diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 4082ca7af..9832d174e 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -3,75 +3,88 @@ # Parameters to import should be all the standard ikiwiki config stuff, # plus an array of wrappers to set up. +package IkiWiki::Setup::Standard; + use warnings; use strict; -use IkiWiki::Wrapper; -use IkiWiki::Render; -package IkiWiki::Setup::Standard; +sub import { #{{{ + $IkiWiki::Setup::raw_setup=$_[1]; +} #}}} -sub import { - IkiWiki::setup_standard(@_); -} +sub dumpline ($$$) { #{{{ + my $key=shift; + my $value=shift; + my $prefix=shift; -package IkiWiki; - -sub setup_standard { - my %setup=%{$_[1]}; + my $dumpedvalue=Dumper($value); + chomp $dumpedvalue; + $dumpedvalue=~s/^\t//; + + return "\t$prefix$key=$dumpedvalue,"; +} #}}} - $setup{plugin}=$config{plugin}; - if (exists $setup{add_plugins}) { - push @{$setup{plugin}}, @{$setup{add_plugins}}; - delete $setup{add_plugins}; - } - if (exists $setup{disable_plugins}) { - foreach my $plugin (@{$setup{disable_plugins}}) { - $setup{plugin}=[grep { $_ ne $plugin } @{$setup{plugin}}]; +sub dumpsetup ($@) { #{{{ + 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}; } - delete $setup{disable_plugins}; - } - - debug("generating wrappers.."); - my @wrappers=@{$setup{wrappers}}; - delete $setup{wrappers}; - my %startconfig=(%config); - foreach my $wrapper (@wrappers) { - %config=(%startconfig, verbose => 0, %setup, %{$wrapper}); - checkconfig(); - gen_wrapper(); - } - %config=(%startconfig); - - foreach my $c (keys %setup) { - if (defined $setup{$c}) { - if (! ref $setup{$c}) { - $config{$c}=possibly_foolish_untaint($setup{$c}); - } - elsif (ref $setup{$c} eq 'ARRAY') { - $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}] - } + elsif (exists $info{default}) { + push @ret, dumpline($key, $info{default}, "#"); } - else { - $config{$c}=undef; + elsif (exists $info{example}) { + push @ret, dumpline($key, $info{example}, "#"); } } + return @ret; +} #}}} - if (! $config{refresh}) { - $config{rebuild}=1; - debug("rebuilding wiki.."); +sub dump (@) { #{{{ + my %setup=@_; + + 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; + + my @ret; + 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, dumpsetup(\%setup, @s); + push @ret, ""; } - else { - debug("refreshing wiki.."); + + 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. - loadplugins(); - checkconfig(); - lockwiki(); - loadindex(); - refresh(); - - debug("done"); - saveindex(); -} +use IkiWiki::Setup::Standard {"; + push @ret, "}"; + return @ret; +} #}}} 1