2010-03-19 20:50:59 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
package IkiWiki::Setup::Yaml;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki;
|
|
|
|
|
|
|
|
sub loaddump ($$) {
|
|
|
|
my $class=shift;
|
|
|
|
my $content=shift;
|
|
|
|
|
2010-03-24 19:30:38 +01:00
|
|
|
eval q{use YAML::Any};
|
2010-03-24 19:53:32 +01:00
|
|
|
eval q{use YAML} if $@;
|
2010-03-19 21:09:07 +01:00
|
|
|
die $@ if $@;
|
2010-03-24 21:19:50 +01:00
|
|
|
$YAML::Syck::ImplicitUnicode=1;
|
2010-03-19 20:50:59 +01:00
|
|
|
IkiWiki::Setup::merge(Load($content));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gendump ($@) {
|
|
|
|
my $class=shift;
|
2010-03-19 21:09:07 +01:00
|
|
|
|
2010-03-19 20:50:59 +01:00
|
|
|
"# IkiWiki::Setup::Yaml - YAML formatted setup file",
|
|
|
|
"#",
|
|
|
|
(map { "# $_" } @_),
|
|
|
|
"#",
|
|
|
|
IkiWiki::Setup::commented_dump(\&dumpline, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub dumpline ($$$$) {
|
|
|
|
my $key=shift;
|
|
|
|
my $value=shift;
|
|
|
|
my $type=shift;
|
|
|
|
my $prefix=shift;
|
|
|
|
|
2010-03-24 21:12:35 +01:00
|
|
|
eval q{use YAML::Old};
|
|
|
|
eval q{use YAML} if $@;
|
|
|
|
die $@ if $@;
|
2010-03-19 20:50:59 +01:00
|
|
|
$YAML::UseHeader=0;
|
2010-03-24 21:12:35 +01:00
|
|
|
|
2010-03-19 20:50:59 +01:00
|
|
|
my $dump=Dump({$key => $value});
|
|
|
|
chomp $dump;
|
|
|
|
if (length $prefix) {
|
2010-03-19 22:54:58 +01:00
|
|
|
$dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
|
2010-03-19 20:50:59 +01:00
|
|
|
}
|
|
|
|
return $dump;
|
|
|
|
}
|
|
|
|
|
|
|
|
1
|