[Jifty-commit] r2418 - in jifty/branches/template-declare: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Dec 21 19:21:48 EST 2006


Author: jesse
Date: Thu Dec 21 19:21:47 2006
New Revision: 2418

Modified:
   jifty/branches/template-declare/   (props changed)
   jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm

Log:
 r46386 at 110:  jesse | 2006-12-21 16:21:33 -0800
 * Add support for sending the http header with Template::Declare


Modified: jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm	(original)
+++ jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm	Thu Dec 21 19:21:47 2006
@@ -24,23 +24,36 @@
 
 
 sub show {
-    my $self = shift;
+    my $self          = shift;
     my $code_template = shift;
 
     no warnings qw/redefine utf8/;
     local *Jifty::Web::out = sub {
-        shift;  # Remove the $self in Jifty::Web->out
+        shift;    # Turn the method into a function
+        my $r = Jifty->handler->apache;
+        unless ( $r->http_header_sent ) {
+            $r->content_type || $r->content_type('text/html; charset=utf-8');    # Set up a default
+            if ( $r->content_type =~ /charset=([\w-]+)$/ ) {
+                my $enc = $1;
+                binmode *STDOUT, ((lc($enc) =~ /utf-?8/)  ? ":utf8" : "encoding($enc)");
+            }
+            eval {
+               #HTML::Mason::FakeApache's send_http_header uses "print STDOUT"
+               # this reimplements that.
+               Template::Declare::outs( $r->http_header );
+               $r->{http_header_sent} = 1;
+            };
+        }
+
         goto &Template::Declare::Tags::outs;
     };
 
     local $Template::Declare::Tags::BUFFER = '';
-
     my $rv = Template::Declare::Tags::show($code_template);
 
     # XXX - Kluge - Before $r->send_http_headers is fixed for real, escape all non-latin1 characters.
-    print STDOUT Encode::encode(latin1 => $rv, &Encode::FB_XMLCREF)
-        unless Jifty->handler->apache->http_header_sent;
-
+    print STDOUT Encode::encode( latin1 => $rv, &Encode::FB_XMLCREF )
+    unless Jifty->handler->apache->http_header_sent;
     return undef;
 }
 


More information about the Jifty-commit mailing list