diff --git a/Netdisco/Changes b/Netdisco/Changes index df801042..ddaef1d2 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,12 +1,18 @@ +2.007000_001 - + + [NEW FEATURES] + + * Plugins can now 'register_template_path' and supply their own HTML templates + 2.006000 - 2013-03-07 - [ENHANCEMENTS] + [BUG FIXES] * Documentation fixups 2.005000_004 - 2013-03-05 - [ENHANCEMENTS] + [BUG FIXES] * Documentation fixups diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin.pm b/Netdisco/lib/App/Netdisco/Web/Plugin.pm index 56a5e430..c1f5172d 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin.pm @@ -9,6 +9,20 @@ set( 'device_tabs' => [], ); +# this is what Dancer::Template::TemplateToolkit does by default +config->{engines}->{template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ]; + +register 'register_template_path' => sub { + my ($self, $path) = plugin_args(@_); + + die "bad template path to register_template_paths\n" + unless length $path; + + unshift + @{ config->{engines}->{template_toolkit}->{INCLUDE_PATH} }, + $path; +}; + register 'register_navbar_item' => sub { my ($self, $config) = plugin_args(@_); @@ -246,18 +260,26 @@ the name of the registration helper sub: register_device_tab({id => 'newfeature', label => 'My New Feature'}); -=head1 Templates +=head2 Templates All of Netdisco's web page templates are stashed away in its distribution, probably installed in your system's or user's Perl directory. It's not recommended that you mess about with those files. So in order to replace a template with your own version, or to reference a -template file of your own in your plugin, you need a new path. +template file of your own in your plugin, you need a new path: -TODO: this bit! + package App::Netdisco::Web::Plugin::Search::MyNewFeature + + use File::ShareDir 'dist_dir'; + register_template_path( + dist_dir( 'App-Netdisco-Web-Plugin-Search-MyNewFeature' )); -=head2 Template Variables +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. + +=head3 Template Variables Some useful variables are made available in your templates automatically by App::Netdisco: diff --git a/TODO b/TODO index 9c2c9701..e71076b6 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ FRONTEND * UI for topo DB table editing - drop topo file support and use DB only * update inventory to use bootstrap accordion -* UI plugins add template include path * reports page * reports plugin(s) * (jeneric) device module tab