2006-03-15 04:24:34 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2008-07-11 12:07:48 +02:00
|
|
|
package IkiWiki::Setup::Standard;
|
|
|
|
|
2006-03-15 04:24:34 +01:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-07-26 18:53:07 +02:00
|
|
|
use IkiWiki;
|
2006-03-15 04:24:34 +01:00
|
|
|
|
2010-03-19 20:36:33 +01:00
|
|
|
# Parameters to import should be all the standard ikiwiki config, in a hash.
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-07-27 21:08:10 +02:00
|
|
|
IkiWiki::Setup::merge($_[1]);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-26 07:35:26 +02:00
|
|
|
|
2010-03-19 20:35:21 +01:00
|
|
|
sub gendump ($@) {
|
2010-03-19 20:27:15 +01:00
|
|
|
my $class=shift;
|
|
|
|
|
2012-01-08 18:06:56 +01:00
|
|
|
my $thisperl = eval q{use Config; $Config{perlpath}};
|
|
|
|
error($@) if $@;
|
|
|
|
|
|
|
|
"#!$thisperl",
|
2010-03-19 20:27:15 +01:00
|
|
|
"#",
|
2010-03-19 20:35:21 +01:00
|
|
|
(map { "# $_" } @_),
|
2010-03-19 20:27:15 +01:00
|
|
|
"use IkiWiki::Setup::Standard {",
|
2010-03-19 20:44:28 +01:00
|
|
|
IkiWiki::Setup::commented_dump(\&dumpline, "\t"),
|
2010-03-19 20:35:21 +01:00
|
|
|
"}"
|
2010-03-19 20:27:15 +01:00
|
|
|
}
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub dumpline ($$$$) {
|
2008-07-26 18:01:10 +02:00
|
|
|
my $key=shift;
|
|
|
|
my $value=shift;
|
2008-07-26 20:39:12 +02:00
|
|
|
my $type=shift;
|
2008-07-26 18:01:10 +02:00
|
|
|
my $prefix=shift;
|
|
|
|
|
2008-07-26 18:46:31 +02:00
|
|
|
eval q{use Data::Dumper};
|
|
|
|
error($@) if $@;
|
2016-01-18 09:45:18 +01:00
|
|
|
no warnings 'once';
|
2008-07-26 18:46:31 +02:00
|
|
|
local $Data::Dumper::Terse=1;
|
|
|
|
local $Data::Dumper::Indent=1;
|
|
|
|
local $Data::Dumper::Pad="\t";
|
|
|
|
local $Data::Dumper::Sortkeys=1;
|
|
|
|
local $Data::Dumper::Quotekeys=0;
|
2008-10-20 03:23:48 +02:00
|
|
|
# only the perl version preserves utf-8 in output
|
|
|
|
local $Data::Dumper::Useperl=1;
|
2016-01-18 09:45:18 +01:00
|
|
|
use warnings;
|
2008-07-26 18:46:31 +02:00
|
|
|
|
2008-07-26 20:39:12 +02:00
|
|
|
my $dumpedvalue;
|
2008-08-03 05:14:23 +02:00
|
|
|
if (($type eq 'boolean' || $type eq 'integer') && $value=~/^[0-9]+$/) {
|
2008-07-26 21:34:38 +02:00
|
|
|
# avoid quotes
|
2008-07-26 20:39:12 +02:00
|
|
|
$dumpedvalue=$value;
|
|
|
|
}
|
2008-08-04 04:01:11 +02:00
|
|
|
elsif (ref $value eq 'ARRAY' && @$value && ! grep { /[^\S]/ } @$value) {
|
2008-07-26 21:34:38 +02:00
|
|
|
# dump simple array as qw{}
|
2008-08-04 00:17:13 +02:00
|
|
|
$dumpedvalue="[qw{".join(" ", @$value)."}]";
|
2008-07-26 21:34:38 +02:00
|
|
|
}
|
2008-07-26 20:39:12 +02:00
|
|
|
else {
|
|
|
|
$dumpedvalue=Dumper($value);
|
|
|
|
chomp $dumpedvalue;
|
2008-07-27 01:49:45 +02:00
|
|
|
if (length $prefix) {
|
|
|
|
# add to second and subsequent lines
|
|
|
|
my @lines=split(/\n/, $dumpedvalue);
|
|
|
|
$dumpedvalue="";
|
|
|
|
for (my $x=0; $x <= $#lines; $x++) {
|
|
|
|
$lines[$x] =~ s/^\t//;
|
|
|
|
$dumpedvalue.="\t".($x ? $prefix : "").$lines[$x]."\n";
|
|
|
|
}
|
|
|
|
}
|
2008-07-26 20:39:12 +02:00
|
|
|
$dumpedvalue=~s/^\t//;
|
2008-07-27 01:49:45 +02:00
|
|
|
chomp $dumpedvalue;
|
2008-07-26 20:39:12 +02:00
|
|
|
}
|
2008-07-26 18:01:10 +02:00
|
|
|
|
2008-07-26 21:34:38 +02:00
|
|
|
return "\t$prefix$key => $dumpedvalue,";
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-26 07:35:26 +02:00
|
|
|
|
2006-03-15 04:24:34 +01:00
|
|
|
1
|