[Jifty-commit] r3107 - in jifty/trunk: lib/Jifty
lib/Jifty/View/Mason
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Apr 6 12:11:14 EDT 2007
Author: jesse
Date: Fri Apr 6 12:11:14 2007
New Revision: 3107
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/lib/Jifty/View/Mason/Handler.pm
Log:
r54527 at dhcp207: jesse | 2007-04-07 00:33:45 +0900
* Refactoring to support more template engines
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Fri Apr 6 12:11:14 2007
@@ -1115,6 +1115,9 @@
return $text;
}
+sub _template_handlers { qw(declare_handler mason) }
+sub _fallback_template_handler { 'mason' }
+
=head2 template_exists PATH
Returns true if PATH is a valid template inside your template root. This checks
@@ -1123,11 +1126,15 @@
=cut
sub template_exists {
- my $self = shift;
+ my $self = shift;
my $template = shift;
- return Jifty->handler->declare_handler->template_exists($template)
- || Jifty->handler->mason->interp->comp_exists( $template);
+ foreach my $handler ( $self->_template_handlers) {
+ if ( Jifty->handler->$handler->template_exists($template) ) {
+ return 1;
+ }
+ }
+ return undef;
}
@@ -1143,17 +1150,21 @@
sub render_template {
my $self = shift;
my $template = shift;
-
+ my $showed = 0;
eval {
- my( $val) = Jifty->handler->declare_handler->template_exists($template);
- if ($val) {
- Jifty->handler->declare_handler->show($template);
- } else {
- Jifty->handler->mason->handle_comp( $template );
- }
-
+ foreach my $handler ( $self->_template_handlers ) {
+ if (Jifty->handler->$handler->template_exists($template) ) {
+ $showed = 1;
+ Jifty->handler->$handler->show($template);
+ last;
+ }
+ }
+ if (not $showed and my $fallback_handler = $self->_fallback_template_handler) {
+ Jifty->handler->$fallback_handler->show($template);
+ }
};
+
my $err = $@;
# Handle parse errors
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 Fri Apr 6 12:11:14 2007
@@ -139,14 +139,35 @@
}
-=head2 handle_comp COMPONENT
+=head2 template_exists COMPONENT
+
+A convenience method for $self->interp->comp_exists().
+(Jifty uses this method as part of its standard Templating system API).
+
+=cut
+
+sub template_exists {
+ my $self = shift;
+ return $self->interp->comp_exists(@_);
+}
+
+
+=head2 show COMPONENT
Takes a component path to render. Deals with setting up a global
L<HTML::Mason::FakeApache> and Request object, and calling the
component.
+=head2 handle_comp
+
+A synonym for show
+
=cut
+sub show {
+ shift->handle_comp(@_);
+}
+
sub handle_comp {
my ($self, $comp) = (shift, shift);
More information about the Jifty-commit
mailing list