summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: 8b0bc22799dab625b9d5f8c411f8d34a93add084 (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 generate (@) { #{{{
  12. my %setup=@_;
  13. eval q{use Data::Dumper};
  14. error($@) if $@;
  15. local $Data::Dumper::Terse=1;
  16. local $Data::Dumper::Indent=1;
  17. local $Data::Dumper::Pad="\t";
  18. local $Data::Dumper::Sortkeys=1;
  19. local $Data::Dumper::Quotekeys=0;
  20. my @ret="#!/usr/bin/perl
  21. # Setup file for ikiwiki.
  22. # Passing this to ikiwiki --setup will make ikiwiki generate wrappers and
  23. # build the wiki.
  24. #
  25. # Remember to re-run ikiwiki --setup any time you edit this file.
  26. use IkiWiki::Setup::Standard {";
  27. foreach my $id (sort keys %{$IkiWiki::hooks{getsetup}}) {
  28. my @setup=$IkiWiki::hooks{getsetup}{$id}{call}->();
  29. return unless @setup;
  30. push @ret, "\t# $id plugin";
  31. while (@setup) {
  32. my $key=shift @setup;
  33. my %info=%{shift @setup};
  34. push @ret, "\t# ".$info{description} if exists $info{description};
  35. my $value=undef;
  36. my $prefix="#";
  37. if (exists $setup{$key} && defined $setup{$key}) {
  38. $value=$setup{$key};
  39. $prefix="";
  40. }
  41. elsif (exists $info{default}) {
  42. $value=$info{default};
  43. }
  44. elsif (exists $info{example}) {
  45. $value=$info{example};
  46. }
  47. my $dumpedvalue=Dumper($value);
  48. chomp $dumpedvalue;
  49. $dumpedvalue=~/^\t//;
  50. push @ret, "\t$prefix$key=$dumpedvalue,";
  51. }
  52. push @ret, "";
  53. }
  54. push @ret, "}";
  55. return @ret;
  56. } #}}}
  57. 1