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