summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: 9832d174ea41639900a627bdf686669567cd1d83 (plain)
  1. #!/usr/bin/perl
  2. # Standard ikiwiki setup module.
  3. # Parameters to import should be all the standard ikiwiki config stuff,
  4. # plus an array of wrappers to set up.
  5. package IkiWiki::Setup::Standard;
  6. use warnings;
  7. use strict;
  8. sub import { #{{{
  9. $IkiWiki::Setup::raw_setup=$_[1];
  10. } #}}}
  11. sub dumpline ($$$) { #{{{
  12. my $key=shift;
  13. my $value=shift;
  14. my $prefix=shift;
  15. my $dumpedvalue=Dumper($value);
  16. chomp $dumpedvalue;
  17. $dumpedvalue=~s/^\t//;
  18. return "\t$prefix$key=$dumpedvalue,";
  19. } #}}}
  20. sub dumpsetup ($@) { #{{{
  21. my $setup=shift;
  22. my @ret;
  23. while (@_) {
  24. my $key=shift;
  25. my %info=%{shift()};
  26. push @ret, "\t# ".$info{description} if exists $info{description};
  27. if (exists $setup->{$key} && defined $setup->{$key}) {
  28. push @ret, dumpline($key, $setup->{$key}, "");
  29. delete $setup->{$key};
  30. }
  31. elsif (exists $info{default}) {
  32. push @ret, dumpline($key, $info{default}, "#");
  33. }
  34. elsif (exists $info{example}) {
  35. push @ret, dumpline($key, $info{example}, "#");
  36. }
  37. }
  38. return @ret;
  39. } #}}}
  40. sub dump (@) { #{{{
  41. my %setup=@_;
  42. eval q{use Data::Dumper};
  43. error($@) if $@;
  44. local $Data::Dumper::Terse=1;
  45. local $Data::Dumper::Indent=1;
  46. local $Data::Dumper::Pad="\t";
  47. local $Data::Dumper::Sortkeys=1;
  48. local $Data::Dumper::Quotekeys=0;
  49. my @ret;
  50. foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) {
  51. # use an array rather than a hash, to preserve order
  52. my @s=$IkiWiki::hooks{getsetup}{$id}{call}->();
  53. return unless @s;
  54. push @ret, "\t# $id plugin";
  55. push @ret, dumpsetup(\%setup, @s);
  56. push @ret, "";
  57. }
  58. if (%setup) {
  59. push @ret, "\t# other";
  60. foreach my $key (sort keys %setup) {
  61. push @ret, dumpline($key, $setup{$key}, "");
  62. }
  63. }
  64. unshift @ret, "#!/usr/bin/perl
  65. # Setup file for ikiwiki.
  66. # Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
  67. # build the wiki.
  68. #
  69. # Remember to re-run ikiwiki --setup any time you edit this file.
  70. use IkiWiki::Setup::Standard {";
  71. push @ret, "}";
  72. return @ret;
  73. } #}}}
  74. 1