summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-07-30 00:20:11 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-07-30 00:20:11 +0000
commitab75c0323bc584203a2b4a507c2a2012523354d0 (patch)
treeff4f82fd125bb7976b74d88520bd3cb847fc814d /IkiWiki
parent584fe78075793b2b5dc2992125e88188cae0d1c7 (diff)
* Add a run_hooks function for the common task of running all hooks of a
given type. * Add a savestate hook. * Don't put blog post forms on pages if there's no cgiurl set. * Reformat front page.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm6
-rw-r--r--IkiWiki/Plugin/inline.pm26
-rw-r--r--IkiWiki/Plugin/skeleton.pm6
-rw-r--r--IkiWiki/Render.pm43
4 files changed, 29 insertions, 52 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index 7360ca998..5e54c5674 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -567,11 +567,7 @@ sub cgi () { #{{{
my $q=CGI->new;
- if (exists $hooks{cgi}) {
- foreach my $id (keys %{$hooks{cgi}}) {
- $hooks{cgi}{$id}{call}->($q);
- }
- }
+ run_hooks(cgi => sub { shift->($q) });
my $do=$q->param('do');
if (! defined $do || ! length $do) {
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 427c25a96..7bb71a436 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -58,7 +58,7 @@ sub preprocess_inline (@) { #{{{
my $ret="";
- if (exists $params{rootpage}) {
+ if (exists $params{rootpage} && $config{cgiurl}) {
# Add a blog post form, with a rss link button.
my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
$formtemplate->param(cgiurl => $config{cgiurl});
@@ -88,15 +88,10 @@ sub preprocess_inline (@) { #{{{
if $params{archive} eq "no";
$template->param(ctime => displaytime($pagectime{$page}));
- if (exists $hooks{pagetemplate}) {
- foreach my $id (keys %{$hooks{pagetemplate}}) {
- $hooks{pagetemplate}{$id}{call}->(
- page => $page,
- destpage => $params{page},
- template => $template,
- );
- }
- }
+ run_hooks(pagetemplate => sub {
+ shift->(page => $page, destpage => $params{page},
+ template => $template,);
+ });
$ret.=$template->output;
$template->clear_params;
@@ -181,13 +176,10 @@ sub genrss ($@) { #{{{
items => \@items,
);
- foreach my $id (keys %{$hooks{pagetemplate}}) {
- $hooks{pagetemplate}{$id}{call}->(
- page => $page,
- destpage => $page,
- template => $template,
- );
- }
+ run_hooks(pagetemplate => sub {
+ shift->(page => $page, destpage => $page,
+ template => $template);
+ });
return $template->output;
} #}}}
diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm
index 27da50e6f..e63bab6d7 100644
--- a/IkiWiki/Plugin/skeleton.pm
+++ b/IkiWiki/Plugin/skeleton.pm
@@ -29,6 +29,8 @@ sub import { #{{{
call => \&change);
IkiWiki::hook(type => "cgi", id => "skeleton",
call => \&cgi);
+ IkiWiki::hook(type => "cgi", id => "savestate",
+ call => \&savestate);
} # }}}
sub getopt () { #{{{
@@ -95,4 +97,8 @@ sub cgi ($) { #{{{
IkiWiki::debug("skeleton plugin running in cgi");
} #}}}
+sub savestate () { #{{{
+ IkiWiki::debug("skeleton plugin running in savestate");
+} #}}}
+
1
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index caec7f1f0..5dbb4654c 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -31,11 +31,9 @@ sub htmlize ($$) { #{{{
error("htmlization of $type not supported");
}
- if (exists $hooks{sanitize}) {
- foreach my $id (keys %{$hooks{sanitize}}) {
- $content=$hooks{sanitize}{$id}{call}->($content);
- }
- }
+ run_hooks(sanitize => sub {
+ $content=shift->($content);
+ });
return $content;
} #}}}
@@ -206,15 +204,9 @@ sub genpage ($$$) { #{{{
styleurl => styleurl($page),
);
- if (exists $hooks{pagetemplate}) {
- foreach my $id (keys %{$hooks{pagetemplate}}) {
- $hooks{pagetemplate}{$id}{call}->(
- page => $page,
- destpage => $page,
- template => $template,
- );
- }
- }
+ run_hooks(pagetemplate => sub {
+ shift->(page => $page, destpage => $page, template => $template);
+ });
return $template->output;
} #}}}
@@ -268,14 +260,9 @@ sub filter ($$) {
my $page=shift;
my $content=shift;
- if (exists $hooks{filter}) {
- foreach my $id (keys %{$hooks{filter}}) {
- $content=$hooks{filter}{$id}{call}->(
- page => $page,
- content => $content
- );
- }
- }
+ run_hooks(filter => sub {
+ $content=shift->(page => $page, content => $content);
+ });
return $content;
}
@@ -496,15 +483,11 @@ FILE: foreach my $file (@files) {
}
}
- if (@del && exists $hooks{delete}) {
- foreach my $id (keys %{$hooks{delete}}) {
- $hooks{delete}{$id}{call}->(@del);
- }
+ if (@del) {
+ run_hooks(delete => sub { shift->(@del) });
}
- if (%rendered && exists $hooks{change}) {
- foreach my $id (keys %{$hooks{change}}) {
- $hooks{change}{$id}{call}->(keys %rendered);
- }
+ if (%rendered) {
+ run_hooks(change => sub { shift->(keys %rendered) });
}
} #}}}