* Search in default location for templates as a fallback when templatedir is
pointed elsewhere, so that only modified templates need to be copied into a templatedir. Based on work by JeremyReed.master
parent
b26b1d51ab
commit
8c8ce06a1b
25
IkiWiki.pm
25
IkiWiki.pm
|
@ -636,18 +636,35 @@ sub saveindex () { #{{{
|
||||||
close OUT;
|
close OUT;
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
sub template_file ($) { #{{{
|
||||||
|
my $template=shift;
|
||||||
|
|
||||||
|
foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
|
||||||
|
return "$dir/$template" if -e "$dir/$template";
|
||||||
|
}
|
||||||
|
return undef;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
sub template_params (@) { #{{{
|
sub template_params (@) { #{{{
|
||||||
my $filename=shift;
|
my $filename=template_file(shift);
|
||||||
|
|
||||||
|
if (! defined $filename) {
|
||||||
|
return if wantarray;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
require HTML::Template;
|
require HTML::Template;
|
||||||
return filter => sub {
|
my @ret=(
|
||||||
|
filter => sub {
|
||||||
my $text_ref = shift;
|
my $text_ref = shift;
|
||||||
$$text_ref=&Encode::decode_utf8($$text_ref);
|
$$text_ref=&Encode::decode_utf8($$text_ref);
|
||||||
},
|
},
|
||||||
filename => "$config{templatedir}/$filename",
|
filename => $filename,
|
||||||
loop_context_vars => 1,
|
loop_context_vars => 1,
|
||||||
die_on_bad_params => 0,
|
die_on_bad_params => 0,
|
||||||
@_;
|
@_
|
||||||
|
);
|
||||||
|
return wantarray ? @ret : {@ret};
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub template ($;@) { #{{{
|
sub template ($;@) { #{{{
|
||||||
|
|
|
@ -129,8 +129,7 @@ sub cgi_signin ($$) { #{{{
|
||||||
params => $q,
|
params => $q,
|
||||||
action => $config{cgiurl},
|
action => $config{cgiurl},
|
||||||
header => 0,
|
header => 0,
|
||||||
template => (-e "$config{templatedir}/signin.tmpl" ?
|
template => scalar template_params("signin.tmpl"),
|
||||||
{template_params("signin.tmpl")} : ""),
|
|
||||||
stylesheet => baseurl()."style.css",
|
stylesheet => baseurl()."style.css",
|
||||||
);
|
);
|
||||||
my $buttons=["Login"];
|
my $buttons=["Login"];
|
||||||
|
@ -198,8 +197,7 @@ sub cgi_prefs ($$) { #{{{
|
||||||
javascript => 0,
|
javascript => 0,
|
||||||
params => $q,
|
params => $q,
|
||||||
action => $config{cgiurl},
|
action => $config{cgiurl},
|
||||||
template => (-e "$config{templatedir}/prefs.tmpl" ?
|
template => scalar template_params("prefs.tmpl"),
|
||||||
{template_params("prefs.tmpl")} : ""),
|
|
||||||
stylesheet => baseurl()."style.css",
|
stylesheet => baseurl()."style.css",
|
||||||
);
|
);
|
||||||
my $buttons=["Save Preferences", "Logout", "Cancel"];
|
my $buttons=["Save Preferences", "Logout", "Cancel"];
|
||||||
|
@ -293,8 +291,7 @@ sub cgi_editpage ($$) { #{{{
|
||||||
params => $q,
|
params => $q,
|
||||||
action => $config{cgiurl},
|
action => $config{cgiurl},
|
||||||
table => 0,
|
table => 0,
|
||||||
template => (-e "$config{templatedir}/editpage.tmpl" ?
|
template => scalar template_params("editpage.tmpl"),
|
||||||
{template_params("editpage.tmpl")} : ""),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
run_hooks(formbuilder_setup => sub {
|
run_hooks(formbuilder_setup => sub {
|
||||||
|
|
|
@ -10,8 +10,11 @@ ikiwiki (1.39) UNRELEASED; urgency=low
|
||||||
* Fix encoding issue with use of Locale::Gettext. Seems that the OO
|
* Fix encoding issue with use of Locale::Gettext. Seems that the OO
|
||||||
interface returns proper utf-8 decoded strings, unlike the traditional
|
interface returns proper utf-8 decoded strings, unlike the traditional
|
||||||
interface, so use the OO interface.
|
interface, so use the OO interface.
|
||||||
|
* Search in default location for templates as a fallback when templatedir is
|
||||||
|
pointed elsewhere, so that only modified templates need to be copied into
|
||||||
|
a templatedir. Based on work by JeremyReed.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Thu, 11 Jan 2007 18:59:49 -0500
|
-- Joey Hess <joeyh@debian.org> Fri, 12 Jan 2007 15:34:14 -0500
|
||||||
|
|
||||||
ikiwiki (1.38) unstable; urgency=low
|
ikiwiki (1.38) unstable; urgency=low
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
It would be nice if you didn't have to copy all templates to your custom templatedir so you only have your customizations there. And then have it fall back to the location as configured at build time (like /usr/share/ikiwiki/templates/). This would be similar to underlaydir. I don't think any extra configuration directive is needed. As it is now, RecentChanges will have Perl CGI error and Preferences will be an empty page, if you don't have corresponding templates.
|
|
||||||
|
|
||||||
I have been testing the following. Sorry if the don't match up as I may have other changes (unrelated) also.
|
|
||||||
|
|
||||||
(no markdown for patch, so open in editor to real)
|
|
||||||
|
|
||||||
--- IkiWiki.pm.save 2007-01-12 09:05:48.000000000 +0900
|
|
||||||
+++ IkiWiki.pm 2007-01-12 09:08:24.000000000 +0900
|
|
||||||
@@ -638,7 +638,9 @@
|
|
||||||
my $text_ref = shift;
|
|
||||||
$$text_ref=&Encode::decode_utf8($$text_ref);
|
|
||||||
},
|
|
||||||
- filename => "$config{templatedir}/$filename",
|
|
||||||
+ filename => (-e "$config{templatedir}/$filename" ?
|
|
||||||
+ "$config{templatedir}/$filename" :
|
|
||||||
+ "$installdir/share/ikiwiki/templates/$filename"),
|
|
||||||
loop_context_vars => 1,
|
|
||||||
die_on_bad_params => 0,
|
|
||||||
@_;
|
|
||||||
|
|
||||||
--- IkiWiki/CGI.pm.orig 2007-01-01 07:18:26.000000000 +0900
|
|
||||||
+++ IkiWiki/CGI.pm 2007-01-12 10:29:14.000000000 +0900
|
|
||||||
@@ -291,8 +294,7 @@
|
|
||||||
params => $q,
|
|
||||||
action => $config{cgiurl},
|
|
||||||
table => 0,
|
|
||||||
- template => (-e "$config{templatedir}/editpage.tmpl" ?
|
|
||||||
- {template_params("editpage.tmpl")} : ""),
|
|
||||||
+ template => {template_params("editpage.tmpl")},
|
|
||||||
);
|
|
||||||
|
|
||||||
run_hooks(formbuilder_setup => sub {
|
|
||||||
|
|
||||||
|
|
||||||
Note I don't do prefs nor signin because they are not real users of templates.
|
|
||||||
Also, the above is a little redundant as by default it will use same path for both.
|
|
||||||
|
|
||||||
Once something like this is in source then usage can be updated
|
|
|
@ -101,9 +101,10 @@ configuration options of their own.
|
||||||
|
|
||||||
* --templatedir
|
* --templatedir
|
||||||
|
|
||||||
Specify the directory that the page [[templates]] are stored in.
|
Specify the directory that the page [[templates]] are stored in. Default
|
||||||
Default is `/usr/share/ikiwiki/templates`, or another location as
|
is `/usr/share/ikiwiki/templates`, or another location as configured at
|
||||||
configured at build time.
|
build time. If the templatedir is changed, missing templates will still
|
||||||
|
be searched for in the default location as a fallback.
|
||||||
|
|
||||||
* --underlaydir
|
* --underlaydir
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue