[Jifty-commit] r2402 - in jifty/branches/template-declare: .
lib/Jifty lib/Jifty/Action/Record
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Dec 19 00:14:21 EST 2006
Author: jesse
Date: Tue Dec 19 00:14:17 2006
New Revision: 2402
Modified:
jifty/branches/template-declare/ (props changed)
jifty/branches/template-declare/lib/Jifty/Action/Record/Create.pm
jifty/branches/template-declare/lib/Jifty/Dispatcher.pm
jifty/branches/template-declare/lib/Jifty/Handler.pm
jifty/branches/template-declare/lib/Jifty/Plugin.pm
jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm
Log:
r46257 at pinglin: jesse | 2006-12-18 19:47:41 -0500
* Initial port to new Template::Declare API
Modified: jifty/branches/template-declare/lib/Jifty/Action/Record/Create.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Action/Record/Create.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Action/Record/Create.pm Tue Dec 19 00:14:17 2006
@@ -78,7 +78,7 @@
}
if (! $record->id ) {
- $self->log->debug(_("Create of %1 failed: %2", ref($record), $msg));
+ $self->log->warn(_("Create of %1 failed: %2", ref($record), $msg));
$self->result->error($msg || _("An error occurred. Try again later"));
}
Modified: jifty/branches/template-declare/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Dispatcher.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Dispatcher.pm Tue Dec 19 00:14:17 2006
@@ -1130,12 +1130,9 @@
my $self = shift;
my $template = shift;
- $self->log->debug( "Handling template " . $template );
eval {
my( $class,$codetemplate) = Jifty->handler->declare_handler->resolve_template($template);
if ($class and $codetemplate) {
- Jifty->log->debug( "Got $class, $template" );
-
Jifty->handler->declare_handler->show($class => $codetemplate);
} else {
Jifty->handler->mason->handle_comp( $template );
@@ -1159,8 +1156,7 @@
warn "$err";
# Redirect with a continuation
- Jifty->web->_redirect(
- "/__jifty/error/mason_internal_error?J:C=" . $c->id );
+ Jifty->web->_redirect( "/__jifty/error/mason_internal_error?J:C=" . $c->id );
}
elsif ($err) {
die $err;
Modified: jifty/branches/template-declare/lib/Jifty/Handler.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Handler.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Handler.pm Tue Dec 19 00:14:17 2006
@@ -62,25 +62,29 @@
bless $self, $class;
$self->create_cache_directories();
-# wrap 'CGI::new', pre => sub {
-# $_[-1] = Jifty->handler->cgi if Jifty->handler->cgi;
-# };
$self->dispatcher( Jifty->app_class( "Dispatcher" ) );
Jifty::Util->require( $self->dispatcher );
$self->dispatcher->import_plugins;
- $self->dispatcher->dump_rules;
-
- $self->declare_handler(
- Jifty::View::Declare::Handler->new(
- { root_class => Jifty->config->framework('TemplateClass') }
- )
- );
- $self->mason( Jifty::View::Mason::Handler->new( $self->mason_config ) );
+
+ $self->setup_view_handlers();
+ return $self;
+}
- $self->static_handler(Jifty::View::Static::Handler->new());
+=head2 setup_view_handlers
- return $self;
+Initialize all of our view handlers.
+
+XXX TODO: this should take pluggable views
+
+=cut
+
+sub setup_view_handlers {
+ my $self = shift;
+
+ $self->declare_handler( Jifty::View::Declare::Handler->new( $self->templatedeclare_config));
+ $self->mason( Jifty::View::Mason::Handler->new( $self->mason_config ) );
+ $self->static_handler(Jifty::View::Static::Handler->new());
}
@@ -127,7 +131,6 @@
],
comp_root => [
[application => Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} )],
- [jifty => Jifty->config->framework('Web')->{'DefaultTemplateRoot'}],
],
%{ Jifty->config->framework('Web')->{'MasonConfig'} },
);
@@ -137,6 +140,7 @@
next unless $comp_root;
push @{ $config{comp_root} }, [ ref($plugin)."-".Jifty->web->serial => $comp_root ];
}
+ push @{$config{comp_root}}, [jifty => Jifty->config->framework('Web')->{'DefaultTemplateRoot'}];
# In developer mode, we want halos, refreshing and all that other good stuff.
if (Jifty->config->framework('DevelMode') ) {
@@ -144,10 +148,32 @@
$config{static_source} = 0;
$config{use_object_files} = 0;
}
- return (%config);
+ return %config;
}
+
+=head2 templatedeclare_config
+
+=cut
+
+sub templatedeclare_config {
+ my %config = (
+ roots => [ Jifty->config->framework('TemplateClass') ],
+ %{ Jifty->config->framework('Web')->{'TemplateDeclareConfig'} ||{}},
+ );
+
+ for my $plugin ( Jifty->plugins ) {
+ my $comp_root = $plugin->template_class;
+ next unless $comp_root;
+ push @{ $config{roots} }, $comp_root ;
+ }
+
+ push @{$config{roots}}, 'Jifty::View::Declare::Base';
+
+ return %config;
+}
+
=head2 cgi
Returns the L<CGI> object for the current request, or C<undef> if
Modified: jifty/branches/template-declare/lib/Jifty/Plugin.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Plugin.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Plugin.pm Tue Dec 19 00:14:17 2006
@@ -55,11 +55,8 @@
Jifty::Util->require($class->dispatcher);
# Start a plugin classloader set up on behalf of the application
- require Jifty::Plugin::ClassLoader;
- Jifty::Plugin::ClassLoader->new(
- base => Jifty->app_class,
- plugin => $class,
- )->require;
+ Jifty::Util->require('Jifty::Plugin::ClassLoader');
+ Jifty::Plugin::ClassLoader->new( base => Jifty->app_class, plugin => $class,)->require;
# XXX TODO: Add .po path
@@ -96,7 +93,7 @@
=head2 template_root
-Returns the root of the template directory for this plugin
+Returns the root of the C<HTML::Mason> template directory for this plugin
=cut
@@ -111,6 +108,20 @@
return $self->{share}."/web/templates";
}
+
+=head2 template_class
+
+Returns the Template::Declare view package for this plugin
+
+=cut
+
+sub template_class {
+ my $self = shift;
+ my $class = ref($self) || $self;
+ return $class.'::View';
+}
+
+
=head2 static_root
Returns the root of the static directory for this plugin
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 Tue Dec 19 00:14:17 2006
@@ -4,6 +4,8 @@
use strict;
use base qw/Jifty::Object Class::Accessor/;
+use Template::Declare;
+
__PACKAGE__->mk_accessors(qw/root_class/);
@@ -11,6 +13,16 @@
=cut
+
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self,$class;
+ Template::Declare->init(@_);
+ return $self;
+}
+
+
sub show {
my $self = shift;
my $package = shift;
@@ -33,65 +45,6 @@
return undef;
}
-=head2 resolve_template template_path
-
-Takes the path of a template
-to resolve. Checks to make sure it's a valid template, resolves the
-template name and package to an exact package and the name of the
-template within that package. Returns undef if it can't resolve the
-template.
-
-
-
-For example:
-
- admin/users/new
-
-would become
-
- Wifty::View::admin::users, new
-
-
-=cut
-
-
-sub resolve_template {
- my $self = shift;
- my $template_name = shift; # like /admin/ui/new
-
- my @components = split( '/', $template_name );
- my $template = pop @components;
- my $package;
-
- REQUIRE_PACKAGE: {
- $package = join('::', $self->root_class, grep { $_ } @components);
- $package->require;
-
- if ($UNIVERSAL::require::ERROR =~ /^Can't locate/) {
- $self->log->debug($UNIVERSAL::require::ERROR);
-
- # It's possible that /admin/ui/new is defined in admin, instead of admin::ui
- if (@components) {
- $template = pop(@components) . '/' . $template;
- redo REQUIRE_PACKAGE;
- }
-
- return undef;
- }
- }
-
- unless ( $package->isa('Jifty::View::Declare::Templates') ) {
- $self->log->error( "$package (" . $self->root_class . " / $template_name) isn't a valid template package." );
- return undef;
- }
-
- if ( $package->can('has_template') and my $code_template = $package->has_template($template) ) {
- return ( $package, $code_template );
- }
- else {
- $self->log->warn("$package has no template $template.");
- return undef;
- }
-}
+sub resolve_template { return Template::Declare->resolve_template(@_);}
1;
More information about the Jifty-commit
mailing list