summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Yaml.pm
blob: 0fc2736756d73ba099b27961a2772a769731b204 (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};
  10. die $@ if $@;
  11. IkiWiki::Setup::merge(Load($content));
  12. }
  13. sub gendump ($@) {
  14. my $class=shift;
  15. eval q{use YAML};
  16. die $@ if $@;
  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. $YAML::UseHeader=0;
  29. my $dump=Dump({$key => $value});
  30. chomp $dump;
  31. if (length $prefix) {
  32. $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
  33. }
  34. return $dump;
  35. }
  36. 1