Plugins can now 'register_template_path' and supply their own HTML templates

This commit is contained in:
Oliver Gorwits
2013-03-10 00:50:39 +00:00
parent 4f54f0f609
commit a950ce533e
3 changed files with 34 additions and 7 deletions

View File

@@ -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 2.006000 - 2013-03-07
[ENHANCEMENTS] [BUG FIXES]
* Documentation fixups * Documentation fixups
2.005000_004 - 2013-03-05 2.005000_004 - 2013-03-05
[ENHANCEMENTS] [BUG FIXES]
* Documentation fixups * Documentation fixups

View File

@@ -9,6 +9,20 @@ set(
'device_tabs' => [], '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 { register 'register_navbar_item' => sub {
my ($self, $config) = plugin_args(@_); 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'}); 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, 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 probably installed in your system's or user's Perl directory. It's not
recommended that you mess about with those files. recommended that you mess about with those files.
So in order to replace a template with your own version, or to reference a 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<App::Netdisco>
path. We recommend use of the L<File::ShareDir> 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 Some useful variables are made available in your templates automatically by
App::Netdisco: App::Netdisco:

1
TODO
View File

@@ -8,7 +8,6 @@ FRONTEND
* UI for topo DB table editing * UI for topo DB table editing
- drop topo file support and use DB only - drop topo file support and use DB only
* update inventory to use bootstrap accordion * update inventory to use bootstrap accordion
* UI plugins add template include path
* reports page * reports page
* reports plugin(s) * reports plugin(s)
* (jeneric) device module tab * (jeneric) device module tab