Egg::View::TT - View for TemplateToolKit.


Egg-View-TT documentation Contained in the Egg-View-TT distribution.

Index


Code Index:

NAME

Top

Egg::View::TT - View for TemplateToolKit.

SYNOPSIS

Top

  __PACKAGE__->egg_startup(
   ...
   .....
   VIEW=> [
    [ 'TT' => {
     INCLUDE_PATH=> ['/path/to/root'],
      } ],
    ],

   );

  # The VIEW object is acquired.
  my $view= $e->view('TT');

  # It outputs it specifying the template.
  my $content= $view->render('hoge.tt', \%option);

DESCRIPTION

Top

It is a view for TemplateToolKit.

http://www.template-toolkit.org/

Please add TT to the setting of VIEW to make it use.

   VIEW=> [
    [ 'TT' => { ... TemplateToolKit option. (HASH) }
    ],

The object that can be used is as follows from the template.

  e ... Object of project.
  s ... $e->stash
  p ... $e->view('TT')->params

HANDLER METHODS

Top

Egg::View has been succeeded to.

new

Constructor.

Egg::View::Template::GlobalParam is set up.

  my $view= $e->view('TT');

render ([TEMPLATE_STR], [OPTION])

The result of evaluating the template of TEMPLATE_STR with TemplateToolKit is returned by the SCALAR reference.

OPTION is an option to pass to TemplateToolKit. OPTION overwrites a set value of the configuration.

  my $body= $view->render( 'foo.tt', 
    ..........
    ....
    );

output ([TEMPLATE], [OPTION])

The result of the render method is set in $e->response->body.

When TEMPLATE is omitted, it acquires it from $view->template.

OPTION is passed to the render method as it is.

  $view->output;

SEE ALSO

Top

Egg::Release, Egg::View, Egg::View::Template::GlobalParam, Template, http://www.template-toolkit.org/,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-View-TT documentation Contained in the Egg-View-TT distribution.

package Egg::View::TT;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: TT.pm 237 2008-02-03 13:42:55Z lushe $
#
use strict;
use warnings;

our $VERSION = '3.01';

sub _setup {
	my($class, $e)= @_;
	my $c= "$e->{namespace}::View::TT"->config;
	$c->{ABSOLUTE}= 1 unless exists($c->{ABSOLUTE});
	$c->{RELATIVE}= 1 unless exists($c->{RELATIVE});
	$c->{INCLUDE_PATH} ||= [ $e->config->{dir}{template} ];
	$c->{TEMPLATE_EXTENSION} ||= '.'. $e->config->{template_extention};
	$class->next::method($e);
}

package Egg::View::TT::handler;
use strict;
use warnings;
use Carp qw/ croak /;
use base qw/ Egg::View /;
use Template;
use Egg::View::Template::GlobalParam;

sub new {
	my $view= shift->SUPER::new(@_);
	$view->params({ Egg::View::Template::GlobalParam::set($view->e) });
	$view;
}
sub render {
	my $view= shift;
	my $tmpl= shift || return (undef);
	my $tt= do {
		my $class= $view->e->namespace. '::View::TT';
		my %option= (
		  %{ $class->config },
		  %{ $_[0] ? ($_[1] ? {@_}: $_[0]): {} },
		  );
		if ($option{TIMER}) {
			require Template::Timer;
			$option{CONTEXT}= Template::Timer->new(%option);
		}
		Template->new(\%option) || die Template->error;
	  };
	my $body;
	$tt->process($tmpl, {
	  e => $view->{e},
	  s => $view->{e}->stash,
	  p => $view->params,
	  }, \$body) || die $tt->error;
	\$body;
}
sub output {
	my $view= shift;
	my $tmpl= shift || $view->template || croak q{ I want template. };
	$view->e->response->body( $view->render($tmpl, @_) );
}

1;

__END__