1 package Catalyst::Helper::View::TTSite;
7 my ( $self, $helper, @args ) = @_;
8 my $file = $helper->{file};
9 $helper->render_file( 'compclass', $file );
10 $self->mk_templates( $helper, @args );
14 my ( $self, $helper ) = @_;
15 my $base = $helper->{base},;
16 my $ldir = File::Spec->catfile( $base, 'root', 'lib' );
17 my $sdir = File::Spec->catfile( $base, 'root', 'src' );
19 $helper->mk_dir($ldir);
20 $helper->mk_dir($sdir);
22 my $dir = File::Spec->catfile( $ldir, 'config' );
23 $helper->mk_dir($dir);
25 foreach my $file (qw( main col url )) {
26 $helper->render_file( "config_$file",
27 File::Spec->catfile( $dir, $file ) );
30 $dir = File::Spec->catfile( $ldir, 'site' );
31 $helper->mk_dir($dir);
33 foreach my $file (qw( wrapper layout html header footer )) {
34 $helper->render_file( "site_$file",
35 File::Spec->catfile( $dir, $file ) );
38 foreach my $file (qw( welcome.tt2 message.tt2 error.tt2 ttsite.css )) {
39 $helper->render_file( $file, File::Spec->catfile( $sdir, $file ) );
46 Catalyst::Helper::View::TTSite - Helper for TT view which builds a skeleton web site
50 # use the helper to create the view module and templates
52 $ script/myapp_create.pl view HTML TTSite
54 # add something like the following to your main application module
56 sub message : Global {
57 my ( $self, $c ) = @_;
58 $c->stash->{template} = 'message.tt2';
59 $c->stash->{message} ||= $c->req->param('message') || 'No message';
62 sub default : Private {
63 my ( $self, $c ) = @_;
64 $c->stash->{template} = 'welcome.tt2';
67 sub end : Private { # Or use Catalyst::Action::RenderView
68 my ( $self, $c ) = @_;
69 $c->forward( $c->view('HTML') );
74 This helper module creates a TT View module. It goes further than
75 Catalyst::Helper::View::TT in that it additionally creates a simple
76 set of templates to get you started with your web site presentation.
78 It creates the templates in F<root/> directory underneath your
79 main project directory. In here two further subdirectories are
80 created: F<root/src> which contains the main page templates, and F<root/lib>
81 containing a library of other template components (header, footer,
82 etc.) that the page templates use.
84 The view module that the helper creates is automatically configured
85 to locate these templates.
87 =head2 Default Rendering
89 To render a template the following process is applied:
91 The configuration template F<root/lib/config/main> is rendered. This is
92 controlled by the C<PRE_PROCESS> configuration variable set in the controller
93 generated by Catalyst::Helper::View::TTsite. Additionally, templates referenced by
94 the C<PROCESS> directive will then be rendered. By default the following additional
95 templates are set: F<root/lib/config/col>,
96 which defines color names and RGB their RGB values and F</root/lib/config/url>,
97 which defines site wide variables available to templates.
99 Next, the template defined by the C<WRAPPER> config variable is called. The default
100 wrapper template is located in F<root/lib/site/wrapper>. The wrapper template
101 passes files with C<.css/.js/.txt> extensions through as text OR processes
102 the templates defined after the C<WRAPPER> directive: C<site/html> and C<site/layout>.
104 Based on the default value of the C<WRAPPER> directive in F<root/lib/site/wrapper>,
105 the following templates are processed in order:
109 =item * F<root/src/your_template.tt2>
111 =item * F<root/lib/site/footer>
113 =item * F<root/lib/site/header>
115 =item * F<root/lib/site/layout>
117 =item * F<root/lib/site/html>
121 Finally, the rendered content is returned to the bowser.
127 Generates the component class.
131 Generates the templates.
137 L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>,
138 L<Catalyst::Helper::View::TT>
142 Andy Wardley <abw@cpan.org>
146 This library is free software. You can redistribute it and/or modify
147 it under the same terms as perl itself.
159 use base 'Catalyst::View::TT';
161 __PACKAGE__->config({
163 [% app %]->path_to( 'root', 'src' ),
164 [% app %]->path_to( 'root', 'lib' )
166 PRE_PROCESS => 'config/main',
167 WRAPPER => 'site/wrapper',
168 ERROR => 'error.tt2',
175 [% class %] - Catalyst TTSite View
183 Catalyst TTSite View.
191 This library is free software. You can redistribute it and/or modify
192 it under the same terms as Perl itself.
200 year = Date.format(Date.now, '%Y');
205 # This is the main configuration template which is processed before
206 # any other page, by virtue of it being defined as a PRE_PROCESS
207 # template. This is the place to define any extra template variables,
208 # macros, load plugins, and perform any other template setup.
211 # define a debug() macro directed to Catalyst's log
212 MACRO debug(message) CALL Catalyst.log.debug(message);
215 # define a data structure to hold sitewide data
217 title => 'Catalyst::View::TTSite Example Page',
218 copyright => '[* year *] Your Name Here',
221 # load up any other configuration items
225 # set defaults for variables, etc.
227 message = 'There is no message';
245 page = site.rgb.white
246 text = site.rgb.grey1
247 head = site.rgb.grey3
248 line = site.rgb.orange
249 message = site.rgb.green
255 [% base = Catalyst.req.base;
259 home = "${base}welcome"
260 message = "${base}message"
265 [% IF template.name.match('\.(css|js|txt)');
266 debug("Passing page through as text: $template.name");
269 debug("Applying HTML page layout wrappers to $template.name\n");
270 content WRAPPER site/html + site/layout;
275 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
278 <title>[% template.title or site.title %]</title>
279 <style type="text/css">
280 [% PROCESS ttsite.css %]
289 <div id="header">[% PROCESS site/header %]</div>
295 <div id="footer">[% PROCESS site/footer %]</div>
298 <!-- BEGIN site/header -->
299 <h1 class="title">[% template.title or site.title %]</h1>
300 <!-- END site/header -->
303 <!-- BEGIN site/footer -->
304 <div id="copyright">© [% site.copyright %]</div>
305 <!-- END site/footer -->
308 [% META title = 'Catalyst/TT View!' %]
310 Yay! You're looking at a page generated by the Catalyst::View::TT
314 This is the welcome page. Why not try the equally-exciting
315 <a href="[% site.url.message %]">Message Page</a>?
319 [% META title = 'Catalyst/TT View!' %]
321 Yay! You're looking at a page generated by the Catalyst::View::TT
325 We have a message for you: <span class="message">[% message %]</span>.
328 Why not try updating the message? Go on, it's really exciting, honest!
330 <form action="[% site.url.message %]"
331 method="POST" enctype="application/x-www-form-urlencoded">
332 <input type="text" name="message" value="[% message %]" />
333 <input type="submit" name="submit" value=" Update Message "/>
337 [% META title = 'Catalyst/TT Error' %]
339 An error has occurred. We're terribly sorry about that, but it's
340 one of those things that happens from time to time. Let's just
341 hope the developers test everything properly before release...
344 Here's the error message, on the off-chance that it means something
345 to you: <span class="error">[% error %]</span>
354 background-color: [% site.col.page %];
355 color: [% site.col.text %];
362 background-color: [% site.col.head %];
363 border-bottom: 1px solid [% site.col.line %];
367 background-color: [% site.col.head %];
369 border-top: 1px solid [% site.col.line %];
387 color: [% site.col.message %];
391 color: [% site.col.error %];