properly search the template path!! [#103]

This commit is contained in:
Oliver Gorwits
2014-06-23 20:35:30 +01:00
parent 5742bc7856
commit caedbdadc6
4 changed files with 28 additions and 5 deletions

View File

@@ -42,7 +42,7 @@ if (setting('extra_web_plugins') and ref [] eq ref setting('extra_web_plugins'))
} }
# after plugins are loaded, add our own template path # after plugins are loaded, add our own template path
push @{ config->{engines}->{template_toolkit}->{INCLUDE_PATH} }, push @{ config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} },
setting('views'); setting('views');
# workaround for https://github.com/PerlDancer/Dancer/issues/935 # workaround for https://github.com/PerlDancer/Dancer/issues/935

View File

@@ -21,7 +21,7 @@ set(
); );
# this is what Dancer::Template::TemplateToolkit does by default # this is what Dancer::Template::TemplateToolkit does by default
config->{engines}->{template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ]; config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ];
register 'register_template_path' => sub { register 'register_template_path' => sub {
my ($self, $path) = plugin_args(@_); my ($self, $path) = plugin_args(@_);
@@ -30,7 +30,7 @@ register 'register_template_path' => sub {
return error "bad template path to register_template_paths"; return error "bad template path to register_template_paths";
} }
push @{ config->{engines}->{template_toolkit}->{INCLUDE_PATH} }, push @{ config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} },
dir($path, 'views')->stringify; dir($path, 'views')->stringify;
}; };

View File

@@ -0,0 +1,23 @@
package Dancer::Template::NetdiscoTemplateToolkit;
use strict;
use warnings;
use Dancer::FileUtils 'path';
use base 'Dancer::Template::TemplateToolkit';
sub view {
my ($self, $view) = @_;
foreach my $path (@{ $self->config->{INCLUDE_PATH} }) {
foreach my $template ($self->_template_name($view)) {
my $view_path = path($path, $template);
return $view_path if -f $view_path;
}
}
# No matching view path was found
return;
}
1;

View File

@@ -218,7 +218,7 @@ warnings: false
show_errors: false show_errors: false
logger: 'console' logger: 'console'
engines: engines:
template_toolkit: netdisco_template_toolkit:
encoding: 'utf8' encoding: 'utf8'
start_tag: '[%' start_tag: '[%'
end_tag: '%]' end_tag: '%]'
@@ -235,7 +235,7 @@ plugins:
provider: 'App::Netdisco::Web::Auth::Provider::DBIC' provider: 'App::Netdisco::Web::Auth::Provider::DBIC'
schema_name: 'netdisco' schema_name: 'netdisco'
session: 'YAML' session: 'YAML'
template: 'template_toolkit' template: 'netdisco_template_toolkit'
route_cache: true route_cache: true
appname: 'Netdisco' appname: 'Netdisco'
behind_proxy: false behind_proxy: false