summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagetemplate.pm
blob: b5ebf623d19a08d94e669ce1940534141e46e0e1 (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. return "[[pagetemplate ".gettext("bad or missing template")."]]";
  17. }
  18. if ($params{page} eq $params{destpage}) {
  19. $templates{$params{page}}=$params{template};
  20. }
  21. } # }}}
  22. sub templatefile (@) { #{{{
  23. my %params=@_;
  24. if (exists $templates{$params{page}}) {
  25. return $templates{$params{page}};
  26. }
  27. return undef;
  28. } # }}}
  29. 1