Skip to content
This repository has been archived by the owner on Jun 24, 2018. It is now read-only.

Commit

Permalink
better control over where the templats are stored
Browse files Browse the repository at this point in the history
  • Loading branch information
jjn1056 committed Jan 28, 2011
1 parent 90a6324 commit 43d4f2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MooseX::Types::Common = 0.001
namespace::autoclean = 0.09
HTML::Zoom = 0.009
Class::MOP = 1.12
Path::Class = 0.23

[Prereq / TestRequires]
Test::More = 0.96
Expand Down
22 changes: 17 additions & 5 deletions lib/Catalyst/View/HTML/Zoom.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use HTML::Zoom;
use MooseX::Types::Moose qw( Maybe );
use MooseX::Types::Common::String qw( NonEmptySimpleStr );
use namespace::autoclean;
use Path::Class ();

extends 'Catalyst::View';

Expand All @@ -17,6 +18,12 @@ has template_extension => (
required => 1
);

has root => (
is => 'ro',
isa => 'Str',
predicate => 'has_root',
);

my $app_class;
before COMPONENT => sub {
$app_class = ref $_[1] || $_[1];
Expand All @@ -31,11 +38,16 @@ sub process {
$template_fn = $template_fn . '.' . $ext
unless $template_fn =~ /\.$ext$/;
}

my $template = $c->path_to('root', $template_fn);
die("Cannot find template $template_fn") unless -r $template;

$c->res->body($self->render($c, $template->stringify));

my $template_path = $self->has_root ?
Path::Class::dir($self->root, $template_fn) :
Path::Class::dir($c->config->{root}, $template_fn);

if( -r $template_path) {
$c->res->body($self->render($c, $template_path->stringify));
} else {
$c->log->error("Cannot find template $template_fn at $template_path");
}
}

sub render {
Expand Down

0 comments on commit 43d4f2a

Please sign in to comment.