aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-04-22 15:34:32 -0400
committerJoey Hess <joey@kitenet.net>2010-04-22 15:55:58 -0400
commitabd233931247ef38f1b084afd5906619f02c13b6 (patch)
tree6156798eeefd40ba3b83857112b2b09c57172797 /IkiWiki.pm
parent23d62f42bd8fe18087cd293962a79d937cf5a3bc (diff)
downloadikiwiki-abd233931247ef38f1b084afd5906619f02c13b6.tar
ikiwiki-abd233931247ef38f1b084afd5906619f02c13b6.tar.gz
look for templates in srcdir and underlays, first
This entailed changing template_params; it no longer takes the template filename as its first parameter. Add template_depends to api and replace calls to template() with template_depends() in appropriate places, where a dependency should be added on the template. Other plugins don't use template(), so will need further work. Also, includes are disabled for security. Enabling includes only when using templates from the templatedir would be nice, but would add a lot of complexity to the implementation.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm59
1 files changed, 35 insertions, 24 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index c2c2337b4..1327e4db5 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -18,8 +18,8 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%autofiles};
use Exporter q{import};
-our @EXPORT = qw(hook debug error template htmlpage deptype
- add_depends pagespec_match pagespec_match_list bestlink
+our @EXPORT = qw(hook debug error htmlpage template template_depends
+ deptype add_depends pagespec_match pagespec_match_list bestlink
htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext ngettext urlto targetpage
add_underlay pagetitle titlepage linkpage newpagefile
@@ -1652,47 +1652,58 @@ sub saveindex () {
}
sub template_file ($) {
- my $template=shift;
+ my $name=shift;
+ my $template=srcfile("templates/$name", 1);
+ return $template if defined $template;
+
foreach my $dir ($config{templatedir},
"$installdir/share/ikiwiki/templates") {
- return "$dir/$template" if -e "$dir/$template";
+ return "$dir/$name" if -e "$dir/$name";
}
return;
}
sub template_params (@) {
- my $filename=template_file(shift);
-
- if (! defined $filename) {
- return if wantarray;
- return "";
- }
+ filter => sub {
+ my $text_ref = shift;
+ ${$text_ref} = decode_utf8(${$text_ref});
+ },
+ loop_context_vars => 1,
+ die_on_bad_params => 0,
+ @_,
+ no_includes => 1,
+}
- my @ret=(
- filter => sub {
- my $text_ref = shift;
- ${$text_ref} = decode_utf8(${$text_ref});
- },
- filename => $filename,
- loop_context_vars => 1,
- die_on_bad_params => 0,
+sub template ($;@) {
+ require HTML::Template;
+ return HTML::Template->new(template_params(
+ filename => template_file(shift),
@_
- );
- return wantarray ? @ret : {@ret};
+ ));
}
-sub template ($;@) {
+sub template_depends ($$;@) {
+ my $name=shift;
+ my $page=shift;
+
+ if (defined $page) {
+ add_depends($page, "templates/$name");
+ }
+ my $filename=template_file($name);
+
require HTML::Template;
- return HTML::Template->new(template_params(@_));
+ return HTML::Template->new(template_params(
+ filename => $filename,
+ @_
+ ));
}
sub misctemplate ($$;@) {
my $title=shift;
my $pagebody=shift;
- my $template=template("misc.tmpl");
- $template->param(
+ my $template=template("misc.tmpl",
title => $title,
indexlink => indexlink(),
wikiname => $config{wikiname},