]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Setup/Standard.pm
setup dumping improvements
[ikiwiki.git] / IkiWiki / Setup / Standard.pm
1 #!/usr/bin/perl
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.
5
6 package IkiWiki::Setup::Standard;
7
8 use warnings;
9 use strict;
10
11 sub import { #{{{
12         $IkiWiki::Setup::raw_setup=$_[1];
13 } #}}}
14
15 sub dumpline ($$$) { #{{{
16         my $key=shift;
17         my $value=shift;
18         my $prefix=shift;
19         
20         my $dumpedvalue=Dumper($value);
21         chomp $dumpedvalue;
22         $dumpedvalue=~s/^\t//;
23         
24         return "\t$prefix$key=$dumpedvalue,";
25 } #}}}
26
27 sub dumpsetup ($@) { #{{{
28         my $setup=shift;
29         my @ret;
30         while (@_) {
31                 my $key=shift;
32                 my %info=%{shift()};
33                 
34                 push @ret, "\t# ".$info{description} if exists $info{description};
35                 
36                 if (exists $setup->{$key} && defined $setup->{$key}) {
37                         push @ret, dumpline($key, $setup->{$key}, "");
38                         delete $setup->{$key};
39                 }
40                 elsif (exists $info{default}) {
41                         push @ret, dumpline($key, $info{default}, "#");
42                 }
43                 elsif (exists $info{example}) {
44                         push @ret, dumpline($key, $info{example}, "#");
45                 }
46         }
47         return @ret;
48 } #}}}
49
50 sub dump (@) { #{{{
51         my %setup=@_;
52         
53         eval q{use Data::Dumper};
54         error($@) if $@;
55         local $Data::Dumper::Terse=1;
56         local $Data::Dumper::Indent=1;
57         local $Data::Dumper::Pad="\t";
58         local $Data::Dumper::Sortkeys=1;
59         local $Data::Dumper::Quotekeys=0;
60         
61         my @ret;
62         foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) {
63                 # use an array rather than a hash, to preserve order
64                 my @s=$IkiWiki::hooks{getsetup}{$id}{call}->();
65                 return unless @s;
66                 push @ret, "\t# $id plugin";
67                 push @ret, dumpsetup(\%setup, @s);
68                 push @ret, "";
69         }
70         
71         if (%setup) {
72                 push @ret, "\t# other";
73                 foreach my $key (sort keys %setup) {
74                         push @ret, dumpline($key, $setup{$key}, "");
75                 }
76         }
77         
78         unshift @ret, "#!/usr/bin/perl
79 # Setup file for ikiwiki.
80 # Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
81 # build the wiki.
82 #
83 # Remember to re-run ikiwiki --setup any time you edit this file.
84
85 use IkiWiki::Setup::Standard {";
86         push @ret, "}";
87         return @ret;
88 } #}}}
89
90 1