summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagetemplate.pm
blob: 1d8a84ca77726d5d8486fc632b2606b98e25b5f6 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagetemplate;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. my %templates;
  7. sub import {
  8. hook(type => "getsetup", id => "pagetemplate", call => \&getsetup);
  9. hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
  10. hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
  11. }
  12. sub getsetup () {
  13. return
  14. plugin => {
  15. safe => 1,
  16. rebuild => undef,
  17. },
  18. }
  19. sub preprocess (@) {
  20. my %params=@_;
  21. if (! exists $params{template} ||
  22. $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
  23. ! defined IkiWiki::template_file($params{template})) {
  24. error gettext("bad or missing template")
  25. }
  26. if ($params{page} eq $params{destpage}) {
  27. $templates{$params{page}}=$params{template};
  28. }
  29. return "";
  30. }
  31. sub templatefile (@) {
  32. my %params=@_;
  33. if (exists $templates{$params{page}}) {
  34. return $templates{$params{page}};
  35. }
  36. return undef;
  37. }
  38. 1