X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper%2FView%2FTTSite.pm;h=ec00594a7b240f28f9cfe650fecc1b00ebbfcbc0;hb=caa68319afbd7b8db59975b1e968766da6ac6bbc;hp=d63ad4100346d0dbb6f7c9950ed06582cff97495;hpb=8cd017a801022dffbc26e7c6f8f5e91475d968a3;p=catagits%2FCatalyst-View-TT.git diff --git a/lib/Catalyst/Helper/View/TTSite.pm b/lib/Catalyst/Helper/View/TTSite.pm index d63ad41..ec00594 100644 --- a/lib/Catalyst/Helper/View/TTSite.pm +++ b/lib/Catalyst/Helper/View/TTSite.pm @@ -3,6 +3,9 @@ package Catalyst::Helper::View::TTSite; use strict; use File::Spec; +our $VERSION = '0.45'; +$VERSION = eval $VERSION; + sub mk_compclass { my ( $self, $helper, @args ) = @_; my $file = $helper->{file}; @@ -12,10 +15,9 @@ sub mk_compclass { sub mk_templates { my ( $self, $helper ) = @_; - my $base = $helper->{base}; - my $tdir = File::Spec->catfile( $base, 'templates' ); - my $ldir = File::Spec->catfile( $tdir, 'lib' ); - my $sdir = File::Spec->catfile( $tdir, 'src' ); + my $base = $helper->{base},; + my $ldir = File::Spec->catfile( $base, 'root', 'lib' ); + my $sdir = File::Spec->catfile( $base, 'root', 'src' ); $helper->mk_dir($ldir); $helper->mk_dir($sdir); @@ -50,24 +52,24 @@ Catalyst::Helper::View::TTSite - Helper for TT view which builds a skeleton web # use the helper to create the view module and templates - $ script/myapp_create.pl view TT TTSite + $ script/myapp_create.pl view HTML TTSite # add something like the following to your main application module sub message : Global { - my ($self, $c) = @_; - $c->stash->{ template } = 'message.tt2'; - $c->stash->{ message } = $c->req->param('message') || 'Hello World'; + my ( $self, $c ) = @_; + $c->stash->{template} = 'message.tt2'; + $c->stash->{message} ||= $c->req->param('message') || 'No message'; } - + sub default : Private { - my ($self, $c) = @_; - $c->stash->{ template } = 'welcome.tt2'; + my ( $self, $c ) = @_; + $c->stash->{template} = 'welcome.tt2'; } - - sub end : Private { - my ($self, $c) = @_; - $c->forward('MyApp::V::TT'); + + sub end : Private { # Or use Catalyst::Action::RenderView + my ( $self, $c ) = @_; + $c->forward( $c->view('HTML') ); } =head1 DESCRIPTION @@ -76,22 +78,58 @@ This helper module creates a TT View module. It goes further than Catalyst::Helper::View::TT in that it additionally creates a simple set of templates to get you started with your web site presentation. -It creates the templates in a F directory underneath your +It creates the templates in F directory underneath your main project directory. In here two further subdirectories are -created: F which contains the main page templates, and F -containing a library of other templates components (header, footer, +created: F which contains the main page templates, and F +containing a library of other template components (header, footer, etc.) that the page templates use. The view module that the helper creates is automatically configured to locate these templates. -=head2 METHODS +=head2 Default Rendering + +To render a template the following process is applied: + +The configuration template F is rendered. This is +controlled by the C configuration variable set in the controller +generated by Catalyst::Helper::View::TTsite. Additionally, templates referenced by +the C directive will then be rendered. By default the following additional +templates are set: F, +which defines color names and RGB their RGB values and F, +which defines site wide variables available to templates. + +Next, the template defined by the C config variable is called. The default +wrapper template is located in F. The wrapper template +passes files with C<.css/.js/.txt> extensions through as text OR processes +the templates defined after the C directive: C and C. + +Based on the default value of the C directive in F, +the following templates are processed in order: + +=over 4 + +=item * F + +=item * F + +=item * F -=head3 mk_compclass +=item * F + +=item * F + +=back + +Finally, the rendered content is returned to the browser. + +=head1 METHODS + +=head2 mk_compclass Generates the component class. -=head3 mk_templates +=head2 mk_templates Generates the templates. @@ -108,7 +146,7 @@ Andy Wardley =head1 LICENSE -This library is free software . You can redistribute it and/or modify +This library is free software. You can redistribute it and/or modify it under the same terms as perl itself. =cut @@ -122,26 +160,22 @@ package [% class %]; use strict; use base 'Catalyst::View::TT'; -use NEXT; -sub new { - my $self = shift; - my $c = shift; - my $root = $c->config->{ root }; - my $template = $c->config->{ template } || { }; - - $template->{ CATALYST_VAR } ||= 'Catalyst', - $template->{ INCLUDE_PATH } ||= [ "$root/templates/src", "$root/templates/lib" ]; - $template->{ PRE_PROCESS } ||= 'config/main'; - $template->{ WRAPPER } ||= 'site/wrapper'; - $template->{ ERROR } ||= 'error.tt2'; - - return $self->NEXT::new($c, @_); -} +__PACKAGE__->config({ + INCLUDE_PATH => [ + [% app %]->path_to( 'root', 'src' ), + [% app %]->path_to( 'root', 'lib' ) + ], + PRE_PROCESS => 'config/main', + WRAPPER => 'site/wrapper', + ERROR => 'error.tt2', + TIMER => 0, + render_die => 1, +}); =head1 NAME -[% class %] - TT View Component +[% class %] - Catalyst TTSite View =head1 SYNOPSIS @@ -149,7 +183,7 @@ See L<[% app %]> =head1 DESCRIPTION -TT View Component. +Catalyst TTSite View. =head1 AUTHOR @@ -157,8 +191,8 @@ TT View Component. =head1 LICENSE -This library is free software . You can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. =cut @@ -172,7 +206,7 @@ __config_main__ [% # config/main # # This is the main configuration template which is processed before - # any other page, by virtue of it being defined as a PRE_PROCESS + # any other page, by virtue of it being defined as a PRE_PROCESS # template. This is the place to define any extra template variables, # macros, load plugins, and perform any other template setup. @@ -187,12 +221,12 @@ __config_main__ copyright => '[* year *] Your Name Here', }; - # load up any other configuration items + # load up any other configuration items PROCESS config/col + config/url; # set defaults for variables, etc. - DEFAULT + DEFAULT message = 'There is no message'; -%] @@ -218,7 +252,7 @@ __config_col__ message = site.rgb.green error = site.rgb.red }; -%] +-%] __config_url__ [% TAGS star -%] [% base = Catalyst.req.base; @@ -232,10 +266,10 @@ __config_url__ __site_wrapper__ [% TAGS star -%] [% IF template.name.match('\.(css|js|txt)'); - debug("passing page through as text: $template.name"); + debug("Passing page through as text: $template.name"); content; ELSE; - debug("applying HTML page layout wrappers to $template.name\n"); + debug("Applying HTML page layout wrappers to $template.name\n"); content WRAPPER site/html + site/layout; END; -%] @@ -280,7 +314,7 @@ __welcome.tt2__ plugin module.

- This is the welcome page. Why not try the equally-exciting + This is the welcome page. Why not try the equally-exciting Message Page?

__message.tt2__ @@ -305,8 +339,8 @@ __error.tt2__ [% TAGS star -%] [% META title = 'Catalyst/TT Error' %]

- An error has occurred. We're terribly sorry about that, but it's - one of those things that happens from time to time. Let's just + An error has occurred. We're terribly sorry about that, but it's + one of those things that happens from time to time. Let's just hope the developers test everything properly before release...

@@ -319,7 +353,7 @@ html { height: 100%; } -body { +body { background-color: [% site.col.page %]; color: [% site.col.text %]; margin: 0px;