Plagger::Template - Template Toolkit subclass for Plagger


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Template - Template Toolkit subclass for Plagger

SYNOPSIS

Top

  From within a plagger plugin
  $self->templatize($file, $vars);

DESCRIPTION

Top

A subclass of Template Toolkit that's used by the Plagger plugins. As a plugin author, you really don't have to worry about this. See the documentation for Plagger::Pluggin's templatize method instead.

The plugin calls the custom new routine like so:

  Plagger::Template->new($plagger_context, $self);

Essentially this subclass uses this to know where the templates are from the assets path.

It also does the right thing with encodings and utf8.

AUTHOR

Top

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

See AUTHORS file for the name of all the contributors.

LICENSE

Top

Except where otherwise noted, Plagger is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top

http://plagger.org/, Template, http://tt2.org/


Plagger documentation Contained in the Plagger distribution.

package Plagger::Template;
use strict;
use base qw( Template );

use FindBin;
use File::Spec::Functions qw(catfile);

use Template::Provider::Encoding 0.04;
use Template::Stash::ForceUTF8;

sub new {
    my($class, $context, $plugin) = @_;

    my $path = $context->conf->{assets_path} || catfile($FindBin::Bin, "assets");
    my $paths = [ catfile($path, "plugins", $plugin->class_id),
                  catfile($path, "common") ];

    if ($plugin->conf->{assets_path}) {
        unshift @$paths, $plugin->conf->{assets_path};
    }

    $context->log(debug => "Assets path: " . join(":", @$paths));

    return $class->SUPER::new({
        INCLUDE_PATH => $paths,
        LOAD_TEMPLATES => [
            Template::Provider::Encoding->new({ INCLUDE_PATH => $paths }),
        ],
        STASH => Template::Stash::ForceUTF8->new,
        PLUGIN_BASE => [ 'Plagger::TT' ],
    });
}

1;

__END__