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('MyApp::V::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 a F<templates> directory underneath your
79 main project directory. In here two further subdirectories are
80 created: F<src> which contains the main page templates, and F<lib>
81 containing a library of other templates 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.
91 Generates the component class.
95 Generates the templates.
101 L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>,
102 L<Catalyst::Helper::View::TT>
106 Andy Wardley <abw@cpan.org>
110 This library is free software . You can redistribute it and/or modify
111 it under the same terms as perl itself.
123 use base 'Catalyst::View::TT';
125 __PACKAGE__->config({
126 CATALYST_VAR => 'Catalyst',
128 MyApp->path_to( 'root', 'src' )
129 MyApp->path_to( 'root', 'lib' )
131 PRE_PROCESS => 'config/main',
132 WRAPPER => 'site/wrapper',
133 ERROR => 'error.tt2',
139 [% class %] - Catalyst TTSite View
147 Catalyst TTSite View.
155 This library is free software, you can redistribute it and/or modify
156 it under the same terms as Perl itself.
164 year = Date.format(Date.now, '%Y');
169 # This is the main configuration template which is processed before
170 # any other page, by virtue of it being defined as a PRE_PROCESS
171 # template. This is the place to define any extra template variables,
172 # macros, load plugins, and perform any other template setup.
175 # define a debug() macro directed to Catalyst's log
176 MACRO debug(message) CALL Catalyst.log.debug(message);
179 # define a data structure to hold sitewide data
181 title => 'Catalyst::View::TTSite Example Page',
182 copyright => '[* year *] Your Name Here',
185 # load up any other configuration items
189 # set defaults for variables, etc.
191 message = 'There is no message';
209 page = site.rgb.white
210 text = site.rgb.grey1
211 head = site.rgb.grey3
212 line = site.rgb.orange
213 message = site.rgb.green
219 [% base = Catalyst.req.base;
223 home = "${base}welcome"
224 message = "${base}message"
229 [% IF template.name.match('\.(css|js|txt)');
230 debug("Passing page through as text: $template.name");
233 debug("Applying HTML page layout wrappers to $template.name\n");
234 content WRAPPER site/html + site/layout;
239 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
242 <title>[% template.title or site.title %]</title>
243 <style type="text/css">
244 [% PROCESS ttsite.css %]
253 <div id="header">[% PROCESS site/header %]</div>
259 <div id="footer">[% PROCESS site/footer %]</div>
262 <!-- BEGIN site/header -->
263 <h1 class="title">[% template.title or site.title %]</h1>
264 <!-- END site/header -->
267 <!-- BEGIN site/footer -->
268 <div id="copyright">© [% site.copyright %]</div>
269 <!-- END site/footer -->
272 [% META title = 'Catalyst/TT View!' %]
274 Yay! You're looking at a page generated by the Catalyst::View::TT
278 This is the welcome page. Why not try the equally-exciting
279 <a href="[% site.url.message %]">Message Page</a>?
283 [% META title = 'Catalyst/TT View!' %]
285 Yay! You're looking at a page generated by the Catalyst::View::TT
289 We have a message for you: <span class="message">[% message %]</span>.
292 Why not try updating the message? Go on, it's really exciting, honest!
294 <form action="[% site.url.message %]"
295 method="POST" enctype="application/x-www-form-urlencoded">
296 <input type="text" name="message" value="[% message %]" />
297 <input type="submit" name="submit" value=" Update Message "/>
301 [% META title = 'Catalyst/TT Error' %]
303 An error has occurred. We're terribly sorry about that, but it's
304 one of those things that happens from time to time. Let's just
305 hope the developers test everything properly before release...
308 Here's the error message, on the off-chance that it means something
309 to you: <span class="error">[% error %]</span>
318 background-color: [% site.col.page %];
319 color: [% site.col.text %];
326 background-color: [% site.col.head %];
327 border-bottom: 1px solid [% site.col.line %];
331 background-color: [% site.col.head %];
333 border-top: 1px solid [% site.col.line %];
351 color: [% site.col.message %];
355 color: [% site.col.error %];