properly search the template path!! [#103]
Conflicts: Netdisco/lib/App/Netdisco/Web.pm Netdisco/lib/App/Netdisco/Web/Plugin.pm
This commit is contained in:
@@ -48,6 +48,10 @@ if (setting('extra_web_plugins') and ref [] eq ref setting('extra_web_plugins'))
|
||||
_load_web_plugins( setting('extra_web_plugins') );
|
||||
}
|
||||
|
||||
# after plugins are loaded, add our own template path
|
||||
push @{ config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} },
|
||||
setting('views');
|
||||
|
||||
# workaround for https://github.com/PerlDancer/Dancer/issues/935
|
||||
hook after_error_render => sub { setting('layout' => 'main') };
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ set(
|
||||
);
|
||||
|
||||
# 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 {
|
||||
my ($self, $path) = plugin_args(@_);
|
||||
@@ -30,9 +30,8 @@ register 'register_template_path' => sub {
|
||||
return error "bad template path to register_template_paths";
|
||||
}
|
||||
|
||||
unshift
|
||||
@{ config->{engines}->{template_toolkit}->{INCLUDE_PATH} },
|
||||
$path, dir($path, 'views')->stringify;
|
||||
push @{ config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} },
|
||||
dir($path, 'views')->stringify;
|
||||
};
|
||||
|
||||
sub _register_include {
|
||||
|
||||
23
Netdisco/lib/Dancer/Template/NetdiscoTemplateToolkit.pm
Normal file
23
Netdisco/lib/Dancer/Template/NetdiscoTemplateToolkit.pm
Normal 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;
|
||||
Reference in New Issue
Block a user