From ab75c0323bc584203a2b4a507c2a2012523354d0 Mon Sep 17 00:00:00 2001 From: joey Date: Sun, 30 Jul 2006 00:20:11 +0000 Subject: [PATCH] * 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. --- IkiWiki.pm | 19 ++++++++++++----- IkiWiki/CGI.pm | 6 +----- IkiWiki/Plugin/inline.pm | 26 ++++++++--------------- IkiWiki/Plugin/skeleton.pm | 6 ++++++ IkiWiki/Render.pm | 43 ++++++++++++-------------------------- debian/changelog | 10 +++++++++ doc/index.mdwn | 18 +++++++++++----- doc/plugins/write.mdwn | 8 +++++++ doc/todo/aggregation.mdwn | 7 +++++++ ikiwiki | 6 +----- 10 files changed, 82 insertions(+), 67 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index d369d7da8..54ca84550 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -93,11 +93,7 @@ sub checkconfig () { #{{{ require IkiWiki::Rcs::Stub; } - if (exists $hooks{checkconfig}) { - foreach my $id (keys %{$hooks{checkconfig}}) { - $hooks{checkconfig}{$id}{call}->(); - } - } + run_hooks(checkconfig => sub { shift->() }); } #}}} sub loadplugins () { #{{{ @@ -503,4 +499,17 @@ sub hook (@) { # {{{ $hooks{$param{type}}{$param{id}}=\%param; } # }}} +sub run_hooks ($$) { # {{{ + # Calls the given sub for each hook of the given type, + # passing it the hook function to call. + my $type=shift; + my $sub=shift; + + if (exists $hooks{$type}) { + foreach my $id (keys %{$hooks{$type}}) { + $sub->($hooks{$type}{$id}{call}); + } + } +} #}}} + 1 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) }); } } #}}} diff --git a/debian/changelog b/debian/changelog index c20b5a102..babaefff2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +ikiwiki (1.13) UNRELEASED; urgency=low + + * 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. + + -- Joey Hess Sat, 29 Jul 2006 20:10:51 -0400 + ikiwiki (1.12) unstable; urgency=low "Viva l'Italia!" diff --git a/doc/index.mdwn b/doc/index.mdwn index 23e60c00b..1e2ec44e5 100644 --- a/doc/index.mdwn +++ b/doc/index.mdwn @@ -4,15 +4,23 @@ into html pages suitable for publishing on a website. Unlike a traditional wiki, ikiwiki does not have its own means of storing page history. Instead it can use [[Subversion]] (or [[Git]]). -* [[News]] is a blog (built using ikiwiki) of news items about ikiwiki. It's the best way to find out when there's a new version to [[Download]]. +* [[News]] is a blog (built using ikiwiki) of news items about ikiwiki. + It's the best way to find out when there's a new version to [[Download]]. -* See [[Features]] for a list of ikiwiki's features. [[RoadMap]], [[TODO]] and [[bugs]] might also be of interest. Feel free to post your thoughts about ikiwiki to [[Discussion]]. +* See [[Features]] for a list of ikiwiki's features. [[RoadMap]], [[TODO]] + and [[bugs]] might also be of interest. Feel free to post your thoughts + about ikiwiki to [[Discussion]]. -* [[Setup]] has a tutorial for setting up ikiwiki, and [[Usage]] documents the parameters and usage of the ikiwiki program. If you use ikiwiki, please add your wiki to [[IkiWikiUsers]]. +* [[Setup]] has a tutorial for setting up ikiwiki, and [[Usage]] documents + the parameters and usage of the ikiwiki program. If you use ikiwiki, + please add your wiki to [[IkiWikiUsers]]. -* [[Security]] lists potential security problems. ikiwiki is still being developed, and is being written with security as a priority, so don't expect things to stay in this list for long. +* [[Security]] lists potential security problems. ikiwiki is still being + developed, and is being written with security as a priority, so don't + expect things to stay in this list for long. -* Developers, please document any ikiwiki patches you have in the [[PatchQueue]]. +* Developers, please document any ikiwiki patches you have in the + [[PatchQueue]]. All wikis are supposed to have a [[SandBox]], so this one does too. diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 93c6d1d5c..025a242a6 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -157,6 +157,14 @@ called in turn, and passed a CGI object. The hook should examine the parameters, and if it will handle this CGI request, output a page and terminate the program. +## savestate + + IkiWiki::hook(type => "savestate", id => "foo", call => \&savestate); + +This hook is called wheneven ikiwiki normally saves its state, just before +the state is saved. The function can save other state, modify values before +they're saved, etc. + # Wiki configuration A plugin can access the wiki's configuration via the `%IkiWiki::config` diff --git a/doc/todo/aggregation.mdwn b/doc/todo/aggregation.mdwn index ce8143fa2..7d765f9e9 100644 --- a/doc/todo/aggregation.mdwn +++ b/doc/todo/aggregation.mdwn @@ -15,3 +15,10 @@ poor-man's news aggregator. better would be to use preprocessor directives in a wiki page, probably the same page that inlines all the pages together. * Where to store when a feed was last pulled? + +So I need: + +* A way to store info from the preprocessor directives about what pages + to pull and expiry. +* A way to store info on last pull time, guids, etc. +* Switch for a mode that a) pulls b) expires old c) rebuilds wiki (for cron) diff --git a/ikiwiki b/ikiwiki index a10876a96..28eba6f64 100755 --- a/ikiwiki +++ b/ikiwiki @@ -68,11 +68,7 @@ sub getconfig () { #{{{ if (! $config{setup}) { loadplugins(); - if (exists $hooks{getopt}) { - foreach my $id (keys %{$hooks{getopt}}) { - $hooks{getopt}{$id}{call}->(); - } - } + run_hooks(getopt => sub { shift->() }); if (grep /^-/, @ARGV) { print STDERR "Unknown option: $_\n" foreach grep /^-/, @ARGV; -- 2.32.0.93.g670b81a890