add paths to plugin files in copyright
[ikiwiki.git] / IkiWiki / Plugin / pagetemplate.pm
blob1d8a84ca77726d5d8486fc632b2606b98e25b5f6
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::pagetemplate;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 my %templates;
10 sub import {
11 hook(type => "getsetup", id => "pagetemplate", call => \&getsetup);
12 hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
13 hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
16 sub getsetup () {
17 return
18 plugin => {
19 safe => 1,
20 rebuild => undef,
24 sub preprocess (@) {
25 my %params=@_;
27 if (! exists $params{template} ||
28 $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
29 ! defined IkiWiki::template_file($params{template})) {
30 error gettext("bad or missing template")
33 if ($params{page} eq $params{destpage}) {
34 $templates{$params{page}}=$params{template};
37 return "";
40 sub templatefile (@) {
41 my %params=@_;
43 if (exists $templates{$params{page}}) {
44 return $templates{$params{page}};
47 return undef;