tidy up changes file, fix generated pod (RT #33983)
[catagits/Catalyst-View-TT.git] / lib / Catalyst / Helper / View / TTSite.pm
CommitLineData
8cd017a8 1package Catalyst::Helper::View::TTSite;
2
3use strict;
4use File::Spec;
5
6sub mk_compclass {
7 my ( $self, $helper, @args ) = @_;
8 my $file = $helper->{file};
9 $helper->render_file( 'compclass', $file );
10 $self->mk_templates( $helper, @args );
11}
12
13sub mk_templates {
14 my ( $self, $helper ) = @_;
19ee577a 15 my $base = $helper->{base},;
16 my $ldir = File::Spec->catfile( $base, 'root', 'lib' );
17 my $sdir = File::Spec->catfile( $base, 'root', 'src' );
8cd017a8 18
19 $helper->mk_dir($ldir);
20 $helper->mk_dir($sdir);
21
22 my $dir = File::Spec->catfile( $ldir, 'config' );
23 $helper->mk_dir($dir);
24
25 foreach my $file (qw( main col url )) {
26 $helper->render_file( "config_$file",
27 File::Spec->catfile( $dir, $file ) );
28 }
29
30 $dir = File::Spec->catfile( $ldir, 'site' );
31 $helper->mk_dir($dir);
32
33 foreach my $file (qw( wrapper layout html header footer )) {
34 $helper->render_file( "site_$file",
35 File::Spec->catfile( $dir, $file ) );
36 }
37
38 foreach my $file (qw( welcome.tt2 message.tt2 error.tt2 ttsite.css )) {
39 $helper->render_file( $file, File::Spec->catfile( $sdir, $file ) );
40 }
41
42}
43
44=head1 NAME
45
46Catalyst::Helper::View::TTSite - Helper for TT view which builds a skeleton web site
47
48=head1 SYNOPSIS
49
50# use the helper to create the view module and templates
51
52 $ script/myapp_create.pl view TT TTSite
53
54# add something like the following to your main application module
55
56 sub message : Global {
94b3529a 57 my ( $self, $c ) = @_;
58 $c->stash->{template} = 'message.tt2';
19ee577a 59 $c->stash->{message} ||= $c->req->param('message') || 'No message';
8cd017a8 60 }
61
62 sub default : Private {
94b3529a 63 my ( $self, $c ) = @_;
64 $c->stash->{template} = 'welcome.tt2';
8cd017a8 65 }
66
67 sub end : Private {
94b3529a 68 my ( $self, $c ) = @_;
8cd017a8 69 $c->forward('MyApp::V::TT');
70 }
71
72=head1 DESCRIPTION
73
74This helper module creates a TT View module. It goes further than
75Catalyst::Helper::View::TT in that it additionally creates a simple
76set of templates to get you started with your web site presentation.
77
78It creates the templates in a F<templates> directory underneath your
79main project directory. In here two further subdirectories are
80created: F<src> which contains the main page templates, and F<lib>
81containing a library of other templates components (header, footer,
82etc.) that the page templates use.
83
84The view module that the helper creates is automatically configured
85to locate these templates.
86
87=head2 METHODS
88
89=head3 mk_compclass
90
91Generates the component class.
92
93=head3 mk_templates
94
95Generates the templates.
96
97=cut
98
99=head1 SEE ALSO
100
101L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>,
102L<Catalyst::Helper::View::TT>
103
104=head1 AUTHOR
105
106Andy Wardley <abw@cpan.org>
107
108=head1 LICENSE
109
110This library is free software . You can redistribute it and/or modify
111it under the same terms as perl itself.
112
113=cut
114
1151;
116
117__DATA__
118
119__compclass__
120package [% class %];
121
122use strict;
123use base 'Catalyst::View::TT';
8cd017a8 124
f4841eb0 125__PACKAGE__->config({
795f7999 126 INCLUDE_PATH => [
4d97e86f 127 [% app %]->path_to( 'root', 'src' ),
128 [% app %]->path_to( 'root', 'lib' )
795f7999 129 ],
f4841eb0 130 PRE_PROCESS => 'config/main',
131 WRAPPER => 'site/wrapper',
94b3529a 132 ERROR => 'error.tt2',
133 TIMER => 0
f4841eb0 134});
8cd017a8 135
136=head1 NAME
137
795f7999 138[% class %] - Catalyst TTSite View
8cd017a8 139
140=head1 SYNOPSIS
141
142See L<[% app %]>
143
144=head1 DESCRIPTION
145
795f7999 146Catalyst TTSite View.
8cd017a8 147
148=head1 AUTHOR
149
150[% author %]
151
152=head1 LICENSE
153
795f7999 154This library is free software, you can redistribute it and/or modify
155it under the same terms as Perl itself.
8cd017a8 156
157=cut
158
1591;
160
161__config_main__
162[% USE Date;
163 year = Date.format(Date.now, '%Y');
164-%]
165[% TAGS star -%]
166[% # config/main
167 #
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.
172
173 IF Catalyst.debug;
174 # define a debug() macro directed to Catalyst's log
175 MACRO debug(message) CALL Catalyst.log.debug(message);
176 END;
177
178 # define a data structure to hold sitewide data
179 site = {
180 title => 'Catalyst::View::TTSite Example Page',
181 copyright => '[* year *] Your Name Here',
182 };
183
184 # load up any other configuration items
185 PROCESS config/col
186 + config/url;
187
188 # set defaults for variables, etc.
189 DEFAULT
190 message = 'There is no message';
191
192-%]
193__config_col__
194[% TAGS star -%]
195[% site.rgb = {
196 black = '#000000'
197 white = '#ffffff'
198 grey1 = '#46494c'
199 grey2 = '#c6c9cc'
200 grey3 = '#e3e6ea'
201 red = '#CC4444'
202 green = '#66AA66'
203 blue = '#89b8df'
204 orange = '#f08900'
205 };
206
207 site.col = {
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
213 error = site.rgb.red
214 };
215%]
216__config_url__
217[% TAGS star -%]
218[% base = Catalyst.req.base;
219
220 site.url = {
221 base = base
222 home = "${base}welcome"
223 message = "${base}message"
224 }
225-%]
226__site_wrapper__
227[% TAGS star -%]
228[% IF template.name.match('\.(css|js|txt)');
94b3529a 229 debug("Passing page through as text: $template.name");
8cd017a8 230 content;
231 ELSE;
94b3529a 232 debug("Applying HTML page layout wrappers to $template.name\n");
8cd017a8 233 content WRAPPER site/html + site/layout;
234 END;
235-%]
236__site_html__
237[% TAGS star -%]
238<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
239<html>
240 <head>
241 <title>[% template.title or site.title %]</title>
242 <style type="text/css">
243[% PROCESS ttsite.css %]
244 </style>
245 </head>
246 <body>
247[% content %]
248 </body>
249</html>
250__site_layout__
251[% TAGS star -%]
252<div id="header">[% PROCESS site/header %]</div>
253
254<div id="content">
255[% content %]
256</div>
257
258<div id="footer">[% PROCESS site/footer %]</div>
259__site_header__
260[% TAGS star -%]
261<!-- BEGIN site/header -->
262<h1 class="title">[% template.title or site.title %]</h1>
263<!-- END site/header -->
264__site_footer__
265[% TAGS star -%]
266<!-- BEGIN site/footer -->
267<div id="copyright">&copy; [% site.copyright %]</div>
268<!-- END site/footer -->
269__welcome.tt2__
270[% TAGS star -%]
271[% META title = 'Catalyst/TT View!' %]
272<p>
273 Yay! You're looking at a page generated by the Catalyst::View::TT
274 plugin module.
275</p>
276<p>
277 This is the welcome page. Why not try the equally-exciting
278 <a href="[% site.url.message %]">Message Page</a>?
279</p>
280__message.tt2__
281[% TAGS star -%]
282[% META title = 'Catalyst/TT View!' %]
283<p>
284 Yay! You're looking at a page generated by the Catalyst::View::TT
285 plugin module.
286</p>
287<p>
288 We have a message for you: <span class="message">[% message %]</span>.
289</p>
290<p>
291 Why not try updating the message? Go on, it's really exciting, honest!
292</p>
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 "/>
297</form>
298__error.tt2__
299[% TAGS star -%]
300[% META title = 'Catalyst/TT Error' %]
301<p>
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...
305</p>
306<p>
307 Here's the error message, on the off-chance that it means something
308 to you: <span class="error">[% error %]</span>
309</p>
310__ttsite.css__
311[% TAGS star %]
312html {
313 height: 100%;
314}
315
316body {
317 background-color: [% site.col.page %];
318 color: [% site.col.text %];
319 margin: 0px;
320 padding: 0px;
321 height: 100%;
322}
323
324#header {
325 background-color: [% site.col.head %];
326 border-bottom: 1px solid [% site.col.line %];
327}
328
329#footer {
330 background-color: [% site.col.head %];
331 text-align: center;
332 border-top: 1px solid [% site.col.line %];
333 position: absolute;
334 bottom: 0;
335 left: 0px;
336 width: 100%;
337 padding: 4px;
338}
339
340#content {
341 padding: 10px;
342}
343
344h1.title {
345 padding: 4px;
346 margin: 0px;
347}
348
349.message {
350 color: [% site.col.message %];
351}
352
353.error {
354 color: [% site.col.error %];
355}