summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagetemplate.pm
blob: 60db8b327de0d4a60eef07e7d6e861024c0dd148 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::pagetemplate;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.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