From: Matt S Trout <mst@shadowcat.co.uk>
Date: Sat, 11 Aug 2012 18:53:25 +0000 (+0000)
Subject: no_escape filter for TT
X-Git-Tag: v1.000000~14
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=51eaef0b19f5ecdb237e313c327745e879f45d28;p=scpubgit%2FHTML-String.git

no_escape filter for TT
---

diff --git a/lib/HTML/String/TT.pm b/lib/HTML/String/TT.pm
index 90b1ec5..6e35360 100644
--- a/lib/HTML/String/TT.pm
+++ b/lib/HTML/String/TT.pm
@@ -1,10 +1,13 @@
 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;
@@ -13,6 +16,11 @@ sub new {
             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]} : @_)
     );
 }
diff --git a/lib/HTML/String/Value.pm b/lib/HTML/String/Value.pm
index d622694..46181d4 100644
--- a/lib/HTML/String/Value.pm
+++ b/lib/HTML/String/Value.pm
@@ -44,7 +44,15 @@ use overload
 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;
 
diff --git a/xt/tt.t b/xt/tt.t
index b8c16e4..bd0af60 100644
--- a/xt/tt.t
+++ b/xt/tt.t
@@ -23,4 +23,9 @@ is(
     '<tag>Hi &lt;bob&gt;</tag>',
 );
 
+is(
+    do_tt('<tag>[% foo | no_escape %]</tag>', { foo => 'Hi <bob>' }),
+    '<tag>Hi <bob></tag>',
+);
+
 done_testing;