[Jifty-commit] r3471 - in jifty/trunk/lib/Jifty: View/Declare View/Mason

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jun 12 20:11:37 EDT 2007


Author: clkao
Date: Tue Jun 12 20:11:27 2007
New Revision: 3471

Modified:
   jifty/trunk/lib/Jifty/Plugin/ErrorTemplates/View.pm
   jifty/trunk/lib/Jifty/View/Declare/BaseClass.pm
   jifty/trunk/lib/Jifty/View/Declare/Helpers.pm
   jifty/trunk/lib/Jifty/View/Mason/Handler.pm

Log:
New Template::Declare page syntax for additional code block run
before wrapper, and have the returned value passed to wrapper:

template foo => 
  page { title => 'this is title', other => 'foo' }
  content {
    h1 { 'blah }
  };


Modified: jifty/trunk/lib/Jifty/Plugin/ErrorTemplates/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/ErrorTemplates/View.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/ErrorTemplates/View.pm	Tue Jun 12 20:11:27 2007
@@ -55,7 +55,7 @@
 {
     no warnings qw'redefine';
 
-    sub wrapper ($) {
+    sub wrapper {
         my $code = shift;
         html {
             head {

Modified: jifty/trunk/lib/Jifty/View/Declare/BaseClass.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/BaseClass.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Declare/BaseClass.pm	Tue Jun 12 20:11:27 2007
@@ -17,9 +17,9 @@
     my $class = shift;
     no strict 'refs';
     no warnings 'redefine';
-    *{ $class . '::wrapper' } = sub ($) {
+    *{ $class . '::wrapper' } = sub {
         my $code = shift;
-
+        my $args = shift;
         # so in td handler, we made jifty::web->out appends to td
         # buffer, we need it back for here before we call $code.
         # someday we need to finish fixing the output system that is
@@ -35,7 +35,7 @@
             $content;
         };
 
-        Jifty->handler->fallback_view_handler->show('/_elements/wrapper');
+        Jifty->handler->fallback_view_handler->show('/_elements/wrapper', $args);
     }
 }
 

Modified: jifty/trunk/lib/Jifty/View/Declare/Helpers.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/Helpers.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Declare/Helpers.pm	Tue Jun 12 20:11:27 2007
@@ -5,7 +5,7 @@
 use base qw/Template::Declare Exporter/;
 use Template::Declare::Tags;
 
-our @EXPORT = ( qw(form hyperlink tangent redirect new_action form_submit form_return  form_next_page page wrapper 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_return form_next_page page content wrapper request get set render_param current_user render_action render_region), @Template::Declare::Tags::EXPORT);
 
 =head1 NAME
 
@@ -264,27 +264,44 @@
 
  template 'foo' => page {{ title is 'Foo' } ... };
 
+  or
+
+ template 'foo' => page { title => 'Foo' } content { ... };
+
 Renders an HTML page wrapped in L</wrapper>, after calling
 "/_elements/nav" and setting a content type. Generally, you shouldn't
 be using "/_elements/nav" but a Dispatcher rule instead.
 
+If C<page/content> calling convention is used, the return value of the
+first sub will be passed into wrapper as the second argument as a
+hashref, as well as the last argument for the content sub.
+
 =cut
 
-sub page (&) {
-    my $code = shift;
+sub page (&;$) {
+    unshift @_, undef if $#_ == 0;
+    my ( $meta, $code ) = @_;
     sub {
         my $self = shift;
         Jifty->handler->apache->content_type('text/html; charset=utf-8');
-        if ( my $wrapper = Jifty->app_class('View')->can('wrapper') ) {
-            $wrapper->(sub { $code->($self)});
-        } else {
-
-        wrapper(sub { $code->($self) });
+        my $wrapper = Jifty->app_class('View')->can('wrapper') || \&wrapper;
+        my @metadata = $meta ? $meta->() : ();
+        my $metadata = $#metadata == 0 ? $metadata[0] : {@metadata};
+        local *is::title = sub { warn "Can't use 'title is' when mixing mason and TD" };
+        $wrapper->( sub { $code->( $self, $metadata ) }, $metadata );
     }
-    };
 }
 
+=head2 content
 
+Helper function for page { ... } content { ... }
+
+=cut
+
+sub content (&;$) {
+    # XXX: Check for only 1 arg
+    return $_[0];
+}
 
 =head2 wrapper $coderef
 
@@ -293,7 +310,7 @@
 
 =cut
 
-sub wrapper ($) {
+sub wrapper {
     my $app_class = get_current_attr('PageClass') || 'View::Page';
     delete $Template::Declare::Tags::ATTRIBUTES{ 'PageClass' };
 

Modified: jifty/trunk/lib/Jifty/View/Mason/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Mason/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Mason/Handler.pm	Tue Jun 12 20:11:27 2007
@@ -183,13 +183,13 @@
 }
 
 sub handle_comp {
-    my ($self, $comp) = (shift, shift);
+    my ($self, $comp, $args) = @_;
 
     # Set up the global
     my $r = Jifty->handler->apache;
     $self->interp->set_global('$r', $r);
 
-    my %args = $self->request_args($r);
+    my %args = $args ? %$args : $self->request_args($r);
 
     my @result;
     if (wantarray) {


More information about the Jifty-commit mailing list