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