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