From 5742bc7856c331e503a240bfb4aa67200d3f5a49 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 22 Jun 2014 23:13:53 +0100 Subject: [PATCH] fix registering template paths --- Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod | 6 +++--- Netdisco/lib/App/Netdisco/Web.pm | 7 ++++++- Netdisco/lib/App/Netdisco/Web/Plugin.pm | 5 ++--- Netdisco/share/config.yml | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod index 0c487301..40ba2c68 100644 --- a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod +++ b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod @@ -345,9 +345,9 @@ template file of your own in your plugin, you need a new path: register_template_path( dist_dir( 'App-Netdisco-Web-Plugin-Search-MyNewFeature' )); -The registered path will be searched before the built-in C -path. We recommend use of the L module to package and ship -templates along with your plugin, as shown. +The "C" subdirectory of the registered path will be searched before the +built-in C path. We recommend use of the L +module to package and ship templates along with your plugin, as shown. Each path added using C is searched I any existing paths in the template config. See the diff --git a/Netdisco/lib/App/Netdisco/Web.pm b/Netdisco/lib/App/Netdisco/Web.pm index 455385fd..aa50da3a 100644 --- a/Netdisco/lib/App/Netdisco/Web.pm +++ b/Netdisco/lib/App/Netdisco/Web.pm @@ -14,8 +14,9 @@ use Module::Find (); use Module::Load (); use App::Netdisco::Util::Web 'interval_to_daterange'; +# FIXME: need to avoid splat so that this can be reordered +Module::Find::usesub 'App::Netdisco::Web::Auto'; Module::Find::usesub 'App::Netdisco::Web'; -Module::Find::usesub 'App::Netdisco::Auto::Web'; sub _load_web_plugins { my $plugin_list = shift; @@ -40,6 +41,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}->{template_toolkit}->{INCLUDE_PATH} }, + setting('views'); + # workaround for https://github.com/PerlDancer/Dancer/issues/935 hook after_error_render => sub { setting('layout' => 'main') }; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin.pm b/Netdisco/lib/App/Netdisco/Web/Plugin.pm index e07860a4..49650d00 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin.pm @@ -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}->{template_toolkit}->{INCLUDE_PATH} }, + dir($path, 'views')->stringify; }; sub _register_include { diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 8479600f..cad0966c 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -223,6 +223,7 @@ engines: start_tag: '[%' end_tag: '%]' PRE_CHOMP: 1 + INCLUDE_PATH: [] layout: 'main' plugins: Auth::Extensible: