[Jifty-commit] r2761 - jifty/branches/template-declare/lib/Jifty/View/Declare

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Feb 7 23:45:53 EST 2007


Author: audreyt
Date: Wed Feb  7 23:45:53 2007
New Revision: 2761

Modified:
   jifty/branches/template-declare/lib/Jifty/View/Declare/CoreTemplates.pm
   jifty/branches/template-declare/lib/Jifty/View/Declare/Helpers.pm

Log:
* Move page/wrapper/render_header from CoreTemplates to Helpers.

Modified: jifty/branches/template-declare/lib/Jifty/View/Declare/CoreTemplates.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/View/Declare/CoreTemplates.pm	(original)
+++ jifty/branches/template-declare/lib/Jifty/View/Declare/CoreTemplates.pm	Wed Feb  7 23:45:53 2007
@@ -8,16 +8,6 @@
 
 use Scalar::Defer;
 
-# template 'foo' => page {{ title is 'Foo' } ... };
-sub page (&) {
-    my $code = shift;
-    sub {
-        Jifty->handler->apache->content_type('text/html; charset=utf-8');
-        show('/_elements/nav');
-        wrapper($code);
-    };
-}
-
 template '_elements/nav' => sub {
     my $top = Jifty->web->navigation;
     $top->child( Home => url => "/", sort_order => 1 );
@@ -37,95 +27,6 @@
     return ();
 };
 
-sub render_header {
-    my ($title) = @_;
-    outs_raw('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
-            . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' );
-    with( title => $title ), show('/_elements/header');
-    div {
-        { id is 'headers' }
-        hyperlink(
-            url   => "/",
-            label => _( Jifty->config->framework('ApplicationName') )
-        );
-        with( class => "title" ), h1 { $title };
-    };
-}
-
-
-sub wrapper (&) {
-    my $content_code = shift;
-
-    my ($title) = get_current_attr(qw(title));
-
-    my $done_header;
-    my $render_header = sub {
-        no warnings qw( uninitialized redefine once );
-
-        defined $title or return;
-        return if $done_header++;
-
-        Template::Declare->new_buffer_frame;
-        render_header($title);
-        $done_header = Template::Declare->buffer->data;
-        Template::Declare->end_buffer_frame;
-
-
-        '';
-    };
-
-    body {
-        show('/_elements/sidebar');
-        with( id => "content" ), div {
-            with( name => 'content' ), a {};
-            if ( Jifty->config->framework('AdminMode') ) {
-                with( class => "warning admin_mode" ), div {
-                    outs( _('Alert') . ': ' );
-                    outs_raw(
-                        Jifty->web->tangent(
-                            label => _('Administration mode is enabled.'),
-                            url   => '/__jifty/admin/'
-                        )
-                    );
-                  }
-            }
-            Jifty->web->render_messages;
-
-            {
-                no warnings qw( uninitialized redefine once );
-
-                local *is::title = sub {
-                    shift;
-                    $title = "@_";
-                    &$render_header;
-                };
-
-                &$content_code;
-                if ( !$done_header ) {
-                    $title = _("Untitled");
-                    &$render_header;
-                }
-            }
-
-            show('/_elements/keybindings');
-            with( id => "jifty-wait-message", style => "display: none" ),
-              div { _('Loading...') };
-
-# Jifty::Mason::Halo->render_component_tree if ( Jifty->config->framework('DevelMode') );
-
-            # This is required for jifty server push.  If you maintain your own
-            # wrapper, make sure you have this as well.
-            if (   Jifty->config->framework('PubSub')->{'Enable'}
-                && Jifty::Subs->list )
-            {
-                script { outs('new Jifty.Subs({}).start();') };
-            }
-        };
-    };
-
-        Template::Declare->buffer->data( $done_header . Template::Declare->buffer->data);
-}
-
 template '_elements/sidebar' => sub {
     with( id => "salutation" ), div {
         if (    Jifty->web->current_user->id

Modified: jifty/branches/template-declare/lib/Jifty/View/Declare/Helpers.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/View/Declare/Helpers.pm	(original)
+++ jifty/branches/template-declare/lib/Jifty/View/Declare/Helpers.pm	Wed Feb  7 23:45:53 2007
@@ -6,7 +6,7 @@
 use Template::Declare::Tags;
 
 use base qw/Template::Declare/;
-our @EXPORT = (qw(form hyperlink tangent redirect new_action form_submit form_next_page request get set render_param current_user render_action render_region ), @Template::Declare::Tags::EXPORT);
+our @EXPORT = (qw(form hyperlink tangent redirect new_action form_submit form_next_page page wrapper request get set render_param current_user render_action render_region ), @Template::Declare::Tags::EXPORT);
 
 {
 no warnings qw/redefine/;
@@ -94,4 +94,104 @@
     return '';
 }
 
+# template 'foo' => page {{ title is 'Foo' } ... };
+sub page (&) {
+    my $code = shift;
+    sub {
+        Jifty->handler->apache->content_type('text/html; charset=utf-8');
+        show('/_elements/nav');
+        wrapper($code);
+    };
+}
+
+
+sub wrapper (&) {
+    my $content_code = shift;
+
+    my ($title) = get_current_attr(qw(title));
+
+    my $done_header;
+    my $render_header = sub {
+        no warnings qw( uninitialized redefine once );
+
+        defined $title or return;
+        return if $done_header++;
+
+        Template::Declare->new_buffer_frame;
+        render_header($title);
+        $done_header = Template::Declare->buffer->data;
+        Template::Declare->end_buffer_frame;
+
+
+        '';
+    };
+
+    body {
+        show('/_elements/sidebar');
+        with( id => "content" ), div {
+            with( name => 'content' ), a {};
+            if ( Jifty->config->framework('AdminMode') ) {
+                with( class => "warning admin_mode" ), div {
+                    outs( _('Alert') . ': ' );
+                    outs_raw(
+                        Jifty->web->tangent(
+                            label => _('Administration mode is enabled.'),
+                            url   => '/__jifty/admin/'
+                        )
+                    );
+                  }
+            }
+            Jifty->web->render_messages;
+
+            {
+                no warnings qw( uninitialized redefine once );
+
+                local *is::title = sub {
+                    shift;
+                    $title = "@_";
+                    &$render_header;
+                };
+
+                &$content_code;
+                if ( !$done_header ) {
+                    $title = _("Untitled");
+                    &$render_header;
+                }
+            }
+
+            show('/_elements/keybindings');
+            with( id => "jifty-wait-message", style => "display: none" ),
+              div { _('Loading...') };
+
+# Jifty::Mason::Halo->render_component_tree if ( Jifty->config->framework('DevelMode') );
+
+            # This is required for jifty server push.  If you maintain your own
+            # wrapper, make sure you have this as well.
+            if (   Jifty->config->framework('PubSub')->{'Enable'}
+                && Jifty::Subs->list )
+            {
+                script { outs('new Jifty.Subs({}).start();') };
+            }
+        };
+    };
+
+        Template::Declare->buffer->data( $done_header . Template::Declare->buffer->data);
+}
+
+sub render_header {
+    my ($title) = @_;
+    outs_raw('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+            . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' );
+    with( title => $title ), show('/_elements/header');
+    div {
+        { id is 'headers' }
+        hyperlink(
+            url   => "/",
+            label => _( Jifty->config->framework('ApplicationName') )
+        );
+        with( class => "title" ), h1 { $title };
+    };
+}
+
+
 1;


More information about the Jifty-commit mailing list