document the setup branch
[ikiwiki.git] / IkiWiki / Setup / Yaml.pm
blob6da93bb644bb5f639dd6871b492782cfa059345d
1 #!/usr/bin/perl
3 package IkiWiki::Setup::Yaml;
5 use warnings;
6 use strict;
7 use IkiWiki;
8 use Encode;
10 sub loaddump ($$) {
11 my $class=shift;
12 my $content=shift;
14 eval q{use YAML::Any};
15 eval q{use YAML} if $@;
16 die $@ if $@;
17 $YAML::Syck::ImplicitUnicode=1;
18 IkiWiki::Setup::merge(Load(encode_utf8($content)));
21 sub gendump ($@) {
22 my $class=shift;
24 "# IkiWiki::Setup::Yaml - YAML formatted setup file",
25 "#",
26 (map { "# $_" } @_),
27 "#",
28 IkiWiki::Setup::commented_dump(\&dumpline, "")
32 sub dumpline ($$$$) {
33 my $key=shift;
34 my $value=shift;
35 my $type=shift;
36 my $prefix=shift;
38 eval q{use YAML::Old};
39 eval q{use YAML} if $@;
40 die $@ if $@;
41 $YAML::UseHeader=0;
43 my $dump=Dump({$key => $value});
44 chomp $dump;
45 if (length $prefix) {
46 $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
48 return $dump;