From a63929f6cc7778ffc4ba57d784cdf2206ec650c7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Feb 2010 22:24:15 -0500 Subject: Group related plugins into sections in the setup file, and drop unused rcs plugins from the setup file. --- IkiWiki/Setup/Standard.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 951bcfc56..c99dbb620 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -90,10 +90,18 @@ sub gendump ($) { # disable logging to syslog while dumping $config{syslog}=undef; + my $curr_section; push @ret, dumpvalues(\%setup, IkiWiki::getsetup()); foreach my $pair (IkiWiki::Setup::getsetup()) { my $plugin=$pair->[0]; my $setup=$pair->[1]; + my %s=@{$setup}; + my $section=$s{plugin}->{section}; + if (! defined $curr_section || $curr_section ne $section) { + $curr_section=$section; + push @ret, "", "\t#", "\t# $section plugins", "\t#"; + } + my @values=dumpvalues(\%setup, @{$setup}); if (@values) { push @ret, "", "\t# $plugin plugin", @values; -- cgit v1.2.3 From 0ea2f0936bf9d51f4760fe5a8e57d46d1b6ecce6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Feb 2010 00:51:19 -0500 Subject: add plugin section, and show which plugins need no configuration --- IkiWiki/Setup/Standard.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index c99dbb620..bdf52f25a 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -90,16 +90,24 @@ sub gendump ($) { # disable logging to syslog while dumping $config{syslog}=undef; - my $curr_section; + eval q{use Text::Wrap}; + die $@ if $@; + + my %section_plugins; push @ret, dumpvalues(\%setup, IkiWiki::getsetup()); foreach my $pair (IkiWiki::Setup::getsetup()) { my $plugin=$pair->[0]; my $setup=$pair->[1]; my %s=@{$setup}; my $section=$s{plugin}->{section}; - if (! defined $curr_section || $curr_section ne $section) { - $curr_section=$section; - push @ret, "", "\t#", "\t# $section plugins", "\t#"; + push @{$section_plugins{$section}}, $plugin; + if (@{$section_plugins{$section}} == 1) { + push @ret, "", "\t#", "\t# $section plugins", + sub { + wrap("\t# (", "\t# ", + join(", ", @{$section_plugins{$section}})).")" + }, + "\t#"; } my @values=dumpvalues(\%setup, @{$setup}); @@ -119,7 +127,7 @@ sub gendump ($) { "use IkiWiki::Setup::Standard {"; push @ret, "}"; - return @ret; + return map { ref $_ ? $_->() : $_ } @ret; } 1 -- cgit v1.2.3 From 2d4b84e45f1dc947e8bb9ff92ab543861223ff42 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Feb 2010 01:16:20 -0500 Subject: borders --- IkiWiki/Setup/Standard.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index bdf52f25a..71abb1cfb 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -102,12 +102,12 @@ sub gendump ($) { my $section=$s{plugin}->{section}; push @{$section_plugins{$section}}, $plugin; if (@{$section_plugins{$section}} == 1) { - push @ret, "", "\t#", "\t# $section plugins", + push @ret, "", "\t".("#" x 70), "\t# $section plugins", sub { wrap("\t# (", "\t# ", join(", ", @{$section_plugins{$section}})).")" }, - "\t#"; + "\t".("#" x 70); } my @values=dumpvalues(\%setup, @{$setup}); -- cgit v1.2.3 From 805b3afff7158a7912b06948d134478308b5855b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 12 Feb 2010 04:09:57 -0500 Subject: formatting sillyness --- IkiWiki/Setup/Standard.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 71abb1cfb..f7a322317 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -104,7 +104,7 @@ sub gendump ($) { if (@{$section_plugins{$section}} == 1) { push @ret, "", "\t".("#" x 70), "\t# $section plugins", sub { - wrap("\t# (", "\t# ", + wrap("\t# (", "\t# ", join(", ", @{$section_plugins{$section}})).")" }, "\t".("#" x 70); -- cgit v1.2.3 From b1dade8d960ce7ccb549e5652d35a8e9dbccf5c6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Mar 2010 14:52:17 -0400 Subject: allow multiple setup file types, and support safe parsing Finally removed the last hardcoding of IkiWiki::Setup::Standard. Take the first "IkiWiki::Setup::*" in the setup file to define the setuptype, and remember that type to use in dumping later. (But it can be overridden using --set, etc.) Also, support setup file types that are not evaled. --- IkiWiki.pm | 7 +++++++ IkiWiki/Setup.pm | 40 +++++++++++++++++++++++++++++----------- IkiWiki/Setup/Standard.pm | 4 +++- 3 files changed, 39 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index 6e333504e..241fb45b7 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -467,6 +467,13 @@ sub getsetup () { safe => 0, rebuild => 0, }, + setuptype => { + type => "internal", + default => "IkiWiki::Setup::Standard", + description => "perl class to use to dump setup file", + safe => 0, + rebuild => 0, + }, allow_symlinks_before_srcdir => { type => "boolean", default => 0, diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index a3fd5ce66..3accf3591 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -1,6 +1,8 @@ #!/usr/bin/perl -# Ikiwiki setup files are perl files that 'use IkiWiki::Setup::foo', -# passing it some sort of configuration data. +# Ikiwiki setup files can be perl files that 'use IkiWiki::Setup::foo', +# passing it some sort of configuration data. Or, they can contain +# the module name at the top, without the 'use', and the whole file is +# then fed into that module. package IkiWiki::Setup; @@ -10,24 +12,39 @@ use IkiWiki; use open qw{:utf8 :std}; use File::Spec; -sub load ($) { +sub load ($;$) { my $setup=IkiWiki::possibly_foolish_untaint(shift); + my $safemode=shift; + $config{setupfile}=File::Spec->rel2abs($setup); #translators: The first parameter is a filename, and the second #translators: is a (probably not translated) error message. open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!)); - my $code; + my $content; { local $/=undef; - $code= || error("$setup: $!"); + $content= || error("$setup: $!"); } - - ($code)=$code=~/(.*)/s; close IN; - eval $code; - error("$setup: ".$@) if $@; + if ($content=~/(use\s+)?(IkiWiki::Setup::\w+)/) { + $config{setuptype}=$2; + if ($1) { + error sprintf(gettext("cannot load %s in safe mode"), $setup) + if $safemode; + eval IkiWiki::possibly_foolish_untaint($content); + error("$setup: ".$@) if $@; + } + else { + eval qq{require $config{setuptype}}; + error $@ if $@; + $config{setuptype}->loaddump(IkiWiki::possibly_foolish_untaint($content)); + } + } + else { + error sprintf(gettext("failed to parse %s"), $setup); + } } sub merge ($) { @@ -133,8 +150,9 @@ sub getsetup () { sub dump ($) { my $file=IkiWiki::possibly_foolish_untaint(shift); - require IkiWiki::Setup::Standard; - my @dump=IkiWiki::Setup::Standard::gendump("Setup file for ikiwiki."); + eval qq{require $config{setuptype}}; + error $@ if $@; + my @dump=$config{setuptype}->gendump("Setup file for ikiwiki."); open (OUT, ">", $file) || die "$file: $!"; print OUT "$_\n" foreach @dump; diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index f7a322317..4022ff03c 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -82,8 +82,10 @@ sub dumpvalues ($@) { return @ret; } -sub gendump ($) { +sub gendump ($$) { + my $class=shift; my $description=shift; + my %setup=(%config); my @ret; -- cgit v1.2.3 From 522daa7ea8111482701ce222800096edaf8eb2d2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Mar 2010 15:27:15 -0400 Subject: factored out generic commented line dumping --- IkiWiki/Setup.pm | 94 +++++++++++++++++++++++++++++++++++++++-------- IkiWiki/Setup/Standard.pm | 94 +++++++++-------------------------------------- 2 files changed, 96 insertions(+), 92 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index 3accf3591..369ff44d0 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -13,28 +13,28 @@ use open qw{:utf8 :std}; use File::Spec; sub load ($;$) { - my $setup=IkiWiki::possibly_foolish_untaint(shift); + my $file=IkiWiki::possibly_foolish_untaint(shift); my $safemode=shift; - $config{setupfile}=File::Spec->rel2abs($setup); + $config{setupfile}=File::Spec->rel2abs($file); #translators: The first parameter is a filename, and the second #translators: is a (probably not translated) error message. - open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!)); + open (IN, $file) || error(sprintf(gettext("cannot read %s: %s"), $file, $!)); my $content; { local $/=undef; - $content= || error("$setup: $!"); + $content= || error("$file: $!"); } close IN; if ($content=~/(use\s+)?(IkiWiki::Setup::\w+)/) { $config{setuptype}=$2; if ($1) { - error sprintf(gettext("cannot load %s in safe mode"), $setup) + error sprintf(gettext("cannot load %s in safe mode"), $file) if $safemode; eval IkiWiki::possibly_foolish_untaint($content); - error("$setup: ".$@) if $@; + error("$file: ".$@) if $@; } else { eval qq{require $config{setuptype}}; @@ -43,10 +43,22 @@ sub load ($;$) { } } else { - error sprintf(gettext("failed to parse %s"), $setup); + error sprintf(gettext("failed to parse %s"), $file); } } +sub dump ($) { + my $file=IkiWiki::possibly_foolish_untaint(shift); + + eval qq{require $config{setuptype}}; + error $@ if $@; + my @dump=$config{setuptype}->gendump("Setup file for ikiwiki."); + + open (OUT, ">", $file) || die "$file: $!"; + print OUT "$_\n" foreach @dump; + close OUT; +} + sub merge ($) { # Merge setup into existing config and untaint. my %setup=%{shift()}; @@ -147,16 +159,68 @@ sub getsetup () { } keys %sections; } -sub dump ($) { - my $file=IkiWiki::possibly_foolish_untaint(shift); +sub commented_dump ($) { + my $dumpline=shift; + + my %setup=(%config); + my @ret; - eval qq{require $config{setuptype}}; - error $@ if $@; - my @dump=$config{setuptype}->gendump("Setup file for ikiwiki."); + # disable logging to syslog while dumping + $config{syslog}=undef; + + eval q{use Text::Wrap}; + die $@ if $@; + + my %section_plugins; + push @ret, commented_dumpvalues($dumpline, \%setup, IkiWiki::getsetup()); + foreach my $pair (IkiWiki::Setup::getsetup()) { + my $plugin=$pair->[0]; + my $setup=$pair->[1]; + my %s=@{$setup}; + my $section=$s{plugin}->{section}; + push @{$section_plugins{$section}}, $plugin; + if (@{$section_plugins{$section}} == 1) { + push @ret, "", "\t".("#" x 70), "\t# $section plugins", + sub { + wrap("\t# (", "\t# ", + join(", ", @{$section_plugins{$section}})).")" + }, + "\t".("#" x 70); + } - open (OUT, ">", $file) || die "$file: $!"; - print OUT "$_\n" foreach @dump; - close OUT; + my @values=commented_dumpvalues($dumpline, \%setup, @{$setup}); + if (@values) { + push @ret, "", "\t# $plugin plugin", @values; + } + } + + return map { ref $_ ? $_->() : $_ } @ret; +} + +sub commented_dumpvalues ($$@) { + my $dumpline=shift; + my $setup=shift; + my @ret; + while (@_) { + my $key=shift; + my %info=%{shift()}; + + next if $key eq "plugin" || $info{type} eq "internal"; + + push @ret, "\t# ".$info{description} if exists $info{description}; + + if (exists $setup->{$key} && defined $setup->{$key}) { + push @ret, $dumpline->($key, $setup->{$key}, $info{type}, ""); + delete $setup->{$key}; + } + elsif (exists $info{example}) { + push @ret, $dumpline->($key, $info{example}, $info{type}, "#"); + } + else { + push @ret, $dumpline->($key, "", $info{type}, "#"); + } + } + return @ret; } 1 diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 4022ff03c..9c177e497 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -1,7 +1,6 @@ #!/usr/bin/perl # Standard ikiwiki setup module. -# Parameters to import should be all the standard ikiwiki config stuff, -# plus an array of wrappers to set up. +# Parameters to import should be all the standard ikiwiki config stuff. package IkiWiki::Setup::Standard; @@ -13,6 +12,22 @@ sub import { IkiWiki::Setup::merge($_[1]); } +sub gendump ($$) { + my $class=shift; + my $description=shift; + + "#!/usr/bin/perl", + "# $description", + "#", + "# Passing this to ikiwiki --setup will make ikiwiki generate", + "# wrappers and build the wiki.", + "#", + "# Remember to re-run ikiwiki --setup any time you edit this file.", + "use IkiWiki::Setup::Standard {", + IkiWiki::Setup::commented_dump(\&dumpline), + "}"; +} + sub dumpline ($$$$) { my $key=shift; my $value=shift; @@ -57,79 +72,4 @@ sub dumpline ($$$$) { return "\t$prefix$key => $dumpedvalue,"; } -sub dumpvalues ($@) { - my $setup=shift; - my @ret; - while (@_) { - my $key=shift; - my %info=%{shift()}; - - next if $key eq "plugin" || $info{type} eq "internal"; - - push @ret, "\t# ".$info{description} if exists $info{description}; - - if (exists $setup->{$key} && defined $setup->{$key}) { - push @ret, dumpline($key, $setup->{$key}, $info{type}, ""); - delete $setup->{$key}; - } - elsif (exists $info{example}) { - push @ret, dumpline($key, $info{example}, $info{type}, "#"); - } - else { - push @ret, dumpline($key, "", $info{type}, "#"); - } - } - return @ret; -} - -sub gendump ($$) { - my $class=shift; - my $description=shift; - - my %setup=(%config); - my @ret; - - # disable logging to syslog while dumping - $config{syslog}=undef; - - eval q{use Text::Wrap}; - die $@ if $@; - - my %section_plugins; - push @ret, dumpvalues(\%setup, IkiWiki::getsetup()); - foreach my $pair (IkiWiki::Setup::getsetup()) { - my $plugin=$pair->[0]; - my $setup=$pair->[1]; - my %s=@{$setup}; - my $section=$s{plugin}->{section}; - push @{$section_plugins{$section}}, $plugin; - if (@{$section_plugins{$section}} == 1) { - push @ret, "", "\t".("#" x 70), "\t# $section plugins", - sub { - wrap("\t# (", "\t# ", - join(", ", @{$section_plugins{$section}})).")" - }, - "\t".("#" x 70); - } - - my @values=dumpvalues(\%setup, @{$setup}); - if (@values) { - push @ret, "", "\t# $plugin plugin", @values; - } - } - - unshift @ret, - "#!/usr/bin/perl", - "# $description", - "#", - "# Passing this to ikiwiki --setup will make ikiwiki generate", - "# wrappers and build the wiki.", - "#", - "# Remember to re-run ikiwiki --setup any time you edit this file.", - "use IkiWiki::Setup::Standard {"; - push @ret, "}"; - - return map { ref $_ ? $_->() : $_ } @ret; -} - 1 -- cgit v1.2.3 From bbe1f2e493f009b49aba6ab83304f9484e37c61d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Mar 2010 15:35:21 -0400 Subject: move generic comment into IkiWiki::Setup --- IkiWiki/Setup.pm | 9 ++++++++- IkiWiki/Setup/Standard.pm | 11 +++-------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index 369ff44d0..45f263bc8 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -52,7 +52,14 @@ sub dump ($) { eval qq{require $config{setuptype}}; error $@ if $@; - my @dump=$config{setuptype}->gendump("Setup file for ikiwiki."); + my @dump=$config{setuptype}->gendump( + "Setup file for ikiwiki.", + "", + "Passing this to ikiwiki --setup will make ikiwiki generate", + "wrappers and build the wiki.", + "", + "Remember to re-run ikiwiki --setup any time you edit this file.", + ); open (OUT, ">", $file) || die "$file: $!"; print OUT "$_\n" foreach @dump; diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 9c177e497..92e97c4b4 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -12,20 +12,15 @@ sub import { IkiWiki::Setup::merge($_[1]); } -sub gendump ($$) { +sub gendump ($@) { my $class=shift; - my $description=shift; "#!/usr/bin/perl", - "# $description", "#", - "# Passing this to ikiwiki --setup will make ikiwiki generate", - "# wrappers and build the wiki.", - "#", - "# Remember to re-run ikiwiki --setup any time you edit this file.", + (map { "# $_" } @_), "use IkiWiki::Setup::Standard {", IkiWiki::Setup::commented_dump(\&dumpline), - "}"; + "}" } sub dumpline ($$$$) { -- cgit v1.2.3 From 10f8a2c85841d5884ccee096145498af96f06f05 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Mar 2010 15:36:33 -0400 Subject: improve comments --- IkiWiki/Setup/Standard.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 92e97c4b4..33b578e12 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -1,6 +1,4 @@ #!/usr/bin/perl -# Standard ikiwiki setup module. -# Parameters to import should be all the standard ikiwiki config stuff. package IkiWiki::Setup::Standard; @@ -8,6 +6,7 @@ use warnings; use strict; use IkiWiki; +# Parameters to import should be all the standard ikiwiki config, in a hash. sub import { IkiWiki::Setup::merge($_[1]); } -- cgit v1.2.3 From 19a794b4829c548a7f5b9dc22e22c24d7f28bad8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 19 Mar 2010 15:44:28 -0400 Subject: parameterized indent --- IkiWiki/Setup.pm | 20 +++++++++++--------- IkiWiki/Setup/Standard.pm | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Setup/Standard.pm') diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm index 45f263bc8..a71a12d9d 100644 --- a/IkiWiki/Setup.pm +++ b/IkiWiki/Setup.pm @@ -166,8 +166,9 @@ sub getsetup () { } keys %sections; } -sub commented_dump ($) { +sub commented_dump ($$) { my $dumpline=shift; + my $indent=shift; my %setup=(%config); my @ret; @@ -179,7 +180,7 @@ sub commented_dump ($) { die $@ if $@; my %section_plugins; - push @ret, commented_dumpvalues($dumpline, \%setup, IkiWiki::getsetup()); + push @ret, commented_dumpvalues($dumpline, $indent, \%setup, IkiWiki::getsetup()); foreach my $pair (IkiWiki::Setup::getsetup()) { my $plugin=$pair->[0]; my $setup=$pair->[1]; @@ -187,25 +188,26 @@ sub commented_dump ($) { my $section=$s{plugin}->{section}; push @{$section_plugins{$section}}, $plugin; if (@{$section_plugins{$section}} == 1) { - push @ret, "", "\t".("#" x 70), "\t# $section plugins", + push @ret, "", $indent.("#" x 70), "$indent# $section plugins", sub { - wrap("\t# (", "\t# ", + wrap("$indent# (", "$indent# ", join(", ", @{$section_plugins{$section}})).")" }, - "\t".("#" x 70); + $indent.("#" x 70); } - my @values=commented_dumpvalues($dumpline, \%setup, @{$setup}); + my @values=commented_dumpvalues($dumpline, $indent, \%setup, @{$setup}); if (@values) { - push @ret, "", "\t# $plugin plugin", @values; + push @ret, "", "$indent# $plugin plugin", @values; } } return map { ref $_ ? $_->() : $_ } @ret; } -sub commented_dumpvalues ($$@) { +sub commented_dumpvalues ($$$@) { my $dumpline=shift; + my $indent=shift; my $setup=shift; my @ret; while (@_) { @@ -214,7 +216,7 @@ sub commented_dumpvalues ($$@) { next if $key eq "plugin" || $info{type} eq "internal"; - push @ret, "\t# ".$info{description} if exists $info{description}; + push @ret, "$indent# ".$info{description} if exists $info{description}; if (exists $setup->{$key} && defined $setup->{$key}) { push @ret, $dumpline->($key, $setup->{$key}, $info{type}, ""); diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 33b578e12..c85069304 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -18,7 +18,7 @@ sub gendump ($@) { "#", (map { "# $_" } @_), "use IkiWiki::Setup::Standard {", - IkiWiki::Setup::commented_dump(\&dumpline), + IkiWiki::Setup::commented_dump(\&dumpline, "\t"), "}" } -- cgit v1.2.3