File Coverage

blib/lib/Catalyst/Helper/View/TTSimple.pm
Criterion Covered Total %
statement 9 34 26.4
branch n/a
condition n/a
subroutine 3 5 60.0
pod 2 2 100.0
total 14 41 34.1


line stmt bran cond sub pod time code
1             package Catalyst::Helper::View::TTSimple;
2              
3 2     2   35833 use warnings;
  2         6  
  2         69  
4 2     2   11 use strict;
  2         3  
  2         66  
5 2     2   12 use File::Spec;
  2         11  
  2         856  
6              
7             =head1 NAME
8              
9             Catalyst::Helper::View::TTSimple - Simplified TT layout for building web sites.
10              
11             =cut
12              
13             our $VERSION = '0.01';
14              
15             =head1 SYNOPSIS
16              
17             use the helper to build the view module and associated templates.
18              
19             $ script/myapp_create.pl view TT TTSimple
20              
21             =head1 DESCRIPTION
22              
23             This helper module creates a simple TT skeleton layout in your catalyst project. It goes further than Catalyst::Helper::View::TT and a bit less than Catalyst:Helper::View::TTSite in that it creates just the bare essentials to get you started.
24              
25             =head2 What gets generated?
26              
27             This creates a xhtml layout container, javascript directory, stylesheet directory and a TT index which would be encapsulated by the layout. If you have ever worked with Rails this should be very familiar to you.
28              
29             project_root/
30             root/
31             site/
32             layout (the xhtml layout)
33             wrapper (wraps content to layout)
34             config/
35             main (main configuration processed before anything)
36             src/
37             index.tt2 (encapsulated index file)
38              
39              
40             =cut
41              
42             =head2 METHODS
43              
44             =head3 mk_compclass
45              
46             Generates the component class.
47              
48             =head3 mk_templates
49              
50             Generates the templates.
51              
52             =cut
53              
54             sub mk_compclass {
55 0     0 1   my ( $self, $helper, @args ) = @_;
56 0           my $file = $helper->{file};
57 0           $helper->render_file( 'compclass', $file );
58 0           $self->mk_templates( $helper, @args );
59             }
60              
61             sub mk_templates {
62 0     0 1   my ($self,$helper)=@_;
63            
64 0           my $base = $helper->{base};
65 0           my $stdir = File::Spec->catfile($base, 'root', 'static' , 'stylesheets');
66 0           my $jtdir = File::Spec->catfile($base, 'root', 'static' , 'javascripts');
67 0           my $idir = File::Spec->catfile($base,'root', 'static' , 'images');
68 0           my $ldir = File::Spec->catfile( $base, 'root', 'lib' );
69 0           my $sdir = File::Spec->catfile( $base, 'root', 'src' );
70 0           my $cdir = File::Spec->catfile( $ldir, 'config' );
71 0           my $sitedir = File::Spec->catfile( $ldir, 'site' );
72            
73 0           $helper->mk_dir($ldir);
74 0           $helper->mk_dir($sdir);
75 0           $helper->mk_dir($stdir);
76 0           $helper->mk_dir($jtdir);
77 0           $helper->mk_dir($cdir);
78 0           $helper->mk_dir($sitedir);
79              
80 0           $helper->render_file( "config_main",
81             File::Spec->catfile( $cdir, "main" ) );
82              
83 0           foreach my $file (qw( wrapper layout )) {
84 0           $helper->render_file( "site_$file",
85             File::Spec->catfile( $sitedir, $file ) );
86             }
87            
88 0           $helper->mk_file(File::Spec->catfile($jtdir,'application.js'),'');
89 0           $helper->mk_file(File::Spec->catfile($stdir,'master.css'),'');
90 0           $helper->render_file("index.tt2", File::Spec->catfile($sdir,'index.tt2'));
91             }
92              
93             =head1 AUTHOR
94              
95             Victor Igumnov, C<< <victori at lamer0.com> >>
96              
97             =head1 BUGS
98              
99             Please report any bugs or feature requests to
100             C<bug-catalyst-helper-view-ttsimple at rt.cpan.org>, or through the web interface at
101             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Helper-View-TTSimple>.
102             I will be notified, and then you'll automatically be notified of progress on
103             your bug as I make changes.
104              
105             =head1 SUPPORT
106              
107             You can find documentation for this module with the perldoc command.
108              
109             perldoc Catalyst::Helper::View::TTSimple
110              
111             You can also look for information at:
112              
113             =over 4
114              
115             =item * AnnoCPAN: Annotated CPAN documentation
116              
117             L<http://annocpan.org/dist/Catalyst-Helper-View-TTSimple>
118              
119             =item * CPAN Ratings
120              
121             L<http://cpanratings.perl.org/d/Catalyst-Helper-View-TTSimple>
122              
123             =item * RT: CPAN's request tracker
124              
125             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Helper-View-TTSimple>
126              
127             =item * Search CPAN
128              
129             L<http://search.cpan.org/dist/Catalyst-Helper-View-TTSimple>
130              
131             =back
132              
133             =head1 ACKNOWLEDGEMENTS
134              
135             =head1 COPYRIGHT & LICENSE
136              
137             Copyright 2006 Victor Igumnov, all rights reserved.
138              
139             This program is free software; you can redistribute it and/or modify it
140             under the same terms as Perl itself.
141              
142             =cut
143              
144              
145             1;
146              
147             __DATA__
148              
149             __compclass__
150             package [% class %];
151              
152             use strict;
153             use base 'Catalyst::View::TT';
154              
155             __PACKAGE__->config({
156             CATALYST_VAR => 'c',
157             INCLUDE_PATH => [
158             [% app %]->path_to( 'root', 'src' ),
159             [% app %]->path_to( 'root', 'lib' )
160             ],
161             PRE_PROCESS => 'config/main',
162             WRAPPER => 'site/wrapper',
163             TIMER => 0
164             });
165            
166              
167             =head1 NAME
168              
169             [% class %] - Catalyst TTSimple View
170              
171             =head1 SYNOPSIS
172              
173             See L<[% app %]>
174              
175             =head1 DESCRIPTION
176              
177             Catalyst TTSimple View.
178              
179             =head1 AUTHOR
180              
181             [% author %]
182              
183             =head1 LICENSE
184              
185             This library is free software, you can redistribute it and/or modify
186             it under the same terms as Perl itself.
187              
188             =cut
189              
190             1;
191              
192             __config_main__
193             [% USE Date;
194             year = Date.format(Date.now, '%Y');
195             -%]
196             [% TAGS star -%]
197             [% # config/main
198             #
199             # This is the main configuration template which is processed before
200             # any other page, by virtue of it being defined as a PRE_PROCESS
201             # template. This is the place to define any extra template variables,
202             # macros, load plugins, and perform any other template setup.
203              
204             IF Catalyst.debug;
205             # define a debug() macro directed to Catalyst's log
206             MACRO debug(message) CALL Catalyst.log.debug(message);
207             END;
208              
209             # define a data structure to hold sitewide data
210             site = {
211             title => 'Catalyst::View::TTSimple Example Page',
212             copyright => '[* year *] Your Name Here',
213             };
214              
215             -%]
216              
217             __site_wrapper__
218             [% TAGS star -%]
219             [% IF template.name.match('\.(css|js|txt)');
220             debug("Passing page through as text: $template.name");
221             content;
222             ELSE;
223             debug("Applying HTML page layout wrappers to $template.name\n");
224             content WRAPPER site/layout;
225             END;
226             -%]
227              
228             __site_layout__
229             [% USE Date;
230             year = Date.format(Date.now, '%Y');
231             -%]
232             <?xml version="1.0" encoding="utf-8"?>
233             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
234             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
235             <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
236             <head>
237             <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
238             <meta http-equiv="Content-Language" content="en-us" />
239            
240             <meta name="ROBOTS" content="ALL" />
241             <meta http-equiv="imagetoolbar" content="no" />
242             <meta name="MSSmartTagsPreventParsing" content="true" />
243             <meta name="Copyright" content="(c) [% year %] Copyright content: Copyright design: your name" />
244             <!-- (c) Copyright [% year %] by your name All Rights Reserved. -->
245            
246             <meta name="Keywords" content="__KEYWORDS__" />
247             <meta name="Description" content="__DESCRIPTION__" />
248            
249             [% TAGS star -%]
250             <title>[% site.title %]</title>
251            
252             <link href="/static/stylesheets/master.css" rel="stylesheet" type="text/css" media="all" />
253            
254             <!-- import the DOM logic from external javascript files -->
255             <script type="text/javascript" src="/static/javascripts/application.js"></script>
256             </head>
257            
258             <body>
259             [% content %]
260             </body>
261             </html>
262              
263             __index.tt2__
264             <p>Welcome to your Simple TT View!</p>