Commit | Line | Data |
8cd017a8 |
1 | package Catalyst::Helper::View::TTSite; |
2 | |
3 | use strict; |
4 | use File::Spec; |
5 | |
6 | sub 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 | |
13 | sub 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 | |
46 | Catalyst::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 | |
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. |
77 | |
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. |
83 | |
84 | The view module that the helper creates is automatically configured |
85 | to locate these templates. |
86 | |
87 | =head2 METHODS |
88 | |
89 | =head3 mk_compclass |
90 | |
91 | Generates the component class. |
92 | |
93 | =head3 mk_templates |
94 | |
95 | Generates the templates. |
96 | |
97 | =cut |
98 | |
99 | =head1 SEE ALSO |
100 | |
101 | L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>, |
102 | L<Catalyst::Helper::View::TT> |
103 | |
104 | =head1 AUTHOR |
105 | |
106 | Andy Wardley <abw@cpan.org> |
107 | |
108 | =head1 LICENSE |
109 | |
110 | This library is free software . You can redistribute it and/or modify |
111 | it under the same terms as perl itself. |
112 | |
113 | =cut |
114 | |
115 | 1; |
116 | |
117 | __DATA__ |
118 | |
119 | __compclass__ |
120 | package [% class %]; |
121 | |
122 | use strict; |
123 | use base 'Catalyst::View::TT'; |
8cd017a8 |
124 | |
f4841eb0 |
125 | __PACKAGE__->config({ |
126 | CATALYST_VAR => 'Catalyst', |
795f7999 |
127 | INCLUDE_PATH => [ |
128 | MyApp->path_to( 'root', 'src' ) |
129 | MyApp->path_to( 'root', 'lib' ) |
130 | ], |
f4841eb0 |
131 | PRE_PROCESS => 'config/main', |
132 | WRAPPER => 'site/wrapper', |
94b3529a |
133 | ERROR => 'error.tt2', |
134 | TIMER => 0 |
f4841eb0 |
135 | }); |
8cd017a8 |
136 | |
137 | =head1 NAME |
138 | |
795f7999 |
139 | [% class %] - Catalyst TTSite View |
8cd017a8 |
140 | |
141 | =head1 SYNOPSIS |
142 | |
143 | See L<[% app %]> |
144 | |
145 | =head1 DESCRIPTION |
146 | |
795f7999 |
147 | Catalyst TTSite View. |
8cd017a8 |
148 | |
149 | =head1 AUTHOR |
150 | |
151 | [% author %] |
152 | |
153 | =head1 LICENSE |
154 | |
795f7999 |
155 | This library is free software, you can redistribute it and/or modify |
156 | it under the same terms as Perl itself. |
8cd017a8 |
157 | |
158 | =cut |
159 | |
160 | 1; |
161 | |
162 | __config_main__ |
163 | [% USE Date; |
164 | year = Date.format(Date.now, '%Y'); |
165 | -%] |
166 | [% TAGS star -%] |
167 | [% # config/main |
168 | # |
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. |
173 | |
174 | IF Catalyst.debug; |
175 | # define a debug() macro directed to Catalyst's log |
176 | MACRO debug(message) CALL Catalyst.log.debug(message); |
177 | END; |
178 | |
179 | # define a data structure to hold sitewide data |
180 | site = { |
181 | title => 'Catalyst::View::TTSite Example Page', |
182 | copyright => '[* year *] Your Name Here', |
183 | }; |
184 | |
185 | # load up any other configuration items |
186 | PROCESS config/col |
187 | + config/url; |
188 | |
189 | # set defaults for variables, etc. |
190 | DEFAULT |
191 | message = 'There is no message'; |
192 | |
193 | -%] |
194 | __config_col__ |
195 | [% TAGS star -%] |
196 | [% site.rgb = { |
197 | black = '#000000' |
198 | white = '#ffffff' |
199 | grey1 = '#46494c' |
200 | grey2 = '#c6c9cc' |
201 | grey3 = '#e3e6ea' |
202 | red = '#CC4444' |
203 | green = '#66AA66' |
204 | blue = '#89b8df' |
205 | orange = '#f08900' |
206 | }; |
207 | |
208 | site.col = { |
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 |
214 | error = site.rgb.red |
215 | }; |
216 | %] |
217 | __config_url__ |
218 | [% TAGS star -%] |
219 | [% base = Catalyst.req.base; |
220 | |
221 | site.url = { |
222 | base = base |
223 | home = "${base}welcome" |
224 | message = "${base}message" |
225 | } |
226 | -%] |
227 | __site_wrapper__ |
228 | [% TAGS star -%] |
229 | [% IF template.name.match('\.(css|js|txt)'); |
94b3529a |
230 | debug("Passing page through as text: $template.name"); |
8cd017a8 |
231 | content; |
232 | ELSE; |
94b3529a |
233 | debug("Applying HTML page layout wrappers to $template.name\n"); |
8cd017a8 |
234 | content WRAPPER site/html + site/layout; |
235 | END; |
236 | -%] |
237 | __site_html__ |
238 | [% TAGS star -%] |
239 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
240 | <html> |
241 | <head> |
242 | <title>[% template.title or site.title %]</title> |
243 | <style type="text/css"> |
244 | [% PROCESS ttsite.css %] |
245 | </style> |
246 | </head> |
247 | <body> |
248 | [% content %] |
249 | </body> |
250 | </html> |
251 | __site_layout__ |
252 | [% TAGS star -%] |
253 | <div id="header">[% PROCESS site/header %]</div> |
254 | |
255 | <div id="content"> |
256 | [% content %] |
257 | </div> |
258 | |
259 | <div id="footer">[% PROCESS site/footer %]</div> |
260 | __site_header__ |
261 | [% TAGS star -%] |
262 | <!-- BEGIN site/header --> |
263 | <h1 class="title">[% template.title or site.title %]</h1> |
264 | <!-- END site/header --> |
265 | __site_footer__ |
266 | [% TAGS star -%] |
267 | <!-- BEGIN site/footer --> |
268 | <div id="copyright">© [% site.copyright %]</div> |
269 | <!-- END site/footer --> |
270 | __welcome.tt2__ |
271 | [% TAGS star -%] |
272 | [% META title = 'Catalyst/TT View!' %] |
273 | <p> |
274 | Yay! You're looking at a page generated by the Catalyst::View::TT |
275 | plugin module. |
276 | </p> |
277 | <p> |
278 | This is the welcome page. Why not try the equally-exciting |
279 | <a href="[% site.url.message %]">Message Page</a>? |
280 | </p> |
281 | __message.tt2__ |
282 | [% TAGS star -%] |
283 | [% META title = 'Catalyst/TT View!' %] |
284 | <p> |
285 | Yay! You're looking at a page generated by the Catalyst::View::TT |
286 | plugin module. |
287 | </p> |
288 | <p> |
289 | We have a message for you: <span class="message">[% message %]</span>. |
290 | </p> |
291 | <p> |
292 | Why not try updating the message? Go on, it's really exciting, honest! |
293 | </p> |
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 "/> |
298 | </form> |
299 | __error.tt2__ |
300 | [% TAGS star -%] |
301 | [% META title = 'Catalyst/TT Error' %] |
302 | <p> |
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... |
306 | </p> |
307 | <p> |
308 | Here's the error message, on the off-chance that it means something |
309 | to you: <span class="error">[% error %]</span> |
310 | </p> |
311 | __ttsite.css__ |
312 | [% TAGS star %] |
313 | html { |
314 | height: 100%; |
315 | } |
316 | |
317 | body { |
318 | background-color: [% site.col.page %]; |
319 | color: [% site.col.text %]; |
320 | margin: 0px; |
321 | padding: 0px; |
322 | height: 100%; |
323 | } |
324 | |
325 | #header { |
326 | background-color: [% site.col.head %]; |
327 | border-bottom: 1px solid [% site.col.line %]; |
328 | } |
329 | |
330 | #footer { |
331 | background-color: [% site.col.head %]; |
332 | text-align: center; |
333 | border-top: 1px solid [% site.col.line %]; |
334 | position: absolute; |
335 | bottom: 0; |
336 | left: 0px; |
337 | width: 100%; |
338 | padding: 4px; |
339 | } |
340 | |
341 | #content { |
342 | padding: 10px; |
343 | } |
344 | |
345 | h1.title { |
346 | padding: 4px; |
347 | margin: 0px; |
348 | } |
349 | |
350 | .message { |
351 | color: [% site.col.message %]; |
352 | } |
353 | |
354 | .error { |
355 | color: [% site.col.error %]; |
356 | } |