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 $tdir = File::Spec->catfile( $base, 'root', 'templates' );
17 my $ldir = File::Spec->catfile( $tdir, 'lib' );
18 my $sdir = File::Spec->catfile( $tdir, 'src' );
20 $helper->mk_dir($ldir);
21 $helper->mk_dir($sdir);
23 my $dir = File::Spec->catfile( $ldir, 'config' );
24 $helper->mk_dir($dir);
26 foreach my $file (qw( main col url )) {
27 $helper->render_file( "config_$file",
28 File::Spec->catfile( $dir, $file ) );
31 $dir = File::Spec->catfile( $ldir, 'site' );
32 $helper->mk_dir($dir);
34 foreach my $file (qw( wrapper layout html header footer )) {
35 $helper->render_file( "site_$file",
36 File::Spec->catfile( $dir, $file ) );
39 foreach my $file (qw( welcome.tt2 message.tt2 error.tt2 ttsite.css )) {
40 $helper->render_file( $file, File::Spec->catfile( $sdir, $file ) );
47 Catalyst::Helper::View::TTSite - Helper for TT view which builds a skeleton web site
51 # use the helper to create the view module and templates
53 $ script/myapp_create.pl view TT TTSite
55 # add something like the following to your main application module
57 sub message : Global {
59 $c->stash->{ template } = 'message.tt2';
60 $c->stash->{ message } = $c->req->param('message') || 'Hello World';
63 sub default : Private {
65 $c->stash->{ template } = 'welcome.tt2';
70 $c->forward('MyApp::V::TT');
75 This helper module creates a TT View module. It goes further than
76 Catalyst::Helper::View::TT in that it additionally creates a simple
77 set of templates to get you started with your web site presentation.
79 It creates the templates in a F<templates> directory underneath your
80 main project directory. In here two further subdirectories are
81 created: F<src> which contains the main page templates, and F<lib>
82 containing a library of other templates components (header, footer,
83 etc.) that the page templates use.
85 The view module that the helper creates is automatically configured
86 to locate these templates.
92 Generates the component class.
96 Generates the templates.
102 L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>,
103 L<Catalyst::Helper::View::TT>
107 Andy Wardley <abw@cpan.org>
111 This library is free software . You can redistribute it and/or modify
112 it under the same terms as perl itself.
124 use base 'Catalyst::View::TT';
126 my $root = [% app %]->config->root;
128 __PACKAGE__->config({
129 CATALYST_VAR => 'Catalyst',
130 INCLUDE_PATH => [ "$root/templates/src", "$root/templates/lib" ],
131 PRE_PROCESS => 'config/main',
132 WRAPPER => 'site/wrapper',
138 [% class %] - TT View Component
154 This library is free software . You can redistribute it and/or modify
155 it under the same terms as perl itself.
163 year = Date.format(Date.now, '%Y');
168 # This is the main configuration template which is processed before
169 # any other page, by virtue of it being defined as a PRE_PROCESS
170 # template. This is the place to define any extra template variables,
171 # macros, load plugins, and perform any other template setup.
174 # define a debug() macro directed to Catalyst's log
175 MACRO debug(message) CALL Catalyst.log.debug(message);
178 # define a data structure to hold sitewide data
180 title => 'Catalyst::View::TTSite Example Page',
181 copyright => '[* year *] Your Name Here',
184 # load up any other configuration items
188 # set defaults for variables, etc.
190 message = 'There is no message';
208 page = site.rgb.white
209 text = site.rgb.grey1
210 head = site.rgb.grey3
211 line = site.rgb.orange
212 message = site.rgb.green
218 [% base = Catalyst.req.base;
222 home = "${base}welcome"
223 message = "${base}message"
228 [% IF template.name.match('\.(css|js|txt)');
229 debug("passing page through as text: $template.name");
232 debug("applying HTML page layout wrappers to $template.name\n");
233 content WRAPPER site/html + site/layout;
238 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
241 <title>[% template.title or site.title %]</title>
242 <style type="text/css">
243 [% PROCESS ttsite.css %]
252 <div id="header">[% PROCESS site/header %]</div>
258 <div id="footer">[% PROCESS site/footer %]</div>
261 <!-- BEGIN site/header -->
262 <h1 class="title">[% template.title or site.title %]</h1>
263 <!-- END site/header -->
266 <!-- BEGIN site/footer -->
267 <div id="copyright">© [% site.copyright %]</div>
268 <!-- END site/footer -->
271 [% META title = 'Catalyst/TT View!' %]
273 Yay! You're looking at a page generated by the Catalyst::View::TT
277 This is the welcome page. Why not try the equally-exciting
278 <a href="[% site.url.message %]">Message Page</a>?
282 [% META title = 'Catalyst/TT View!' %]
284 Yay! You're looking at a page generated by the Catalyst::View::TT
288 We have a message for you: <span class="message">[% message %]</span>.
291 Why not try updating the message? Go on, it's really exciting, honest!
293 <form action="[% site.url.message %]"
294 method="POST" enctype="application/x-www-form-urlencoded">
295 <input type="text" name="message" value="[% message %]" />
296 <input type="submit" name="submit" value=" Update Message "/>
300 [% META title = 'Catalyst/TT Error' %]
302 An error has occurred. We're terribly sorry about that, but it's
303 one of those things that happens from time to time. Let's just
304 hope the developers test everything properly before release...
307 Here's the error message, on the off-chance that it means something
308 to you: <span class="error">[% error %]</span>
317 background-color: [% site.col.page %];
318 color: [% site.col.text %];
325 background-color: [% site.col.head %];
326 border-bottom: 1px solid [% site.col.line %];
330 background-color: [% site.col.head %];
332 border-top: 1px solid [% site.col.line %];
350 color: [% site.col.message %];
354 color: [% site.col.error %];