summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Yaml.pm
blob: 904784728e0a0cbc6314cf26006010b5e5d25d8a (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Setup::Yaml;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. sub loaddump ($$) {
  7. my $class=shift;
  8. my $content=shift;
  9. eval q{use YAML::Any};
  10. eval q{use YAML} if $@;
  11. die $@ if $@;
  12. $YAML::Syck::ImplicitUnicode=1;
  13. IkiWiki::Setup::merge(Load($content));
  14. }
  15. sub gendump ($@) {
  16. my $class=shift;
  17. "# IkiWiki::Setup::Yaml - YAML formatted setup file",
  18. "#",
  19. (map { "# $_" } @_),
  20. "#",
  21. IkiWiki::Setup::commented_dump(\&dumpline, "")
  22. }
  23. sub dumpline ($$$$) {
  24. my $key=shift;
  25. my $value=shift;
  26. my $type=shift;
  27. my $prefix=shift;
  28. eval q{use YAML::Old};
  29. eval q{use YAML} if $@;
  30. die $@ if $@;
  31. $YAML::UseHeader=0;
  32. my $dump=Dump({$key => $value});
  33. chomp $dump;
  34. if (length $prefix) {
  35. $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
  36. }
  37. return $dump;
  38. }
  39. 1