2 # Standard ikiwiki setup module.
3 # Parameters to import should be all the standard ikiwiki config stuff,
4 # plus an array of wrappers to set up.
6 package IkiWiki::Setup::Standard;
13 IkiWiki::Setup::merge($_[1]);
22 eval q{use Data::Dumper};
24 local $Data::Dumper::Terse=1;
25 local $Data::Dumper::Indent=1;
26 local $Data::Dumper::Pad="\t";
27 local $Data::Dumper::Sortkeys=1;
28 local $Data::Dumper::Quotekeys=0;
29 # only the perl version preserves utf-8 in output
30 local $Data::Dumper::Useperl=1;
33 if (($type eq 'boolean' || $type eq 'integer') && $value=~/^[0-9]+$/) {
37 elsif (ref $value eq 'ARRAY' && @$value && ! grep { /[^\S]/ } @$value) {
38 # dump simple array as qw{}
39 $dumpedvalue="[qw{".join(" ", @$value)."}]";
42 $dumpedvalue=Dumper($value);
45 # add to second and subsequent lines
46 my @lines=split(/\n/, $dumpedvalue);
48 for (my $x=0; $x <= $#lines; $x++) {
49 $lines[$x] =~ s/^\t//;
50 $dumpedvalue.="\t".($x ? $prefix : "").$lines[$x]."\n";
53 $dumpedvalue=~s/^\t//;
57 return "\t$prefix$key => $dumpedvalue,";
67 next if $key eq "plugin" || $info{type} eq "internal";
69 push @ret, "\t# ".$info{description} if exists $info{description};
71 if (exists $setup->{$key} && defined $setup->{$key}) {
72 push @ret, dumpline($key, $setup->{$key}, $info{type}, "");
73 delete $setup->{$key};
75 elsif (exists $info{example}) {
76 push @ret, dumpline($key, $info{example}, $info{type}, "#");
79 push @ret, dumpline($key, "", $info{type}, "#");
87 my $description=shift;
92 # disable logging to syslog while dumping
93 $config{syslog}=undef;
95 eval q{use Text::Wrap};
99 push @ret, dumpvalues(\%setup, IkiWiki::getsetup());
100 foreach my $pair (IkiWiki::Setup::getsetup()) {
101 my $plugin=$pair->[0];
102 my $setup=$pair->[1];
104 my $section=$s{plugin}->{section};
105 push @{$section_plugins{$section}}, $plugin;
106 if (@{$section_plugins{$section}} == 1) {
107 push @ret, "", "\t".("#" x 70), "\t# $section plugins",
109 wrap("\t# (", "\t# ",
110 join(", ", @{$section_plugins{$section}})).")"
115 my @values=dumpvalues(\%setup, @{$setup});
117 push @ret, "", "\t# $plugin plugin", @values;
125 "# Passing this to ikiwiki --setup will make ikiwiki generate",
126 "# wrappers and build the wiki.",
128 "# Remember to re-run ikiwiki --setup any time you edit this file.",
129 "use IkiWiki::Setup::Standard {";
132 return map { ref $_ ? $_->() : $_ } @ret;