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