summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: dcb278bf48e2e7faae969cba7515e9ace98e149f (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. package IkiWiki::Setup;
  12. sub dumpline ($$$) { #{{{
  13. my $key=shift;
  14. my $value=shift;
  15. my $prefix=shift;
  16. eval q{use Data::Dumper};
  17. error($@) if $@;
  18. local $Data::Dumper::Terse=1;
  19. local $Data::Dumper::Indent=1;
  20. local $Data::Dumper::Pad="\t";
  21. local $Data::Dumper::Sortkeys=1;
  22. local $Data::Dumper::Quotekeys=0;
  23. my $dumpedvalue=Dumper($value);
  24. chomp $dumpedvalue;
  25. $dumpedvalue=~s/^\t//;
  26. return "\t$prefix$key=$dumpedvalue,";
  27. } #}}}
  28. sub dumpvalues ($@) { #{{{
  29. my $setup=shift;
  30. my @ret;
  31. while (@_) {
  32. my $key=shift;
  33. my %info=%{shift()};
  34. push @ret, "\t# ".$info{description} if exists $info{description};
  35. if (exists $setup->{$key} && defined $setup->{$key}) {
  36. push @ret, dumpline($key, $setup->{$key}, "");
  37. delete $setup->{$key};
  38. }
  39. elsif (exists $info{default}) {
  40. push @ret, dumpline($key, $info{default}, "#");
  41. }
  42. elsif (exists $info{example}) {
  43. push @ret, dumpline($key, $info{example}, "#");
  44. }
  45. }
  46. return @ret;
  47. } #}}}
  48. sub dump ($) { #{{{
  49. my $file=shift;
  50. my %setup=(%config);
  51. my @ret;
  52. foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) {
  53. # use an array rather than a hash, to preserve order
  54. my @s=$IkiWiki::hooks{getsetup}{$id}{call}->();
  55. return unless @s;
  56. push @ret, "\t# $id plugin";
  57. push @ret, dumpvalues(\%setup, @s);
  58. push @ret, "";
  59. }
  60. if (%setup) {
  61. push @ret, "\t# other";
  62. foreach my $key (sort keys %setup) {
  63. push @ret, dumpline($key, $setup{$key}, "");
  64. }
  65. }
  66. unshift @ret, "#!/usr/bin/perl
  67. # Setup file for ikiwiki.
  68. # Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
  69. # build the wiki.
  70. #
  71. # Remember to re-run ikiwiki --setup any time you edit this file.
  72. use IkiWiki::Setup::Standard {";
  73. push @ret, "}";
  74. open (OUT, ">", $file) || die "$file: $!";
  75. print OUT "$_\n" foreach @ret;
  76. close OUT;
  77. } #}}}
  78. 1