[Jifty-commit] r2121 - in jifty/branches/template-declare: .
examples/HelloKitty examples/HelloKitty/bin
examples/HelloKitty/etc examples/HelloKitty/lib
examples/HelloKitty/lib/HelloKitty
examples/HelloKitty/lib/HelloKitty/Action
examples/HelloKitty/lib/HelloKitty/Model
examples/HelloKitty/log examples/HelloKitty/share
examples/HelloKitty/share/po examples/HelloKitty/share/web
examples/HelloKitty/share/web/static
examples/HelloKitty/share/web/templates examples/HelloKitty/t
examples/HelloKitty/var examples/HelloKitty/var/mason
lib/Jifty lib/Jifty/View/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Nov 9 00:51:55 EST 2006
Author: jesse
Date: Thu Nov 9 00:51:54 2006
New Revision: 2121
Added:
jifty/branches/template-declare/examples/HelloKitty/
jifty/branches/template-declare/examples/HelloKitty/Makefile.PL
jifty/branches/template-declare/examples/HelloKitty/bin/
jifty/branches/template-declare/examples/HelloKitty/bin/jifty (contents, props changed)
jifty/branches/template-declare/examples/HelloKitty/doc/
jifty/branches/template-declare/examples/HelloKitty/etc/
jifty/branches/template-declare/examples/HelloKitty/etc/config.yml
jifty/branches/template-declare/examples/HelloKitty/hellokitty (contents, props changed)
jifty/branches/template-declare/examples/HelloKitty/lib/
jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/
jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/Action/
jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/Model/
jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/View.pm
jifty/branches/template-declare/examples/HelloKitty/log/
jifty/branches/template-declare/examples/HelloKitty/share/
jifty/branches/template-declare/examples/HelloKitty/share/po/
jifty/branches/template-declare/examples/HelloKitty/share/web/
jifty/branches/template-declare/examples/HelloKitty/share/web/static/
jifty/branches/template-declare/examples/HelloKitty/share/web/templates/
jifty/branches/template-declare/examples/HelloKitty/t/
jifty/branches/template-declare/examples/HelloKitty/var/
jifty/branches/template-declare/examples/HelloKitty/var/jifty-server.pid
jifty/branches/template-declare/examples/HelloKitty/var/mason/
jifty/branches/template-declare/lib/Jifty/View/Declare/
jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm
jifty/branches/template-declare/lib/Jifty/View/Declare/Templates.pm
Modified:
jifty/branches/template-declare/ (props changed)
jifty/branches/template-declare/lib/Jifty/ClassLoader.pm
jifty/branches/template-declare/lib/Jifty/Config.pm
jifty/branches/template-declare/lib/Jifty/Dispatcher.pm
jifty/branches/template-declare/lib/Jifty/Handler.pm
Log:
r44699 at pinglin: jesse | 2006-11-09 00:49:47 -0500
* Initial sketch. Note that this code WILL NOT WORK without Template::Declare, which is as yet unpublished
Added: jifty/branches/template-declare/examples/HelloKitty/Makefile.PL
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/examples/HelloKitty/Makefile.PL Thu Nov 9 00:51:54 2006
@@ -0,0 +1,6 @@
+use inc::Module::Install;
+name('HelloKitty');
+version('0.01');
+requires('Jifty' => '0.61025');
+
+WriteAll;
Added: jifty/branches/template-declare/examples/HelloKitty/bin/jifty
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/examples/HelloKitty/bin/jifty Thu Nov 9 00:51:54 2006
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use File::Basename qw(dirname);
+use UNIVERSAL::require;
+
+BEGIN {
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root;
+ unshift @INC, "$root/lib" if ($root);
+}
+
+use Jifty::Script;
+$SIG{INT} = $SIG{TERM} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
Added: jifty/branches/template-declare/examples/HelloKitty/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/examples/HelloKitty/etc/config.yml Thu Nov 9 00:51:54 2006
@@ -0,0 +1,41 @@
+---
+framework:
+ AdminMode: 1
+ ApplicationClass: HelloKitty
+ ApplicationName: HelloKitty
+ Database:
+ CheckSchema: 1
+ Database: hellokitty
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ DevelMode: 1
+ L10N:
+ PoDir: share/po
+ LogLevel: INFO
+ Mailer: Sendmail
+ MailerArgs: []
+
+ Plugins: []
+
+ PubSub:
+ Backend: Memcached
+ Enable: ~
+ TemplateClass: HelloKitty::View
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Globals: []
+
+ MasonConfig:
+ autoflush: 0
+ default_escape_flags: h
+ error_format: text
+ error_mode: fatal
+ Port: 8888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
+ TemplateRoot: share/web/templates
Added: jifty/branches/template-declare/examples/HelloKitty/hellokitty
==============================================================================
Binary file. No diff available.
Added: jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/View.pm
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/examples/HelloKitty/lib/HelloKitty/View.pm Thu Nov 9 00:51:54 2006
@@ -0,0 +1,21 @@
+
+
+package HelloKitty::View;
+use base qw/Jifty::View::Declare::Templates/;
+use Template::Declare::Tags;
+
+template foo => sub {
+ html {
+ body {
+ show 'content';
+ }
+
+ }
+};
+
+template content => sub {
+ outs 'woot';
+
+};
+
+1;
Added: jifty/branches/template-declare/examples/HelloKitty/var/jifty-server.pid
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/examples/HelloKitty/var/jifty-server.pid Thu Nov 9 00:51:54 2006
@@ -0,0 +1 @@
+2728
\ No newline at end of file
Modified: jifty/branches/template-declare/lib/Jifty/ClassLoader.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/ClassLoader.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/ClassLoader.pm Thu Nov 9 00:51:54 2006
@@ -203,7 +203,7 @@
Jifty::Util->require($base."::CurrentUser");
Jifty::Module::Pluggable->import(
search_path =>
- [ map { $base . "::" . $_ } 'Model', 'Action', 'Notification', 'Event' ],
+ [ map { $base . "::" . $_ } 'Model', 'Action', 'Notification', 'Event', 'View' ],
require => 1,
except => qr/\.#/,
inner => 0
Modified: jifty/branches/template-declare/lib/Jifty/Config.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Config.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Config.pm Thu Nov 9 00:51:54 2006
@@ -239,6 +239,7 @@
AdminMode => 1,
DevelMode => 1,
ApplicationClass => $app_class,
+ TemplateClass => $app_class."::View",
ApplicationName => $app_name,
LogLevel => 'INFO',
PubSub => {
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 Thu Nov 9 00:51:54 2006
@@ -750,6 +750,7 @@
$path ||= $self->{path};
$self->log->debug("Showing path $path");
+
# If we've got a working directory (from an "under" rule) and we have
# a relative path, prepend the working directory
$path = "$self->{cwd}/$path" unless $path =~ m{^/};
@@ -759,10 +760,8 @@
$path .= "/index.html";
}
- my $abs_template_path = Jifty::Util->absolute_path(
- Jifty->config->framework('Web')->{'TemplateRoot'} . $path );
- my $abs_root_path = Jifty::Util->absolute_path(
- Jifty->config->framework('Web')->{'TemplateRoot'} );
+ my $abs_template_path = Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} . $path );
+ my $abs_root_path = Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} );
if ( $abs_template_path !~ /^\Q$abs_root_path\E/ ) {
request->path('/__jifty/errors/500');
@@ -1123,7 +1122,17 @@
my $template = shift;
$self->log->debug( "Handling template " . $template );
- eval { Jifty->handler->mason->handle_comp( $template ); };
+ eval {
+ my( $class,$codetemplate) = Jifty->handler->declare_handler->resolve_template($template);
+ if ($class and $codetemplate) {
+ warn "Got $class, $template";
+ Jifty->handler->declare_handler->show($class => $codetemplate);
+ } else {
+ Jifty->handler->mason->handle_comp( $template );
+ }
+
+
+ };
my $err = $@;
# Handle parse errors
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 Thu Nov 9 00:51:54 2006
@@ -26,6 +26,7 @@
use base qw/Class::Accessor::Fast/;
use Module::Refresh ();
+use Jifty::View::Declare::Handler ();
BEGIN {
# Creating a new CGI object breaks FastCGI in all sorts of painful
@@ -47,7 +48,7 @@
-__PACKAGE__->mk_accessors(qw(mason dispatcher static_handler cgi apache stash));
+__PACKAGE__->mk_accessors(qw(mason dispatcher declare_handler static_handler cgi apache stash));
=head2 new
@@ -70,7 +71,12 @@
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->static_handler(Jifty::View::Static::Handler->new());
Added: jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/lib/Jifty/View/Declare/Handler.pm Thu Nov 9 00:51:54 2006
@@ -0,0 +1,70 @@
+package Jifty::View::Declare::Handler;
+
+use warnings;
+use strict;
+
+use base qw/Jifty::Object Class::Accessor/;
+
+__PACKAGE__->mk_accessors(qw/root_class/);
+
+=head2 show $package $template
+
+=cut
+
+sub show {
+ my $self = shift;
+ my $package = shift;
+ my $template = shift;
+ warn "Showing $package $template";
+ print STDOUT ($package->show($template));
+
+
+}
+
+=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::UI::admin::users, new
+
+
+=cut
+
+
+sub resolve_template {
+ my $self = shift;
+ my $templatename = shift; # like /admin/ui/new
+
+
+ my @components = split('/',$templatename);
+ my $template = pop @components;
+
+
+ my $package = $self->root_class; # join('::',$self->root_class, at components);
+ warn "The user is looking for $package $template";
+ #unless ($package->isa('Jifty::View::Declare::Templates')) { $self->log->error("$package (".$self->root_class." / $templatename) isn't a valid template package."); return undef; }
+ unless ($package->has_template($template)) {
+ $self->log->error("$package has no template $template.");
+ return undef;
+
+ }
+
+ warn "Resolved $package -> $template";
+ return ($package, $template);
+
+}
+
+1;
+
Added: jifty/branches/template-declare/lib/Jifty/View/Declare/Templates.pm
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/lib/Jifty/View/Declare/Templates.pm Thu Nov 9 00:51:54 2006
@@ -0,0 +1,6 @@
+package Jifty::View::Declare::Templates;
+
+sub x{}
+use base qw/Template::Declare/;
+#
+1;
More information about the Jifty-commit
mailing list