[Jifty-commit] r618 - in jifty/trunk: lib/Jifty lib/Jifty/Web
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Feb 22 17:12:20 EST 2006
Author: alexmv
Date: Wed Feb 22 17:12:18 2006
New Revision: 618
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/lib/Jifty/Web/PageRegion.pm
Log:
r9235 at zoq-fot-pik: chmrr | 2006-02-22 17:10:08 -0500
* Make Jifty->web->region simply do a -new, ->enter, ->render, ->exit
on the page region; this involves moving some of the processing into
->enter. The reason for this is so we can enter a region, and thus
reference it using current_region, and have it have a qualified name
that we can refer to. We can then refer to it (using submit buttons
and the like) and then render it by hand.
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Wed Feb 22 17:12:18 2006
@@ -17,8 +17,6 @@
use XML::Writer;
use base qw/Class::Accessor Jifty::Object/;
-use UNIVERSAL::require;
-
use vars qw/$SERIAL/;
__PACKAGE__->mk_accessors(
@@ -35,7 +33,7 @@
sub new {
my $class = shift;
- my $self = bless {}, $class;
+ my $self = bless {region_stack => []}, $class;
$self->session(Jifty::Web::Session->new());
return ($self);
}
@@ -1022,8 +1020,9 @@
Creates and renders a L<Jifty::Web::PageRegion>; the C<PARAMHASH> is
passed directly to its L<Jifty::Web::PageRegion/new> method. The
-region is then added to the stack of regions, and the fragment is
-rendered.
+region is then L<Jifty::Web::PageRegion/enter>ed, then
+L<Jifty::Web::PageRegion/render>ed, and finally
+L<Jifty::Web::PageRegion/exit>ed.
=cut
@@ -1032,19 +1031,16 @@
# Add ourselves to the region stack
my $region = Jifty::Web::PageRegion->new(@_) or return;
- $region->parent(Jifty->web->current_region);
- local $self->{'region_stack'}
- = [ @{ $self->{'region_stack'} || [] }, $region ];
- $region->enter;
- # Keep track of the fully qualified name (which should be unique)
- warn "Repeated region: " . $self->qualified_region
- if $self->{'regions'}{ $self->qualified_region };
- $self->{'regions'}{ $self->qualified_region } = $region;
+ # Enter the region
+ $region->enter;
# Render it
$self->out( $region->render );
+ # Exit it when we're done
+ $region->exit;
+
"";
}
@@ -1105,7 +1101,6 @@
parent => Jifty->web->current_region,
defaults => $f->arguments,
);
- push @{ Jifty->web->{'region_stack'} }, $new;
$new->enter;
}
@@ -1113,6 +1108,8 @@
$writer->startTag( "fragment", id => Jifty->web->current_region->qualified_name );
$writer->cdata( Jifty->web->current_region->render );
$writer->endTag();
+
+ Jifty->web->current_region->exit while Jifty->web->current_region;
}
$writer->endTag();
Modified: jifty/trunk/lib/Jifty/Web/PageRegion.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/PageRegion.pm (original)
+++ jifty/trunk/lib/Jifty/Web/PageRegion.pm Wed Feb 22 17:12:18 2006
@@ -180,8 +180,18 @@
sub enter {
my $self = shift;
+ $self->log->warn("Region occurred in more than once place: ".$self->qualified_name)
+ if (defined $self->parent and $self->parent != Jifty->web->current_region);
+
+ $self->parent(Jifty->web->current_region);
+ push @{Jifty->web->{'region_stack'}}, $self;
$self->qualified_name(Jifty->web->qualified_region);
+ # Keep track of the fully qualified name (which should be unique)
+ $self->log->warn("Repeated region: " . $self->qualified_name)
+ if Jifty->web->{'regions'}{ $self->qualified_name };
+ Jifty->web->{'regions'}{ $self->qualified_name } = $self;
+
# Merge in the settings passed in via state variables
for (Jifty->web->request->state_variables) {
if ($_->key =~ /^region-(.*?)\.(.*)/ and $1 eq $self->qualified_name and $_->value ne $self->default_argument($2)) {
@@ -195,6 +205,20 @@
}
}
+=head2 exit
+
+=cut
+
+sub exit {
+ my $self = shift;
+
+ if (Jifty->web->current_region != $self) {
+ $self->log->warn("Attempted to exit page region ".$self->qualified_name." when it wasn't the most recent");
+ } else {
+ pop @{Jifty->web->{'region_stack'}};
+ }
+}
+
=head2 render
Returns a string of the fragment and associated javascript.
More information about the Jifty-commit
mailing list