Bootstrap/Manual.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package Catalyst::Helper::View::TT::Bootstrap::Manual; 1;
2  
3 =head1 NAME
4  
5 Catalyst::Helper::View::TT::Bootstrap::Manual - User guide and reference for
6 files generated by Catalyst::Helper::View::TT::Bootstrap.
7  
8 =head1 DESCRIPTION
9  
10 =head2 Files and Directory Structure
11  
12 The files and directories generated under your application root (e.g. MyApp/) are:
13  
14 lib/MyApp/View/TT.pm # The TT View module with a couple extras
15  
16 root/
17 site/
18 wrapper.tt # routes all pages to their appropriate layout
19 html.tt # renders the html wrapper. See below
20  
21 header/ # directory for header templates
22 default.tt # placeholder masthead for you to override
23  
24 footer/ # directory for footer templates
25 default.tt # placeholder footer for you to override
26  
27 nav/ # directory for navigation templates. See below
28 default.tt # placeholder nav for you to override
29  
30 layout/ # directory for various content layouts
31 default.tt # basic layout, renders content only
32 2columns.tt # 2 column layout. See below
33 2col_top.tt # 2 columns above full width content. See below
34 2col_bottom.tt # 2 columns below full width content. See below
35  
36 shared/ # directory for templates shared by several pages
37 base.tt # core macros and stash framework. See below
38  
39 static/ # directory root of static resources
40
41 images/ # content images go here or in a subdir
42  
43 scripts/ # javascript files go here or in a subdir
44  
45 css/ # stylesheets go here or in a subdir
46 screen.css # global stylesheet supporting the provided
47 # layouts and resetting default browser styles
48 nav_default.css # stylesheet for nav/default.tt
49  
50 images/ # css images go here on in a subdir
51
52 =head2 View Module Configuration
53  
54 The generated View/TT.pm sets the following configuration key/values:
55  
56 PRE_PROCESS => 'site/shared/base.tt',
57 WRAPPER => 'site/wrapper.tt',
58 TEMPLATE_EXTENSION => '.tt',
59 TIMER => 0,
60 static_root => '/static',
61 static_build => 0
62  
63 The last two config options are added to the template stash for each rendering.
64  
65 <p>The current static root is [% static_root %]</p>
66 <p>And the current static build is [% static_build %]</p>
67  
68 =over 4
69  
70 =item static_root
71  
72 Used by the macro 'static' (see below) to locate static resources such as images, stylesheets, and javascript files. The default value is '/static' (effectively MyApp/root/static).
73  
74 =item static_build
75  
76 (Optional) Used by the macro 'static' to append the returned URIs with a query
77 string 'ver' with the value assigned to static_build. This is particularly
78 useful to ensure returning site visitors get the latest version of static
79 resources. By default, this is set to 0 (versioning off).
80  
81 Two strategies for use are
82  
83 =over 4
84  
85 =item 1
86  
87 Manually update it when a static file is modifed, using the a datestamp value.
88 Using a YAML config makes this more convenient.
89  
90 ...
91 View::TT:
92 static_build: 20070907
93 ...
94  
95 =item 2
96  
97 Assign it the result of a call to localtime, so every time the server restarts,
98 static requests will avoid the browser cache (first request only).
99  
100 =back
101  
102 =back
103  
104 =head2 Template variable framework
105  
106 =head3 base.tt and the page variable
107  
108 site/shared/base.tt is PRE_PROCESSed before any page template rendering. It
109 adds the following variables and macros:
110  
111 =over 4
112  
113 =item MACRO ref(variable)
114  
115 Works essentially like the native perl ref. Since TT auto-converts variables,
116 it's often difficult to incorporate type checking into any template
117 conditionals. This makes that functionality available again.
118  
119 [%
120 IF colors && ref(colors) == 'HASH';
121 ...do something...
122 END
123 %]
124  
125 =item MACRO static(resource, versioned, query)
126  
127 Wraps c.uri_for for static resources. The full URI is returned with any query
128 params appended. If a non-false value is passed for the versioned param, the
129 query param ver => [% static_build %] will be added to the query string if
130 static_build is set.
131  
132 <img alt="Sample image" src="[% static('images/sample.png') %]">
133 BECOMES (e.g.)
134 <img alt="Sample image" src="http://mydomain.com/static/images/sample.png">
135  
136 <script type="text/javascript" src="[% static('scripts/changes_often.js',1) %]"></script>
137 BECOMES
138 <script type="text/javascript" src="http://mydomain.com/static/scripts/changes_often.js?ver=20070907"></script>
139
140 For flexibility, if a full URI is passed as the resource param, it will be
141 returned unaltered. No query params nor the static_build versioning will be
142 appended to the URI.
143  
144 =item page
145  
146 This hash struct contains key/value pairs used by the template structure to
147 describe how the page should be rendered. Don't create or clobber a template
148 stash variable named 'page', as this will cause havok. Work with the page
149 variable structure provided.
150  
151 The stuff you can and should play with are ...
152  
153 =item page.layout
154  
155 [% page.layout = '2columns'; %]
156  
157 Assign the short name of the template found in /root/site/layout.
158 Will cause the page to be wrapped in the appropriate layout. Add any new
159 layouts (say 3column.tt) to this directory and the page.layout will do the right
160 thing. The default value is 'default'.
161  
162 Other magic values are:
163  
164 =over 4
165  
166 =item 'none'
167  
168 Don't use a layout. Just place the content in the html.tt wrapper. Out of the
169 box, this is equivalent to the default.
170  
171 =item 'partial'
172  
173 Don't even wrap in html.tt. This is useful for Ajax calls returning only bits
174 of a page dynamically.
175  
176 =back
177  
178 =item page.title
179  
180 Assigned to the title element in the html head. The default value is the name
181 of your app (e.g. MyApp).
182  
183 Note, unless you refer to page.title in the content area, this is NOT displayed in your page content.
184  
185 =item page.header
186  
187 [% page.header = 'small_screen' %]
188  
189 Similar to page.layout, this accepts a string short name for templates in
190 /root/site/header. The default value is 'default'.
191  
192 This also accepts the value 'none' to omit the inclusion of a header.
193  
194 Note that page.header and page.footer are still rendered when page.layout is set
195 to 'none' unless they too are set to 'none'.
196  
197 =item page.footer
198  
199 [% page.footer = 'no_contact_us' %]
200  
201 Works like page.header.
202  
203 =item page.nav
204  
205 [% page.nav = 'green' %]
206  
207 Similar to page.layout, this accepts a string short name for templates in
208 /root/site/nav. The default value is 'default';
209  
210 The out of the box default header happens to PROCESS page.nav, but in a real
211 world application, you should add the PROCESS call in either your header or
212 a layout template according to where you want the nav located.
213  
214 Additionally, a stylesheet reference is automatically added to the head element
215 named nav_[% page.nav %].css. In the example above, 'nav_green.css'. Be sure
216 to place style rules for your navigation template(s) in appropriately named
217 files.
218  
219 =item page.head.stylesheets
220  
221 [%
222 page.head.stylesheets.push('widgets.css', 'widgets.css', page_name _ '.css',
223 'http://somedomain.com/hosted/stylesheet.css');
224 %]
225  
226 Holds an array of css file names/URIs. Each entry will be added to the head
227 element after locating the resource URI using the static macro. Duplicates will
228 be ignored. Filenames will be prepended with /css and absolute URIs will be
229 left alone. Local files will also be versioned according to the configuration
230 of static_build (see above).
231  
232 The above example will produce the following links:
233  
234 <link rel="stylesheet" type="text/css" href="http://mydomain.com/static/css/widgets.css?ver=20070907" media="screen">
235 <link rel="stylesheet" type="text/css" href="http://mydomain.com/static/css/foo.css?ver=20070907" media="screen">
236 <link rel="stylesheet" type="text/css" href="http://somedomain.com/hosted/stylesheet.css" media="screen">
237  
238 Note that screen.css and nav_[% page.nav %].css are added to the head separately
239 and before any page.head.stylesheets.
240  
241 =item page.head.scripts
242  
243 [%
244 page.head.scripts.push('widgets.js', 'widgets.js', page_name _ '.js',
245 'http://somedomain.com/hosted/script.js');
246 %]
247  
248 Holds an array of javascript file names/URIs. Works in the same fashion as
249 page.head.stylesheets.
250  
251 Note that it is generally preferable from a performance standpoint to place
252 script tags at the bottom of the body tag. For this reason, it is advisable to
253 use page.body.scripts rather than this.
254  
255 =item page.body.id
256  
257 Apply an ID to the body tag
258  
259 =item page.body.classes
260  
261 [%
262 page.body.classes.push('foo','foo','bar');
263 %]
264  
265 Holds an array of class names to add to the body tag. Duplicates are ignored.
266  
267 Note that html.tt automatically adds classes 'IE' and 'IE(5|6|7)' to the body
268 tag using conditional comments. These will only be added when the requesting
269 browser is Internet Explorer. This is useful for adding style rules to target
270 IE without resorting to css hacks.
271  
272 =item page.body.scripts
273  
274 Works exactly as page.head.scripts, except it adds script tags to the very end of the body content.
275  
276 =item page.content_class
277  
278 [% page.content_class = 'wide_content' %]
279  
280 Used by html.tt, assigned to the class of the div containing the page content.
281 Also used by layouts as a default container class. See the info on the layouts
282 below. Default value is 'content'.
283  
284 =back
285  
286 =head2 html.tt points of interest
287  
288 html.tt creates the html, head and body elements of each page. As noted above,
289 it references many of the page.* variables to populate these sections.
290  
291 =over 4
292  
293 =item HTML 4.01 strict DOCTYPE
294  
295 Per the recommendation of the w3c, the broadcasted DOCTYPE is HTML 4.01 strict.
296 It was either this or XHTML 1.0 strict, but since you're likely delivering your
297 pages with Content-Type header set to 'text/html', this is more correct. There
298 are arguments for and against using HTML 4.01 instead of XHTML 1.0, but it's
299 probably not worth the reading, since you really just want to get stuff done.
300  
301 That said, please use HTML style closed tags or change the DOCTYPE in html.tt
302  
303 <p>This is<br>GOOD</p>
304 <p>This is<br/>a waste of a character</p>
305  
306 =item debug_init
307  
308 [% # in some PRE_PROCESS template
309 MACRO devel_env BLOCK;
310 ...etc...
311 END;
312  
313 debug_init = 'devel_env';
314 %]
315
316 If your server is running in debug mode, before anything, it checks if a
317 variable named debug_init is populated. If it is, it attempts to execute a
318 macro by the name assigned to the variable. This allows you to set up logging,
319 add scripts or stylesheets etc for use in development.
320  
321 =item IE detection
322  
323 html.tt uses IE conditional comments to decorate the body tag with a class 'IE'
324 and another class 'IE5', 'IE6', or 'IE7' depending on the version of the browser
325 requesting the page. Non-IE browsers will no have these classes added.
326  
327 This allows you to use the cascade in your css to target IE to correct display
328 issues that may*cough*WILL*cough* arise.
329  
330 /* Container dimensions */
331 .container {
332 width: 276px;
333 padding: 10px:
334 border: 2px solid #eee;
335 }
336  
337 /* correction for IE's box model */
338 .IE .container {
339 width: 300px;
340 }
341  
342 =item Header, content, and footer separation
343  
344 The header, content, and footer are rendered separately under the body element,
345 not wrapped in a global wrapping div. This was done to allow layouts to use
346 the full content width for header/footer if their design mandates, but keep a
347 narrower content area centered. If your design mandates consistent width, it's
348 probably easiest to move the open and close div tags surrounding [% content %]
349 to encompass the header and footer includes.
350  
351 =back
352  
353 =head2 Using layouts
354  
355 TODO: talk about the template vars and nesting
356  
357 =head1 AUTHOR
358  
359 Lucas Smith E<lt>lsmith@lucassmith.nameE<gt>
360  
361 =head1 VERSION
362  
363 TT Bootstrap version 0.1, released Sept 7, 2007
364  
365 =head1 COPYRIGHT
366  
367 Copyright (C) Lucas Smith. All Rights Reserved.
368  
369 This module is free software; you can redistribute it and/or
370 modify it under the same terms as Perl itself.
371  
372 =cut