/
TT.pm
41 lines (35 loc) · 1011 Bytes
/
TT.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Kamui::View::TT;
use Kamui;
use base 'Kamui::View';
use Template;
use File::Spec;
use Template::Stash::EscapeHTML;
use Encode;
sub render {
my ($class, $context) = @_;
my $template = $context->load_template || $context->guess_filename;
my $tt = Template->new(
ABSOLUTE => 1,
RELATIVE => 1,
ENCODING => 'utf-8',
STASH => Template::Stash::EscapeHTML->new,
FILTERS => $context->conf->{view}->{tt}->{filters},
COMPILE_DIR => '/tmp/' . $ENV{USER} . "/",
INCLUDE_PATH => [ '.', File::Spec->catfile($context->conf->{view}->{tt}->{path}) ],
%{ $context->conf->{view}->{tt}->{options} || {} },
);
$tt->process(
$template,
{
%{ $context->stash },
c => $context,
},
\my $output
) or die $@;
my $res = $context->res;
$res->status('200');
$res->body($output);
$res->headers([ 'Content-Type' => 'text/html' ]);
$res;
}
1;