[Jifty-commit] r3173 - in jifty/trunk: lib/Jifty
lib/Jifty/View/Static
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Apr 30 09:39:26 EDT 2007
Author: jesse
Date: Mon Apr 30 09:39:25 2007
New Revision: 3173
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/lib/Jifty/Handler.pm
jifty/trunk/lib/Jifty/View/Static/Handler.pm
Log:
r56108 at pinglin: jesse | 2007-04-27 20:14:23 -0400
* More refactoring toward making view handlers plugins
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Mon Apr 30 09:39:25 2007
@@ -1127,8 +1127,8 @@
my $self = shift;
my $template = shift;
- foreach my $handler ( Jifty->handler->_template_handlers) {
- if ( Jifty->handler->$handler->template_exists($template) ) {
+ foreach my $handler ( Jifty->handler->template_handlers) {
+ if ( Jifty->handler->view($handler)->template_exists($template) ) {
return 1;
}
}
@@ -1146,21 +1146,21 @@
=cut
sub render_template {
- my $self = shift;
+ my $self = shift;
my $template = shift;
- my $showed = 0;
- eval {
- foreach my $handler (Jifty->handler->_template_handlers ) {
- if (Jifty->handler->$handler->template_exists($template) ) {
- $showed = 1;
- Jifty->handler->$handler->show($template);
- last;
- }
- }
- if (not $showed and my $fallback_handler = Jifty->handler->_fallback_template_handler) {
- Jifty->handler->$fallback_handler->show($template);
- }
-
+ my $showed = 0;
+ eval {
+ foreach my $handler ( Jifty->handler->template_handlers ) {
+ if ( Jifty->handler->view($handler)->template_exists($template) ) {
+ $showed = 1;
+ Jifty->handler->view($handler)->show($template);
+ last;
+ }
+ }
+ if ( not $showed and my $fallback_handler = Jifty->handler->_fallback_template_handler ) {
+ $fallback_handler->show($template);
+ }
+
};
my $err = $@;
@@ -1180,8 +1180,7 @@
# Redirect with a continuation
Jifty->web->_redirect( "/__jifty/error/mason_internal_error?J:C=" . $c->id );
- }
- elsif ($err) {
+ } elsif ($err) {
die $err;
}
Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/Handler.pm Mon Apr 30 09:39:25 2007
@@ -48,7 +48,13 @@
-__PACKAGE__->mk_accessors(qw(mason dispatcher declare_handler static_handler cgi apache stash));
+__PACKAGE__->mk_accessors(qw(dispatcher view_handlers cgi apache stash));
+
+sub mason {
+ my $self = shift;
+ return $self->view_handlers()->{'Jifty::View::Mason::Handler'};
+}
+
=head2 new
@@ -72,8 +78,8 @@
return $self;
}
-sub _template_handlers { qw(declare_handler mason) }
-sub _fallback_template_handler { 'mason' }
+sub template_handlers { qw(Jifty::View::Static::Handler Jifty::View::Declare::Handler Jifty::View::Mason::Handler)}
+sub _fallback_template_handler { my $self = shift; return $self->mason; }
=head2 setup_view_handlers
@@ -86,9 +92,19 @@
sub setup_view_handlers {
my $self = shift;
- $self->declare_handler( Jifty::View::Declare::Handler->new());
- $self->mason( Jifty::View::Mason::Handler->new());
- $self->static_handler(Jifty::View::Static::Handler->new());
+ $self->view_handlers({});
+ foreach my $class ($self->template_handlers()) {
+ $self->view_handlers->{$class} = $class->new();
+ }
+
+}
+
+sub view {
+ my $self = shift;
+ my $class = shift;
+
+ return $self->view_handlers->{$class};
+
}
@@ -153,30 +169,22 @@
$self->apache( HTML::Mason::FakeApache->new( cgi => $self->cgi ) );
# Build a new stash for the life of this request
- $self->stash({});
+ $self->stash( {} );
local $HTML::Mason::Commands::JiftyWeb = Jifty::Web->new();
Jifty->web->request( Jifty::Request->new()->fill( $self->cgi ) );
Jifty->web->response( Jifty::Response->new );
Jifty->api->reset;
- $_->new_request for Jifty->plugins;
-
+ for ( Jifty->plugins ) {
+ $_->new_request;
+ }
Jifty->log->debug( "Received request for " . Jifty->web->request->path );
- my $sent_response = 0;
- $sent_response
- = $self->static_handler->handle_request( Jifty->web->request->path )
- if ( Jifty->config->framework('Web')->{'ServeStaticFiles'} );
-
- Jifty->web->setup_session unless $sent_response;
+ Jifty->web->setup_session;
# Return from the continuation if need be
Jifty->web->request->return_from_continuation;
-
- unless ($sent_response) {
- Jifty->web->session->set_cookie;
- $self->dispatcher->handle_request()
- }
-
+ Jifty->web->session->set_cookie;
+ $self->dispatcher->handle_request();
$self->cleanup_request();
}
Modified: jifty/trunk/lib/Jifty/View/Static/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Static/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/View/Static/Handler.pm Mon Apr 30 09:39:25 2007
@@ -62,6 +62,10 @@
=cut
+sub show {
+ shift->handle_request(@_);
+}
+
sub handle_request {
my $self = shift;
my $path = shift;
@@ -113,6 +117,10 @@
=cut
+sub template_exists {
+ shift->file_path(@_);
+}
+
sub file_path {
my $self = shift;
my $file = shift;
More information about the Jifty-commit
mailing list