diff options
author | Joey Hess <joey@kitenet.net> | 2010-05-14 20:20:41 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-05-14 20:20:41 -0400 |
commit | bbe971881a7a3c03dfdb5312215c434e35eff94e (patch) | |
tree | ba57cfc88103d80c76e62c97110e0e4c70951187 | |
parent | 377e82b16c95833a37c1f87e57122e8b44c187cb (diff) |
refactor template actions
-rw-r--r-- | IkiWiki.pm | 22 | ||||
-rw-r--r-- | IkiWiki/Render.pm | 18 |
2 files changed, 21 insertions, 19 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm index 46c29abe3..a42f56bf0 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1755,18 +1755,32 @@ sub misctemplate ($$;@) { html5 => $config{html5}, @_, ); + + templateactions($template, ""); + return $template->output; +} + +sub templateactions ($$) { + my $template=shift; + my $page=shift; + + my $have_actions=0; my @actions; run_hooks(pageactions => sub { push @actions, map { { action => $_ } } - grep { defined } shift->(page => ""); + grep { defined } shift->(page => $page); }); $template->param(actions => \@actions); - if (@actions) { - $template->param(have_actions => 1); + + if ($config{cgiurl} && exists $hooks{auth}) { + $template->param(prefsurl => cgiurl(do => "prefs")); + $have_actions=1; } - return $template->output; + if ($have_actions || @actions) { + $template->param(have_actions => 1); + } } sub hook (@) { diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 8b1b9aef4..833fcaaff 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -84,19 +84,14 @@ sub genpage ($$) { $template=template('page.tmpl', blind_cache => 1); } - my $actions=0; + my $actions=0; if (length $config{cgiurl}) { if (IkiWiki->can("cgi_editpage")) { $template->param(editurl => cgiurl(do => "edit", page => $page)); $actions++; } - if (exists $hooks{auth}) { - $template->param(prefsurl => cgiurl(do => "prefs")); - $actions++; - } } - if (defined $config{historyurl} && length $config{historyurl}) { my $u=$config{historyurl}; $u=~s/\[\[file\]\]/$pagesources{$page}/g; @@ -111,17 +106,10 @@ sub genpage ($$) { $actions++; } } - - my @actions; - run_hooks(pageactions => sub { - push @actions, map { { action => $_ } } - grep { defined } shift->(page => $page); - }); - $template->param(actions => \@actions); - - if ($actions || @actions) { + if ($actions) { $template->param(have_actions => 1); } + templateactions($template, $page); my @backlinks=sort { $a->{page} cmp $b->{page} } backlinks($page); my ($backlinks, $more_backlinks); |