| 1 | package Plagger::Template; | ||
| 2 | use strict; | ||
| 3 | use base qw( Template ); | ||
| 4 | |||
| 5 | use FindBin; | ||
| 6 | use File::Spec::Functions qw(catfile); | ||
| 7 | |||
| 8 | use Template::Provider::Encoding 0.04; | ||
| 9 | use Template::Stash::ForceUTF8; | ||
| 10 | |||
| 11 | sub new { | ||
| 12 | my($class, $context, $plugin) = @_; | ||
| 13 | |||
| 14 | my $path = $context->conf->{assets_path} || catfile($FindBin::Bin, "assets"); | ||
| 15 | my $paths = [ catfile($path, "plugins", $plugin->class_id), | ||
| 16 | catfile($path, "common") ]; | ||
| 17 | |||
| 18 | if ($plugin->conf->{assets_path}) { | ||
| 19 | unshift @$paths, $plugin->conf->{assets_path}; | ||
| 20 | } | ||
| 21 | |||
| 22 | $context->log(debug => "Assets path: " . join(":", @$paths)); | ||
| 23 | |||
| 24 | return $class->SUPER::new({ | ||
| 25 | INCLUDE_PATH => $paths, | ||
| 26 | LOAD_TEMPLATES => [ | ||
| 27 | Template::Provider::Encoding->new({ INCLUDE_PATH => $paths }), | ||
| 28 | ], | ||
| 29 | STASH => Template::Stash::ForceUTF8->new, | ||
| 30 | PLUGIN_BASE => [ 'Plagger::TT' ], | ||
| 31 | }); | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; | ||
| 35 | |||
| 36 | __END__ |