| 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__ |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
=head1 NAME |
|---|
| 40 |
|
|---|
| 41 |
Plagger::Template - Template Toolkit subclass for Plagger |
|---|
| 42 |
|
|---|
| 43 |
=head1 SYNOPSIS |
|---|
| 44 |
|
|---|
| 45 |
From within a plagger plugin |
|---|
| 46 |
$self->templatize($file, $vars); |
|---|
| 47 |
|
|---|
| 48 |
=head1 DESCRIPTION |
|---|
| 49 |
|
|---|
| 50 |
A subclass of Template Toolkit that's used by the Plagger plugins. |
|---|
| 51 |
As a plugin author, you really don't have to worry about this. See the |
|---|
| 52 |
documentation for Plagger::Pluggin's templatize method instead. |
|---|
| 53 |
|
|---|
| 54 |
The plugin calls the custom new routine like so: |
|---|
| 55 |
|
|---|
| 56 |
Plagger::Template->new($plagger_context, $self); |
|---|
| 57 |
|
|---|
| 58 |
Essentially this subclass uses this to know where the templates are |
|---|
| 59 |
from the assets path. |
|---|
| 60 |
|
|---|
| 61 |
It also does the right thing with encodings and utf8. |
|---|
| 62 |
|
|---|
| 63 |
=head1 AUTHOR |
|---|
| 64 |
|
|---|
| 65 |
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> |
|---|
| 66 |
|
|---|
| 67 |
See I<AUTHORS> file for the name of all the contributors. |
|---|
| 68 |
|
|---|
| 69 |
=head1 LICENSE |
|---|
| 70 |
|
|---|
| 71 |
Except where otherwise noted, Plagger is free software; you can |
|---|
| 72 |
redistribute it and/or modify it under the same terms as Perl itself. |
|---|
| 73 |
|
|---|
| 74 |
=head1 SEE ALSO |
|---|
| 75 |
|
|---|
| 76 |
L<http://plagger.org/>, L<Template>, L<http://tt2.org/> |
|---|
| 77 |
|
|---|
| 78 |
=cut |
|---|