| 1 | package Catalyst::Helper::View::TT::Bootstrap::YUI; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | our $VERSION = '0.02'; | ||
| 6 | |||
| 7 | use Path::Class; | ||
| 8 | |||
| 9 | sub mk_compclass { | ||
| 10 | my ( $self, $helper, @args ) = @_; | ||
| 11 | my $file = $helper->{file}; | ||
| 12 | $helper->render_file( 'compclass', $file ); | ||
| 13 | $self->mk_templates( $helper, @args ); | ||
| 14 | } | ||
| 15 | |||
| 16 | sub mk_templates { | ||
| 17 | my ( $self, $helper ) = @_; | ||
| 18 | |||
| 19 | # Build directory structure | ||
| 20 | # /{base}/root | ||
| 21 | my $root = dir( $helper->{base}, 'root' ); | ||
| 22 | $helper->mk_dir($root); | ||
| 23 | |||
| 24 | # /{base}/root/static ./css ./css/images ./scripts ./images | ||
| 25 | my $static = dir( $root, 'static' ); | ||
| 26 | $helper->mk_dir($static); | ||
| 27 | my $css = dir( $static, 'css' ); | ||
| 28 | $helper->mk_dir($css); | ||
| 29 | $helper->mk_dir( dir( $css, 'images' ) ); | ||
| 30 | $helper->mk_dir( dir( $static, 'images') ); | ||
| 31 | $helper->mk_dir( dir( $static, 'scripts') ); | ||
| 32 | |||
| 33 | # /{base}/root/site | ||
| 34 | my $site = dir( $root, 'site' ); | ||
| 35 | $helper->mk_dir($site); | ||
| 36 | |||
| 37 | # /{base}/root/site/shared | ||
| 38 | my $shared = dir( $site, 'shared' ); | ||
| 39 | $helper->mk_dir($shared); | ||
| 40 | |||
| 41 | # /{base}/root/site/layout | ||
| 42 | my $layout = dir( $site, 'layout' ); | ||
| 43 | $helper->mk_dir($layout); | ||
| 44 | |||
| 45 | # /{base}/root/site/header, navigation, and footer | ||
| 46 | my $header = dir( $site, 'header' ); | ||
| 47 | $helper->mk_dir($header); | ||
| 48 | my $nav = dir( $site, 'nav' ); | ||
| 49 | $helper->mk_dir($nav); | ||
| 50 | my $footer = dir( $site, 'footer' ); | ||
| 51 | $helper->mk_dir($footer); | ||
| 52 | |||
| 53 | # Render files | ||
| 54 | # /{base}/root/static/css files | ||
| 55 | $helper->render_file( "screen_css", file( $css, 'screen.css' ) ); | ||
| 56 | |||
| 57 | # /{base}/root/site files | ||
| 58 | $helper->render_file( "site_wrapper", file( $site, 'wrapper.tt' ) ); | ||
| 59 | $helper->render_file( "site_html", file( $site, 'html.tt' ) ); | ||
| 60 | |||
| 61 | # /{base}/root/site/shared files | ||
| 62 | $helper->render_file( "shared_base", file( $shared, 'base.tt' ) ); | ||
| 63 | |||
| 64 | # /{base}/root/site/layout files | ||
| 65 | $helper->render_file( "layout_default", file( $layout, 'default.tt' )); | ||
| 66 | #$helper->render_file( "layout_2columns", file( $layout, '2columns.tt' )); | ||
| 67 | #$helper->render_file( "layout_2col_left", file( $layout, '2col_left.tt' )); | ||
| 68 | #$helper->render_file( "layout_2col_right", file( $layout, '2col_right.tt')); | ||
| 69 | #$helper->render_file( "layout_3col", file( $layout, '3columns.tt' ) ); | ||
| 70 | |||
| 71 | # /{base}/root/site/header, navigation, and footer files | ||
| 72 | $helper->render_file( "header_default", file( $header, 'default.tt' )); | ||
| 73 | $helper->render_file( "nav_default", file( $nav, 'default.tt' )); | ||
| 74 | $helper->render_file( "footer_default", file( $footer, 'default.tt' )); | ||
| 75 | } | ||
| 76 | |||
| 77 | =head1 NAME | ||
| 78 | |||
| 79 | Catalyst::Helper::View::TT::Bootstrap::YUI - Generate TT templates using YUI | ||
| 80 | |||
| 81 | =head1 SYNOPSIS | ||
| 82 | |||
| 83 | Helper for TT view. Creates the C<MyAppView/TT.pm> file and a template | ||
| 84 | directory structure under MyApp/root containing templates, macros, and | ||
| 85 | links to the hosted version of the YUI C<reset-fonts-grids.css> file. | ||
| 86 | |||
| 87 | Use the helper to create the view module and templates: | ||
| 88 | |||
| 89 | $ script/myapp_create.pl view TT TT::Bootstrap::YUI | ||
| 90 | |||
| 91 | The stash key for configuring everything is C<< $c->stash->{page} >> with | ||
| 92 | defaults in C<MyApp/root/site/shared/base.tt>. | ||
| 93 | |||
| 94 | Add something like the following to the page templates for your application | ||
| 95 | |||
| 96 | [%~ | ||
| 97 | page.layout = '2columns'; # use a 2 column layout (default is 'default') | ||
| 98 | page.header = 'my_custom'; # will load root/site/header/my_custom.tt | ||
| 99 | page.footer = 'none'; # don't display a footer | ||
| 100 | |||
| 101 | # adds these <link rel="stylsheet"...> tags to the <head> | ||
| 102 | page.head.stylesheets.push('foo.css','bar.css'); | ||
| 103 | |||
| 104 | # adds these <script> tags to the <head> | ||
| 105 | page.head.scripts.push('foo.js','bar.js'); | ||
| 106 | |||
| 107 | # adds these <script> tags to the bottom of the <body> -- usually preferable | ||
| 108 | page.body.scripts.push('baz.js','poop.js'); | ||
| 109 | |||
| 110 | # adds these classes to the <body> tag | ||
| 111 | page.body.classes.push('foo','bar'); | ||
| 112 | ~%] | ||
| 113 | ...your content here... | ||
| 114 | |||
| 115 | =head1 DESCRIPTION | ||
| 116 | |||
| 117 | This helper module creates a L<Catalyst::View::TT> class in your application. | ||
| 118 | It also creates a set of templates, macros, and a stylesheet to let you focus | ||
| 119 | on the content of your apps pages sooner with less copy and pasting. | ||
| 120 | |||
| 121 | It also provides a mechanism for adding dynamic filters, for doing things | ||
| 122 | like date formatting. | ||
| 123 | |||
| 124 | If you already have a TT view in your application, make sure to include the | ||
| 125 | other directives that are created by the helper. Typically, this file is | ||
| 126 | simply C<MyApp/lib/MyApp/View/TT.pm.new> if a file exists with the same name. | ||
| 127 | |||
| 128 | See L<Catalyst::Helper::View::TT::Bootstrap::YUI::Manual> for more details on | ||
| 129 | available variables and macros, and how to work with the layouts. | ||
| 130 | |||
| 131 | =head2 METHODS | ||
| 132 | |||
| 133 | =head3 mk_compclass | ||
| 134 | |||
| 135 | Generates the component class. | ||
| 136 | |||
| 137 | =head3 mk_templates | ||
| 138 | |||
| 139 | Generates the templates. | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | =head1 SEE ALSO | ||
| 144 | |||
| 145 | L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>, | ||
| 146 | L<Catalyst::Helper::View::TT> | ||
| 147 | |||
| 148 | =head1 AUTHORS | ||
| 149 | |||
| 150 | Jay Shirley <jshirley@cpan.org> | ||
| 151 | |||
| 152 | Lucas Smith <lsmith@lucassmith.name> | ||
| 153 | |||
| 154 | =head1 LICENSE | ||
| 155 | |||
| 156 | This library is free software . You can redistribute it and/or modify | ||
| 157 | it under the same terms as perl itself. | ||
| 158 | |||
| 159 | =cut | ||
| 160 | |||
| 161 | 1; | ||
| 162 | |||
| 163 | __DATA__ |