]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Setup/Yaml.pm
I've not looked at Shake yet, thanks, I'll give it a look! — [[Jon]]
[git.ikiwiki.info.git] / IkiWiki / Setup / Yaml.pm
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::XS};
15         die $@ if $@;
16         IkiWiki::Setup::merge(Load(encode_utf8($content)));
17 }
19 sub gendump ($@) {
20         my $class=shift;
21         
22         "# IkiWiki::Setup::Yaml - YAML formatted setup file",
23         "#",
24         (map { "# $_" } @_),
25         "#",
26         IkiWiki::Setup::commented_dump(\&dumpline, "")
27 }
30 sub dumpline ($$$$) {
31         my $key=shift;
32         my $value=shift;
33         my $type=shift;
34         my $prefix=shift;
35         
36         eval q{use YAML::XS};
37         die $@ if $@;
38         no warnings 'once';
39         $YAML::XS::QuoteNumericStrings=0;
40         use warnings;
42         my $dump=decode_utf8(Dump({$key => $value}));
43         $dump=~s/^---\n//; # yaml header, we don't want
44         chomp $dump;
45         if (length $prefix) {
46                 $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
47         }
48         return $dump;
49 }
51 1