]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Setup/Standard.pm
git: Do not disable commit hook for temporary working tree
[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         local $Data::Dumper::Terse=1;
37         local $Data::Dumper::Indent=1;
38         local $Data::Dumper::Pad="\t";
39         local $Data::Dumper::Sortkeys=1;
40         local $Data::Dumper::Quotekeys=0;
41         # only the perl version preserves utf-8 in output
42         local $Data::Dumper::Useperl=1;
43         
44         my $dumpedvalue;
45         if (($type eq 'boolean' || $type eq 'integer') && $value=~/^[0-9]+$/) {
46                 # avoid quotes
47                 $dumpedvalue=$value;
48         }
49         elsif (ref $value eq 'ARRAY' && @$value && ! grep { /[^\S]/ } @$value) {
50                 # dump simple array as qw{}
51                 $dumpedvalue="[qw{".join(" ", @$value)."}]";
52         }
53         else {
54                 $dumpedvalue=Dumper($value);
55                 chomp $dumpedvalue;
56                 if (length $prefix) {
57                         # add to second and subsequent lines
58                         my @lines=split(/\n/, $dumpedvalue);
59                         $dumpedvalue="";
60                         for (my $x=0; $x <= $#lines; $x++) {
61                                 $lines[$x] =~ s/^\t//;
62                                 $dumpedvalue.="\t".($x ? $prefix : "").$lines[$x]."\n";
63                         }
64                 }
65                 $dumpedvalue=~s/^\t//;
66                 chomp $dumpedvalue;
67         }
68         
69         return "\t$prefix$key => $dumpedvalue,";
70 }
72 1