summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagetemplate.pm
blob: 205f5a9d77b13ce34b6b30d7d528f7658315df09 (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 => "preprocess", id => "pagetemplate", call => \&preprocess);
  9. hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
  10. } # }}}
  11. sub preprocess (@) { #{{{
  12. my %params=@_;
  13. if (! exists $params{template} ||
  14. $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
  15. ! defined IkiWiki::template_file($params{template})) {
  16. error gettext("bad or missing template")
  17. }
  18. if ($params{page} eq $params{destpage}) {
  19. $templates{$params{page}}=$params{template};
  20. }
  21. return "";
  22. } # }}}
  23. sub templatefile (@) { #{{{
  24. my %params=@_;
  25. if (exists $templates{$params{page}}) {
  26. return $templates{$params{page}};
  27. }
  28. return undef;
  29. } # }}}
  30. 1