]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Setup/Standard.pm
dd9368986af9d7647df70dcb115142a0fe9a194c
[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 generate (@) { #{{{
16         my %setup=@_;
17
18         eval q{use Data::Dumper};
19         error($@) if $@;
20         local $Data::Dumper::Terse=1;
21         local $Data::Dumper::Sortkeys=1;
22         local $Data::Dumper::Pad="\t";
23
24         my @ret="#!/usr/bin/perl
25 # Setup file for ikiwiki.
26 # Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
27 # build the wiki.
28 #
29 # Remember to re-run ikiwiki --setup any time you edit this file.
30
31 use IkiWiki::Setup::Standard {";
32
33         foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) {
34                 my @setup=$IkiWiki::hooks{getsetup}{$id}{call}->();
35                 return unless @setup;
36                 push @ret, "\t# $id plugin";
37                 while (@setup) {
38                         my $key=shift @setup;
39                         my %info=%{shift @setup};
40         
41                         push @ret, "\t# ".$info{description} if exists $info{description};
42         
43                         my $value=undef;
44                         my $prefix="#";
45                         if (exists $setup{$key} && defined $setup{$key}) {
46                                 $value=$setup{$key};
47                                 $prefix="";
48                         }
49                         elsif (exists $info{default}) {
50                                 $value=$info{default};
51                         }
52                         elsif (exists $info{example}) {
53                                 $value=$info{example};
54                         }
55         
56                         my $dumpedvalue=Dumper($value);
57                         chomp $dumpedvalue;
58                         $dumpedvalue=~/^\t//;
59                         push @ret, "\t$prefix$key=$dumpedvalue,";
60                 }
61                 push @ret, "";
62         }
63
64         push @ret, "}";
65         return @ret;
66 } #}}}
67
68 1