package HTML::String::TT;
use strictures 1;
+
+use HTML::String;
+use HTML::String::TT::Directive;
+use Safe::Isa;
use Template;
use Template::Parser;
use Template::Stash;
-use HTML::String::TT::Directive;
sub new {
shift;
FACTORY => 'HTML::String::TT::Directive'
),
STASH => Template::Stash->new,
+ FILTERS => { no_escape => sub {
+ $_[0]->$_isa('HTML::String::Value')
+ ? HTML::String::Value->new(map $_->[0], @{$_[0]->{parts}})
+ : HTML::String::Value->new($_)
+ } },
(ref($_[0]) eq 'HASH' ? %{$_[0]} : @_)
);
}
sub new {
my ($class, @raw_parts) = @_;
- my @parts = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @raw_parts;
+ my @parts = map {
+ if (ref($_) eq 'ARRAY') {
+ $_
+ } elsif ($_->$_isa(__PACKAGE__)) {
+ @{$_->{parts}}
+ } else {
+ [ $_, 0 ]
+ }
+ } @raw_parts;
my $self = bless { parts => \@parts }, $class;
'<tag>Hi <bob></tag>',
);
+is(
+ do_tt('<tag>[% foo | no_escape %]</tag>', { foo => 'Hi <bob>' }),
+ '<tag>Hi <bob></tag>',
+);
+
done_testing;