summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-07-26 20:50:55 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-07-26 20:50:55 +0000
commit40959ce76d159cefaf0431ad2cc61ad35a9f99b1 (patch)
treea30b415dbb712912fd45584b9861bb680562aba7 /IkiWiki
parente64442aa08c1d368f0ab3284016b0addb3ac4a67 (diff)
* Add templatefile hook.
* Add pagetemplate plugin, which allows changing the template used for a page. (Not to be confused with the hook of the same name..)
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/pagetemplate.pm40
-rw-r--r--IkiWiki/Plugin/skeleton.pm8
-rw-r--r--IkiWiki/Render.pm10
3 files changed, 57 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/pagetemplate.pm b/IkiWiki/Plugin/pagetemplate.pm
new file mode 100644
index 000000000..b5ebf623d
--- /dev/null
+++ b/IkiWiki/Plugin/pagetemplate.pm
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::pagetemplate;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+my %templates;
+
+sub import { #{{{
+ hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
+ hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
+} # }}}
+
+sub preprocess (@) { #{{{
+ my %params=@_;
+
+ if (! exists $params{template} ||
+ $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
+ ! defined IkiWiki::template_file($params{template})) {
+ return "[[pagetemplate ".gettext("bad or missing template")."]]";
+ }
+
+ if ($params{page} eq $params{destpage}) {
+ $templates{$params{page}}=$params{template};
+ }
+
+} # }}}
+
+sub templatefile (@) { #{{{
+ my %params=@_;
+
+ if (exists $templates{$params{page}}) {
+ return $templates{$params{page}};
+ }
+
+ return undef;
+} # }}}
+
+1
diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm
index fb4cfe9af..d1a50c03b 100644
--- a/IkiWiki/Plugin/skeleton.pm
+++ b/IkiWiki/Plugin/skeleton.pm
@@ -18,6 +18,7 @@ sub import { #{{{
hook(type => "sanitize", id => "skeleton", call => \&sanitize);
hook(type => "format", id => "skeleton", call => \&format);
hook(type => "pagetemplate", id => "skeleton", call => \&pagetemplate);
+ hook(type => "templatefile", id => "skeleton", call => \&templatefile);
hook(type => "delete", id => "skeleton", call => \&delete);
hook(type => "change", id => "skeleton", call => \&change);
hook(type => "cgi", id => "skeleton", call => \&cgi);
@@ -86,6 +87,13 @@ sub pagetemplate (@) { #{{{
debug("skeleton plugin running as a pagetemplate hook");
} # }}}
+sub templatefile (@) { #{{{
+ my %params=@_;
+ my $page=$params{page};
+
+ debug("skeleton plugin running as a templatefile hook");
+} # }}}
+
sub delete (@) { #{{{
my @files=@_;
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 911e9c273..a95da40d2 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -69,7 +69,15 @@ sub genpage ($$$) { #{{{
my $content=shift;
my $mtime=shift;
- my $template=template("page.tmpl", blind_cache => 1);
+ my $templatefile;
+ run_hooks(templatefile => sub {
+ return if defined $templatefile;
+ my $file=shift->(page => $page);
+ if (defined $file && defined template_file($file)) {
+ $templatefile=$file;
+ }
+ });
+ my $template=template(defined $templatefile ? $templatefile : 'page.tmpl', blind_cache => 1);
my $actions=0;
if (length $config{cgiurl}) {