diff options
author | Joey Hess <joey@kitenet.net> | 2010-04-17 13:35:15 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-04-17 13:35:15 -0400 |
commit | b7d50abc0f3dbe99d2a3664c12ea95d24bfcf04b (patch) | |
tree | bd716da03086a6c47df994723d424454c090649d /IkiWiki | |
parent | 2269a4c74b24378d8e7e2229ca3374a197d08d9c (diff) | |
download | ikiwiki-b7d50abc0f3dbe99d2a3664c12ea95d24bfcf04b.tar ikiwiki-b7d50abc0f3dbe99d2a3664c12ea95d24bfcf04b.tar.gz |
refactor autofiles
Made add_autofile take a generator function, and just register the
autofile, for later possible creation. The testing is moved into Render,
which allows cleaning up some stuff.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/tag.pm | 12 | ||||
-rw-r--r-- | IkiWiki/Render.pm | 52 |
2 files changed, 44 insertions, 20 deletions
diff --git a/IkiWiki/Plugin/tag.pm b/IkiWiki/Plugin/tag.pm index 9e6f417bf..7a918a4e8 100644 --- a/IkiWiki/Plugin/tag.pm +++ b/IkiWiki/Plugin/tag.pm @@ -70,13 +70,13 @@ sub gentag ($) { my $tagfile = newpagefile(tagpage($tag), $config{default_pageext}); $tagfile=~s/^\///; - return if (! add_autofile($tagfile, "tag")); + add_autofile($tagfile, sub { + debug(sprintf(gettext("creating tag page %s"), $tag)); - debug(sprintf(gettext("creating tag page %s"), $tag)); - - my $template=template("autotag.tmpl"); - $template->param(tag => $tag); - writefile($tagfile, $config{srcdir}, $template->output); + my $template=template("autotag.tmpl"); + $template->param(tag => $tag); + writefile($tagfile, $config{srcdir}, $template->output); + }); } } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index c80030deb..83242a197 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -680,6 +680,37 @@ sub render_backlinks ($) { } } +sub gen_autofile ($$$) { + my $autofile=shift; + my $pages=shift; + my $del=shift; + + if (srcfile($autofile, 1)) { + return 0; + } + + my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir}); + + if ((!defined $file) || + (exists $wikistate{$autofiles{$autofile}{plugin}}{autofile_deleted})) { + return 0; + } + + if ($pages->{$page}) { + return 0; + } + + if (grep { $_ eq $file } @$del) { + $wikistate{$autofiles{$autofile}{generator}}{autofile_deleted}=1; + return 0; + } + + $autofiles{$autofile}{generator}->(); + $pages->{$page}=1; + return 1; +} + + sub refresh () { srcdir_check(); run_hooks(refresh => sub { shift->() }); @@ -689,26 +720,19 @@ sub refresh () { my ($changed, $internal_changed)=find_changed($files); run_hooks(needsbuild => sub { shift->($changed) }); my $oldlink_targets=calculate_old_links($changed, $del); - %del_hash = map { $_ => 1 } @{$del}; foreach my $file (@$changed) { scan($file); } - while (my $autofile = shift @{[keys %autofiles]}) { - my $plugin=$autofiles{$autofile}; - my $page=pagename($autofile); - if ($pages->{$page}) { - debug(sprintf(gettext("%s has multiple possible source pages"), $page)); + foreach my $autofile (keys %autofiles) { + if (gen_autofile($autofile, $pages, $del)) { + push @{$files}, $autofile; + push @{$new}, $autofile if find_new_files([$autofile]); + push @{$changed}, $autofile if find_changed([$autofile]); + + scan($autofile); } - $pages->{$page}=1; - - push @{$files}, $autofile; - push @{$new}, $autofile if find_new_files([$autofile]); - push @{$changed}, $autofile if find_changed([$autofile]); - - scan($autofile); - delete $autofiles{$autofile}; } calculate_links(); |