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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/usr/bin/perl
use warnings;
use strict;
use Template;
use Test::More;
plan tests => 3;
my $tt = Template->new();
# Make sure that normal TT processing works ...
my $template;
$template = <<'EOTEMPLATE';
hello, world
EOTEMPLATE
my $output;
$tt->process(\$template, undef, \$output);
is($template, $output, 'Basic template processing');
# Now use a [% FILTER ... %] block to run the filter ...
$template = <<'EOTEMPLATE';
[%- USE e = Clickable::Email -%]
[%- FILTER $e -%]
text nik@FreeBSD.org text
[% END -%]
EOTEMPLATE
my $expected_output = <<'EOT';
text <a href="mailto:nik@FreeBSD.org">nik@FreeBSD.org</a> text
EOT
$output = '';
$tt->process(\$template, undef, \$output);
is($output, $expected_output, 'Works in [% FILTER ... %] block');
# Now try and use the filter 'inline' ...
$template = <<'EOTEMPLATE';
[%- USE e = Clickable::Email -%]
[% text | $e %]
EOTEMPLATE
$output = '';
$tt->process(\$template, { text => 'text nik@FreeBSD.org text' }, \$output);
is($output, $expected_output, 'Works inline');
|