root/trunk/plagger/lib/Plagger/Template.pm

Revision 1638 (checked in by mark, 14 years ago)

r4@travis: mark | 2006-09-01 17:57:02 +0100
attempt at adding a little more documentation

  • Property svn:keywords set to Id Revision
Line 
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     return $class->SUPER::new({
23         INCLUDE_PATH => $paths,
24         LOAD_TEMPLATES => [
25             Template::Provider::Encoding->new({ INCLUDE_PATH => $paths }),
26         ],
27         STASH => Template::Stash::ForceUTF8->new,
28         PLUGIN_BASE => [ 'Plagger::TT' ],
29     });
30 }
31
32 1;
33
34 __END__
35
36
37 =head1 NAME
38
39 Plagger::Template - Template Toolkit subclass for Plagger
40
41 =head1 SYNOPSIS
42
43   From within a plagger plugin
44   $self->templatize($file, $vars);
45
46 =head1 DESCRIPTION
47
48 A subclass of Template Toolkit that's used by the Plagger plugins.
49 As a plugin author, you really don't have to worry about this.  See the
50 documentation for Plagger::Pluggin's templatize method instead.
51
52 The plugin calls the custom new routine like so:
53
54   Plagger::Template->new($plagger_context, $self);
55
56 Essentially this subclass uses this to know where the templates are
57 from the assests path.
58
59 It also does the right thing with encodings and utf8.
60
61 =head1 AUTHOR
62
63 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
64
65 See I<AUTHORS> file for the name of all the contributors.
66
67 =head1 LICENSE
68
69 Except where otherwise noted, Plagger is free software; you can
70 redistribute it and/or modify it under the same terms as Perl itself.
71
72 =head1 SEE ALSO
73
74 L<http://plagger.org/>, L<Template>, L<http://tt2.org/>
75
76 =cut
Note: See TracBrowser for help on using the browser.