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.master
parent
2269a4c74b
commit
b7d50abc0f
35
IkiWiki.pm
35
IkiWiki.pm
|
@ -15,7 +15,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
|
|||
%pagestate %wikistate %renderedfiles %oldrenderedfiles
|
||||
%pagesources %destsources %depends %depends_simple %hooks
|
||||
%forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
|
||||
%autofiles %del_hash};
|
||||
%autofiles};
|
||||
|
||||
use Exporter q{import};
|
||||
our @EXPORT = qw(hook debug error template htmlpage deptype
|
||||
|
@ -1956,6 +1956,15 @@ sub add_link ($$;$) {
|
|||
}
|
||||
}
|
||||
|
||||
sub add_autofile ($$$) {
|
||||
my $file=shift;
|
||||
my $plugin=shift;
|
||||
my $generator=shift;
|
||||
|
||||
$autofiles{$file}{plugin}=$plugin;
|
||||
$autofiles{$file}{generator}=$generator;
|
||||
}
|
||||
|
||||
sub sortspec_translate ($$) {
|
||||
my $spec = shift;
|
||||
my $reverse = shift;
|
||||
|
@ -2021,30 +2030,6 @@ sub sortspec_translate ($$) {
|
|||
return eval 'sub { '.$code.' }';
|
||||
}
|
||||
|
||||
sub add_autofile ($$) {
|
||||
my $autofile=shift;
|
||||
my $plugin=shift;
|
||||
|
||||
if (srcfile($autofile, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir});
|
||||
|
||||
if ((!defined $file) ||
|
||||
(exists $pagestate{$page}{$plugin}{autofile_deleted})) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (exists $del_hash{$file}) {
|
||||
$pagestate{$page}{$plugin}{autofile_deleted}=1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$autofiles{$file}=$plugin;
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub pagespec_translate ($) {
|
||||
my $spec=shift;
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
my $template=template("autotag.tmpl");
|
||||
$template->param(tag => $tag);
|
||||
writefile($tagfile, $config{srcdir}, $template->output);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
$pages->{$page}=1;
|
||||
|
||||
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);
|
||||
delete $autofiles{$autofile};
|
||||
}
|
||||
}
|
||||
|
||||
calculate_links();
|
||||
|
|
Loading…
Reference in New Issue