]> rtime.felk.cvut.cz Git - sojka/ikiwiki.git/commitdiff
Merge remote branch 'smcv/ready/transient-tag'
authorJoey Hess <joey@kitenet.net>
Wed, 9 Feb 2011 18:11:06 +0000 (14:11 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 9 Feb 2011 18:11:06 +0000 (14:11 -0400)
Conflicts:
t/tag.t

IkiWiki/Plugin/tag.pm
t/tag.t

index fd5ce1e8a91488ce5d5b20709001fd3d177def97..13dabce0c16cef34b85eab82fcc8c6c9aab2af54 100644 (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);
diff --git a/t/tag.t b/t/tag.t
index 2d0a6e6627ab3a65fca614c52327545bb758d193..9f2a8f3eca7223147708a460eccd59c080579d6f 100755 (executable)
--- a/t/tag.t
+++ b/t/tag.t
@@ -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 = ();