Merge remote branch 'smcv/ready/transient-tag'

Conflicts:
	t/tag.t
master
Joey Hess 2011-02-09 14:11:06 -04:00
commit 8e8311718a
2 changed files with 31 additions and 6 deletions

View File

@ -7,11 +7,14 @@ use strict;
use IkiWiki 3.00;
sub import {
hook(type => "checkconfig", id => "tag", call => \&checkconfig);
hook(type => "getopt", id => "tag", call => \&getopt);
hook(type => "getsetup", id => "tag", call => \&getsetup);
hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1);
hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1);
hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
IkiWiki::loadplugin("transient");
}
sub getopt () {
@ -41,6 +44,20 @@ sub getsetup () {
safe => 1,
rebuild => undef,
},
tag_autocreate_commit => {
type => "boolean",
example => 1,
default => 1,
description => "commit autocreated tag pages",
safe => 1,
rebuild => 0,
},
}
sub checkconfig () {
if (! defined $config{tag_autocreate_commit}) {
$config{tag_autocreate_commit} = 1;
}
}
sub taglink ($) {
@ -97,8 +114,14 @@ sub gentag ($) {
my $template=template("autotag.tmpl");
$template->param(tagname => tagname($tag));
$template->param(tag => $tag);
writefile($tagfile, $config{srcdir}, $template->output);
if ($config{rcs}) {
my $dir = $config{srcdir};
if (! $config{tag_autocreate_commit}) {
$dir = $IkiWiki::Plugin::transient::transientdir;
}
writefile($tagfile, $dir, $template->output);
if ($config{rcs} && $config{tag_autocreate_commit}) {
IkiWiki::disable_commit_hook();
IkiWiki::rcs_add($tagfile);
IkiWiki::rcs_commit_staged(message => $message);

10
t/tag.t
View File

@ -3,7 +3,7 @@ package IkiWiki;
use warnings;
use strict;
use Test::More tests => 22;
use Test::More tests => 23;
BEGIN { use_ok("IkiWiki"); }
BEGIN { use_ok("IkiWiki::Render"); }
@ -22,6 +22,7 @@ $config{wiki_file_chars} = "-[:alnum:]+/.:_";
$config{userdir} = "users";
$config{tagbase} = "tags";
$config{tag_autocreate} = 1;
$config{tag_autocreate_commit} = 0;
$config{default_pageext} = "mdwn";
$config{wiki_file_prune_regexps} = [qr/^\./];
$config{underlaydirbase} = '.';
@ -63,9 +64,10 @@ is_deeply([sort keys %autofiles], [qw(tags/lucky.mdwn tags/numbers.mdwn tags/pri
ok(!-e "t/tmp/tags/lucky.mdwn");
my (%pages, @del);
IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
is_deeply(\%pages, {"t/tmp/tags/lucky" => 1});
is_deeply(\@del, []);
ok(-s "t/tmp/tags/lucky.mdwn");
ok(! -s "t/tmp/tags/lucky.mdwn");
ok(-s "t/tmp/.ikiwiki/transient/tags/lucky.mdwn");
is_deeply(\%pages, {"t/tmp/tags/lucky" => 1}) || diag explain \%pages;
is_deeply(\@del, []) || diag explain \@del;
# generating an autofile that already exists does nothing
%pages = @del = ();