2006-03-15 04:24:34 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Standard ikiwiki setup module.
|
|
|
|
# Parameters to import should be all the standard ikiwiki config stuff,
|
2006-04-21 18:39:59 +02:00
|
|
|
# plus an array of wrappers to set up.
|
2006-03-15 04:24:34 +01:00
|
|
|
|
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
|
|
|
|
2008-07-26 07:35:26 +02:00
|
|
|
sub import { #{{{
|
2008-07-27 21:08:10 +02:00
|
|
|
IkiWiki::Setup::merge($_[1]);
|
2008-07-26 07:35:26 +02:00
|
|
|
} #}}}
|
|
|
|
|
2008-07-26 20:39:12 +02: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 $@;
|
|
|
|
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;
|
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-07-26 18:01:10 +02:00
|
|
|
} #}}}
|
2008-07-26 07:35:26 +02:00
|
|
|
|
2008-07-26 18:46:31 +02:00
|
|
|
sub dumpvalues ($@) { #{{{
|
2008-07-26 18:01:10 +02:00
|
|
|
my $setup=shift;
|
|
|
|
my @ret;
|
|
|
|
while (@_) {
|
|
|
|
my $key=shift;
|
|
|
|
my %info=%{shift()};
|
2008-07-26 20:39:12 +02:00
|
|
|
|
2008-08-04 00:17:13 +02:00
|
|
|
next if $key eq "plugin" || $info{type} eq "internal";
|
2008-07-26 18:01:10 +02:00
|
|
|
|
|
|
|
push @ret, "\t# ".$info{description} if exists $info{description};
|
|
|
|
|
|
|
|
if (exists $setup->{$key} && defined $setup->{$key}) {
|
2008-07-26 20:39:12 +02:00
|
|
|
push @ret, dumpline($key, $setup->{$key}, $info{type}, "");
|
2008-07-26 18:01:10 +02:00
|
|
|
delete $setup->{$key};
|
|
|
|
}
|
|
|
|
elsif (exists $info{example}) {
|
2008-07-26 20:39:12 +02:00
|
|
|
push @ret, dumpline($key, $info{example}, $info{type}, "#");
|
2008-07-26 18:01:10 +02:00
|
|
|
}
|
2008-07-28 01:19:04 +02:00
|
|
|
else {
|
|
|
|
push @ret, dumpline($key, "", $info{type}, "#");
|
|
|
|
}
|
2008-07-26 18:01:10 +02:00
|
|
|
}
|
|
|
|
return @ret;
|
|
|
|
} #}}}
|
|
|
|
|
2008-07-26 21:43:25 +02:00
|
|
|
sub gendump ($) { #{{{
|
|
|
|
my $description=shift;
|
2008-07-26 18:46:31 +02:00
|
|
|
my %setup=(%config);
|
2008-07-26 18:01:10 +02:00
|
|
|
my @ret;
|
2008-07-26 20:39:12 +02:00
|
|
|
|
2008-07-27 04:38:43 +02:00
|
|
|
# disable logging to syslog while dumping
|
2008-08-06 01:36:53 +02:00
|
|
|
$config{syslog}=undef;
|
2008-07-27 04:38:43 +02:00
|
|
|
|
2008-07-26 20:39:12 +02:00
|
|
|
push @ret, dumpvalues(\%setup, IkiWiki::getsetup());
|
2008-08-02 19:38:45 +02:00
|
|
|
foreach my $pair (IkiWiki::Setup::getsetup()) {
|
|
|
|
my $plugin=$pair->[0];
|
|
|
|
my $setup=$pair->[1];
|
2008-08-04 00:17:13 +02:00
|
|
|
my @values=dumpvalues(\%setup, @{$setup});
|
|
|
|
if (@values) {
|
|
|
|
push @ret, "", "\t# $plugin plugin", @values;
|
|
|
|
}
|
2008-07-27 01:10:11 +02:00
|
|
|
}
|
2008-07-27 00:10:01 +02:00
|
|
|
|
2008-07-26 21:43:25 +02:00
|
|
|
unshift @ret,
|
|
|
|
"#!/usr/bin/perl",
|
|
|
|
"# $description",
|
|
|
|
"#",
|
|
|
|
"# Passing this to ikiwiki --setup will make ikiwiki generate",
|
|
|
|
"# wrappers and build the wiki.",
|
|
|
|
"#",
|
|
|
|
"# Remember to re-run ikiwiki --setup any time you edit this file.",
|
|
|
|
"use IkiWiki::Setup::Standard {";
|
2008-07-26 07:35:26 +02:00
|
|
|
push @ret, "}";
|
2008-07-26 18:46:31 +02:00
|
|
|
|
2008-07-26 21:39:41 +02:00
|
|
|
return @ret;
|
2008-07-26 07:35:26 +02:00
|
|
|
} #}}}
|
2006-03-15 04:24:34 +01:00
|
|
|
|
|
|
|
1
|