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 TT 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';
68 my ( $self, $c ) = @_;
69 $c->forward( $c->view('TT') );
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',
174 [% class %] - Catalyst TTSite View
182 Catalyst TTSite View.
190 This library is free software. You can redistribute it and/or modify
191 it under the same terms as Perl itself.
199 year = Date.format(Date.now, '%Y');
204 # This is the main configuration template which is processed before
205 # any other page, by virtue of it being defined as a PRE_PROCESS
206 # template. This is the place to define any extra template variables,
207 # macros, load plugins, and perform any other template setup.
210 # define a debug() macro directed to Catalyst's log
211 MACRO debug(message) CALL Catalyst.log.debug(message);
214 # define a data structure to hold sitewide data
216 title => 'Catalyst::View::TTSite Example Page',
217 copyright => '[* year *] Your Name Here',
220 # load up any other configuration items
224 # set defaults for variables, etc.
226 message = 'There is no message';
244 page = site.rgb.white
245 text = site.rgb.grey1
246 head = site.rgb.grey3
247 line = site.rgb.orange
248 message = site.rgb.green
254 [% base = Catalyst.req.base;
258 home = "${base}welcome"
259 message = "${base}message"
264 [% IF template.name.match('\.(css|js|txt)');
265 debug("Passing page through as text: $template.name");
268 debug("Applying HTML page layout wrappers to $template.name\n");
269 content WRAPPER site/html + site/layout;
274 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
277 <title>[% template.title or site.title %]</title>
278 <style type="text/css">
279 [% PROCESS ttsite.css %]
288 <div id="header">[% PROCESS site/header %]</div>
294 <div id="footer">[% PROCESS site/footer %]</div>
297 <!-- BEGIN site/header -->
298 <h1 class="title">[% template.title or site.title %]</h1>
299 <!-- END site/header -->
302 <!-- BEGIN site/footer -->
303 <div id="copyright">© [% site.copyright %]</div>
304 <!-- END site/footer -->
307 [% META title = 'Catalyst/TT View!' %]
309 Yay! You're looking at a page generated by the Catalyst::View::TT
313 This is the welcome page. Why not try the equally-exciting
314 <a href="[% site.url.message %]">Message Page</a>?
318 [% META title = 'Catalyst/TT View!' %]
320 Yay! You're looking at a page generated by the Catalyst::View::TT
324 We have a message for you: <span class="message">[% message %]</span>.
327 Why not try updating the message? Go on, it's really exciting, honest!
329 <form action="[% site.url.message %]"
330 method="POST" enctype="application/x-www-form-urlencoded">
331 <input type="text" name="message" value="[% message %]" />
332 <input type="submit" name="submit" value=" Update Message "/>
336 [% META title = 'Catalyst/TT Error' %]
338 An error has occurred. We're terribly sorry about that, but it's
339 one of those things that happens from time to time. Let's just
340 hope the developers test everything properly before release...
343 Here's the error message, on the off-chance that it means something
344 to you: <span class="error">[% error %]</span>
353 background-color: [% site.col.page %];
354 color: [% site.col.text %];
361 background-color: [% site.col.head %];
362 border-bottom: 1px solid [% site.col.line %];
366 background-color: [% site.col.head %];
368 border-top: 1px solid [% site.col.line %];
386 color: [% site.col.message %];
390 color: [% site.col.error %];