From abd233931247ef38f1b084afd5906619f02c13b6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 22 Apr 2010 15:34:32 -0400 Subject: 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. --- IkiWiki.pm | 59 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'IkiWiki.pm') 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}, -- cgit v1.2.3