]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Setup/Standard.pm
problem with the creation_before page
[git.ikiwiki.info.git] / IkiWiki / Setup / Standard.pm
1 #!/usr/bin/perl
3 package IkiWiki::Setup::Standard;
5 use warnings;
6 use strict;
7 use IkiWiki;
9 # Parameters to import should be all the standard ikiwiki config, in a hash.
10 sub import {
11         IkiWiki::Setup::merge($_[1]);
12 }
14 sub gendump ($@) {
15         my $class=shift;
17         my $thisperl = eval q{use Config; $Config{perlpath}};
18         error($@) if $@;
20         "#!$thisperl",
21         "#",
22         (map { "# $_" } @_),
23         "use IkiWiki::Setup::Standard {",
24         IkiWiki::Setup::commented_dump(\&dumpline, "\t"),
25         "}"
26 }
28 sub dumpline ($$$$) {
29         my $key=shift;
30         my $value=shift;
31         my $type=shift;
32         my $prefix=shift;
33         
34         eval q{use Data::Dumper};
35         error($@) if $@;
36         no warnings 'once';
37         local $Data::Dumper::Terse=1;
38         local $Data::Dumper::Indent=1;
39         local $Data::Dumper::Pad="\t";
40         local $Data::Dumper::Sortkeys=1;
41         local $Data::Dumper::Quotekeys=0;
42         # only the perl version preserves utf-8 in output
43         local $Data::Dumper::Useperl=1;
44         use warnings;
45         
46         my $dumpedvalue;
47         if (($type eq 'boolean' || $type eq 'integer') && $value=~/^[0-9]+$/) {
48                 # avoid quotes
49                 $dumpedvalue=$value;
50         }
51         elsif (ref $value eq 'ARRAY' && @$value && ! grep { /[^\S]/ } @$value) {
52                 # dump simple array as qw{}
53                 $dumpedvalue="[qw{".join(" ", @$value)."}]";
54         }
55         else {
56                 $dumpedvalue=Dumper($value);
57                 chomp $dumpedvalue;
58                 if (length $prefix) {
59                         # add to second and subsequent lines
60                         my @lines=split(/\n/, $dumpedvalue);
61                         $dumpedvalue="";
62                         for (my $x=0; $x <= $#lines; $x++) {
63                                 $lines[$x] =~ s/^\t//;
64                                 $dumpedvalue.="\t".($x ? $prefix : "").$lines[$x]."\n";
65                         }
66                 }
67                 $dumpedvalue=~s/^\t//;
68                 chomp $dumpedvalue;
69         }
70         
71         return "\t$prefix$key => $dumpedvalue,";
72 }
74 1