]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add a run_hooks function for the common task of running all hooks of a
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 30 Jul 2006 00:20:11 +0000 (00:20 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sun, 30 Jul 2006 00:20:11 +0000 (00:20 +0000)
  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
IkiWiki/CGI.pm
IkiWiki/Plugin/inline.pm
IkiWiki/Plugin/skeleton.pm
IkiWiki/Render.pm
debian/changelog
doc/index.mdwn
doc/plugins/write.mdwn
doc/todo/aggregation.mdwn
ikiwiki

index d369d7da839589f3d440a47e083a241e3cf45389..54ca845501d0396e1893b70ed61e0b98da6a75db 100644 (file)
@@ -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
index 7360ca998f29757032955d343122ab2cf32002e8..5e54c5674acb36b96de4960fefc8c05682d6a0d0 100644 (file)
@@ -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) {
index 427c25a96d75f8ffdd760a487ad1ae704ee80364..7bb71a436783fe3ca57515fab67e42e39170622a 100644 (file)
@@ -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;
 } #}}}
index 27da50e6fba80fe7c998dbbcb7b4265c56f42a76..e63bab6d76e04fed3e6b22e5fce0b7ca69ced692 100644 (file)
@@ -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
index caec7f1f01999361f5f416b9f8d3a096e5adb492..5dbb4654c948446abb95fd5d4c7f40d35d8f06e3 100644 (file)
@@ -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) });
        }
 } #}}}
 
index c20b5a1021e95ab30fe07f8a8e7788a30e31228a..babaefff2dc99a6d25a1520f42fd04125f6a60c8 100644 (file)
@@ -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 <joeyh@debian.org>  Sat, 29 Jul 2006 20:10:51 -0400
+
 ikiwiki (1.12) unstable; urgency=low
 
   "Viva l'Italia!"
index 23e60c00bb5b7e671fb2569ff5cc15c0ee57bf32..1e2ec44e55cf30eb1df6d0250b4965ca7f67c7cd 100644 (file)
@@ -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.
 
index 93c6d1d5cbb216975384bf904f54d80cb14e8c6f..025a242a63c4318888225dd9975e7e680f8194f4 100644 (file)
@@ -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`
index ce8143fa277283339d09856de96e9066c5ec232e..7d765f9e9b51d75b4e6a9b7f1cdd8735facfff72 100644 (file)
@@ -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 a10876a96ba10b6fb888c13742f32c34ddf97939..28eba6f64e98e1298e9a32e61dbe6cb1f2897847 100755 (executable)
--- 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;