<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Catalyst::Helper::View::TTSite;

use strict;
use File::Spec;

sub mk_compclass {
    my ( $self, $helper, @args ) = @_;
    my $file = $helper-&gt;{file};
    $helper-&gt;render_file( 'compclass', $file );
    $self-&gt;mk_templates( $helper, @args );
}

sub mk_templates {
    my ( $self, $helper ) = @_;
    my $base = $helper-&gt;{base},;
    my $ldir = File::Spec-&gt;catfile( $base, 'root', 'lib' );
    my $sdir = File::Spec-&gt;catfile( $base, 'root', 'src' );

    $helper-&gt;mk_dir($ldir);
    $helper-&gt;mk_dir($sdir);

    my $dir = File::Spec-&gt;catfile( $ldir, 'config' );
    $helper-&gt;mk_dir($dir);

    foreach my $file (qw( main col url )) {
        $helper-&gt;render_file( "config_$file",
            File::Spec-&gt;catfile( $dir, $file ) );
    }

    $dir = File::Spec-&gt;catfile( $ldir, 'site' );
    $helper-&gt;mk_dir($dir);

    foreach my $file (qw( wrapper layout html header footer )) {
        $helper-&gt;render_file( "site_$file",
            File::Spec-&gt;catfile( $dir, $file ) );
    }

    foreach my $file (qw( welcome.tt2 message.tt2 error.tt2 ttsite.css )) {
        $helper-&gt;render_file( $file, File::Spec-&gt;catfile( $sdir, $file ) );
    }

}

=head1 NAME

Catalyst::Helper::View::TTSite - Helper for TT view which builds a skeleton web site

=head1 SYNOPSIS

# use the helper to create the view module and templates

    $ script/myapp_create.pl view HTML TTSite

# add something like the following to your main application module

    sub message : Global {
        my ( $self, $c ) = @_;
        $c-&gt;stash-&gt;{template} = 'message.tt2';
        $c-&gt;stash-&gt;{message}  ||= $c-&gt;req-&gt;param('message') || 'No message';
    }

    sub default : Private {
        my ( $self, $c ) = @_;
        $c-&gt;stash-&gt;{template} = 'welcome.tt2';
    }

    sub end : Private { # Or use Catalyst::Action::RenderView
        my ( $self, $c ) = @_;
        $c-&gt;forward( $c-&gt;view('HTML') );
    }

=head1 DESCRIPTION

This helper module creates a TT View module.  It goes further than
Catalyst::Helper::View::TT in that it additionally creates a simple
set of templates to get you started with your web site presentation.

It creates the templates in F&lt;root/&gt; directory underneath your
main project directory.  In here two further subdirectories are
created: F&lt;root/src&gt; which contains the main page templates, and F&lt;root/lib&gt;
containing a library of other template components (header, footer,
etc.) that the page templates use.

The view module that the helper creates is automatically configured
to locate these templates.

=head2 Default Rendering

To render a template the following process is applied:

The configuration template F&lt;root/lib/config/main&gt; is rendered. This is
controlled by the C&lt;PRE_PROCESS&gt; configuration variable set in the controller
generated by Catalyst::Helper::View::TTsite. Additionally, templates referenced by
the C&lt;PROCESS&gt; directive will then be rendered. By default the following additional
templates are set: F&lt;root/lib/config/col&gt;,
which defines color names and RGB their RGB values and F&lt;/root/lib/config/url&gt;,
which defines site wide variables available to templates.

Next, the template defined by the C&lt;WRAPPER&gt; config variable is called. The default
wrapper template is located in F&lt;root/lib/site/wrapper&gt;. The wrapper template
passes files with C&lt;.css/.js/.txt&gt; extensions through as text OR processes
the templates defined after the C&lt;WRAPPER&gt; directive: C&lt;site/html&gt; and C&lt;site/layout&gt;.

Based on the default value of the C&lt;WRAPPER&gt; directive in F&lt;root/lib/site/wrapper&gt;,
the following templates are processed in order:

=over 4

=item * F&lt;root/src/your_template.tt2&gt;

=item * F&lt;root/lib/site/footer&gt;

=item * F&lt;root/lib/site/header&gt;

=item * F&lt;root/lib/site/layout&gt;

=item * F&lt;root/lib/site/html&gt;

=back

Finally, the rendered content is returned to the bowser.

=head1 METHODS

=head2 mk_compclass

Generates the component class.

=head2 mk_templates

Generates the templates.

=cut

=head1 SEE ALSO

L&lt;Catalyst&gt;, L&lt;Catalyst::View::TT&gt;, L&lt;Catalyst::Helper&gt;,
L&lt;Catalyst::Helper::View::TT&gt;

=head1 AUTHOR

Andy Wardley &lt;abw@cpan.org&gt;

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as perl itself.

=cut

1;

__DATA__

__compclass__
package [% class %];

use strict;
use base 'Catalyst::View::TT';

__PACKAGE__-&gt;config({
    INCLUDE_PATH =&gt; [
        [% app %]-&gt;path_to( 'root', 'src' ),
        [% app %]-&gt;path_to( 'root', 'lib' )
    ],
    PRE_PROCESS  =&gt; 'config/main',
    WRAPPER      =&gt; 'site/wrapper',
    ERROR        =&gt; 'error.tt2',
    TIMER        =&gt; 0,
    render_die   =&gt; 1,
});

=head1 NAME

[% class %] - Catalyst TTSite View

=head1 SYNOPSIS

See L&lt;[% app %]&gt;

=head1 DESCRIPTION

Catalyst TTSite View.

=head1 AUTHOR

[% author %]

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;

__config_main__
[% USE Date;
   year = Date.format(Date.now, '%Y');
-%]
[% TAGS star -%]
[% # config/main
   #
   # This is the main configuration template which is processed before
   # any other page, by virtue of it being defined as a PRE_PROCESS
   # template.  This is the place to define any extra template variables,
   # macros, load plugins, and perform any other template setup.

   IF Catalyst.debug;
     # define a debug() macro directed to Catalyst's log
     MACRO debug(message) CALL Catalyst.log.debug(message);
   END;

   # define a data structure to hold sitewide data
   site = {
     title     =&gt; 'Catalyst::View::TTSite Example Page',
     copyright =&gt; '[* year *] Your Name Here',
   };

   # load up any other configuration items
   PROCESS config/col
         + config/url;

   # set defaults for variables, etc.
   DEFAULT
     message = 'There is no message';

-%]
__config_col__
[% TAGS star -%]
[% site.rgb = {
     black  = '#000000'
     white  = '#ffffff'
     grey1  = '#46494c'
     grey2  = '#c6c9cc'
     grey3  = '#e3e6ea'
     red    = '#CC4444'
     green  = '#66AA66'
     blue   = '#89b8df'
     orange = '#f08900'
   };

   site.col = {
      page    = site.rgb.white
      text    = site.rgb.grey1
      head    = site.rgb.grey3
      line    = site.rgb.orange
      message = site.rgb.green
      error   = site.rgb.red
   };
-%]
__config_url__
[% TAGS star -%]
[% base = Catalyst.req.base;

   site.url = {
     base    = base
     home    = "${base}welcome"
     message = "${base}message"
   }
-%]
__site_wrapper__
[% TAGS star -%]
[% IF template.name.match('\.(css|js|txt)');
     debug("Passing page through as text: $template.name");
     content;
   ELSE;
     debug("Applying HTML page layout wrappers to $template.name\n");
     content WRAPPER site/html + site/layout;
   END;
-%]
__site_html__
[% TAGS star -%]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;[% template.title or site.title %]&lt;/title&gt;
  &lt;style type="text/css"&gt;
[% PROCESS ttsite.css %]
  &lt;/style&gt;
 &lt;/head&gt;
 &lt;body&gt;
[% content %]
 &lt;/body&gt;
&lt;/html&gt;
__site_layout__
[% TAGS star -%]
&lt;div id="header"&gt;[% PROCESS site/header %]&lt;/div&gt;

&lt;div id="content"&gt;
[% content %]
&lt;/div&gt;

&lt;div id="footer"&gt;[% PROCESS site/footer %]&lt;/div&gt;
__site_header__
[% TAGS star -%]
&lt;!-- BEGIN site/header --&gt;
&lt;h1 class="title"&gt;[% template.title or site.title %]&lt;/h1&gt;
&lt;!-- END site/header --&gt;
__site_footer__
[% TAGS star -%]
&lt;!-- BEGIN site/footer --&gt;
&lt;div id="copyright"&gt;&amp;copy; [% site.copyright %]&lt;/div&gt;
&lt;!-- END site/footer --&gt;
__welcome.tt2__
[% TAGS star -%]
[% META title = 'Catalyst/TT View!' %]
&lt;p&gt;
  Yay!  You're looking at a page generated by the Catalyst::View::TT
  plugin module.
&lt;/p&gt;
&lt;p&gt;
  This is the welcome page.  Why not try the equally-exciting
  &lt;a href="[% site.url.message %]"&gt;Message Page&lt;/a&gt;?
&lt;/p&gt;
__message.tt2__
[% TAGS star -%]
[% META title = 'Catalyst/TT View!' %]
&lt;p&gt;
  Yay!  You're looking at a page generated by the Catalyst::View::TT
  plugin module.
&lt;/p&gt;
&lt;p&gt;
  We have a message for you: &lt;span class="message"&gt;[% message %]&lt;/span&gt;.
&lt;/p&gt;
&lt;p&gt;
  Why not try updating the message?  Go on, it's really exciting, honest!
&lt;/p&gt;
&lt;form action="[% site.url.message %]"
      method="POST" enctype="application/x-www-form-urlencoded"&gt;
 &lt;input type="text" name="message" value="[% message %]" /&gt;
 &lt;input type="submit" name="submit" value=" Update Message "/&gt;
&lt;/form&gt;
__error.tt2__
[% TAGS star -%]
[% META title = 'Catalyst/TT Error' %]
&lt;p&gt;
  An error has occurred.  We're terribly sorry about that, but it's
  one of those things that happens from time to time.  Let's just
  hope the developers test everything properly before release...
&lt;/p&gt;
&lt;p&gt;
  Here's the error message, on the off-chance that it means something
  to you: &lt;span class="error"&gt;[% error %]&lt;/span&gt;
&lt;/p&gt;
__ttsite.css__
[% TAGS star %]
html {
    height: 100%;
}

body {
    background-color: [% site.col.page %];
    color: [% site.col.text %];
    margin: 0px;
    padding: 0px;
    height: 100%;
}

#header {
    background-color: [% site.col.head %];
    border-bottom: 1px solid [% site.col.line %];
}

#footer {
    background-color: [% site.col.head %];
    text-align: center;
    border-top: 1px solid [% site.col.line %];
    position: absolute;
    bottom: 0;
    left: 0px;
    width: 100%;
    padding: 4px;
}

#content {
    padding: 10px;
}

h1.title {
    padding: 4px;
    margin: 0px;
}

.message {
    color: [% site.col.message %];
}

.error {
    color: [% site.col.error %];
}
</pre></body></html>