Template::Tiny support for text filtering
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / FilterBuilder / Template.pm
CommitLineData
9e219709 1package HTML::Zoom::FilterBuilder;
2
3use strict;
4use warnings FATAL => 'all';
5use Template::Tiny;
6
7sub _template_object {
8 shift->{_template_object} ||= Template::Tiny->new;
9}
10
11sub template_text {
12 my ($self, $vars) = @_;
13 my $parser = $self->_zconfig->parser;
14 my $tt = $self->_template_object;
15 $self->collect({
16 filter => sub {
17 $_->map(sub {
18 return $_ unless $_->{type} eq 'TEXT';
19 my $unescape = $parser->html_unescape($_->{raw});
20 $tt->process(\$unescape, $vars, \my $out);
21 return { %$_, raw => $parser->html_escape($out) }
22 })
23 },
24 passthrough => 1,
25 })
26}
27
28sub template_text_raw {
29 my ($self, $vars) = @_;
30 my $tt = $self->_template_object;
31 my $parser = $self->_zconfig->parser;
32 $self->collect({
33 filter => sub {
34 $_->map(sub {
35 return $_ unless $_->{type} eq 'TEXT';
36 $tt->process(\($_->{raw}), $vars, \my $out);
37 return { %$_, raw => $out }
38 })
39 },
40 passthrough => 1,
41 })
42}
43
441;