Catalyst-Helper-View-TT-Bootstrap-YUI
view release on metacpan or search on metacpan
lib/Catalyst/Helper/View/TT/Bootstrap/YUI.pm view on Meta::CPAN
If you already have a TT view in your application, make sure to include the
other directives that are created by the helper. Typically, this file is
simply C<MyApp/lib/MyApp/View/TT.pm.new> if a file exists with the same name.
See L<Catalyst::Helper::View::TT::Bootstrap::YUI::Manual> for more details on
available variables and macros, and how to work with the layouts.
=head2 METHODS
=head3 mk_compclass
Generates the component class.
=head3 mk_templates
Generates the templates.
=cut
=head1 SEE ALSO
L<Catalyst>, L<Catalyst::View::TT>, L<Catalyst::Helper>,
L<Catalyst::Helper::View::TT>
=head1 AUTHORS
Jay Shirley <jshirley@cpan.org>
Lucas Smith <lsmith@lucassmith.name>
=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 parent 'Catalyst::View::TT';
use Scalar::Util qw(blessed);
use DateTime::Format::DateParse;
__PACKAGE__->config({
PRE_PROCESS => 'site/shared/base.tt',
WRAPPER => 'site/wrapper.tt',
TEMPLATE_EXTENSION => '.tt',
TIMER => 0,
static_root => '/static',
static_build => 0,
default_tz => 'America/Los_Angeles',
default_locale => 'en_US',
formats => {
date => {
date => '%x',
short => '%b %e, %G',
long => '%X %x',
}
}
});
sub template_vars {
my $self = shift;
return (
$self->next::method(@_),
static_root => $self->{static_root},
static_build => $self->{static_build}
);
}
sub new {
my ( $class, $c, $arguments ) = @_;
my $formats = $class->config->{formats};
return $class->next::method( $c, $arguments ) unless ref $formats eq 'HASH';
$class->config->{FILTERS} ||= {};
my $filters = $class->config->{FILTERS};
foreach my $key ( keys %$formats ) {
if ( $key eq 'date' ) {
foreach my $date_key ( keys %{$formats->{$key}} ) {
$filters->{"${key}_$date_key"} = sub {
my $date = shift;
return unless defined $date;
unless ( blessed $date and $date->can("stringify") ) {
$date = DateTime::Format::DateParse->parse_datetime($date);
}
unless ( $date ) { return $date; }
$date->set_locale($class->config->{default_locale})
if defined $class->config->{default_locale};
# Only apply a timezone if we have a complete date.
unless ( "$date" =~ /T00:00:00$/ ) {
$date->set_time_zone( $class->config->{default_tz} || 'America/Los_Angeles' );
}
$date->strftime($formats->{$key}->{$date_key});
};
}
}
}
return $class->next::method( $c, $arguments );
}
=head1 NAME
[% class %] - Catalyst TT::Bootstrap::YUI View
=head1 SYNOPSIS
See L<[% app %]>
=head1 DESCRIPTION
Catalyst TT::Bootstrap::YUI 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;
__shared_base__
[%~ TAGS star %]
[%~
MACRO ref(var) BLOCK;
var_ref = "$var";
var_ref.match('^([A-Z]+)\\(0x[0-9a-f]+\\)$').0;
END;
# Wraps c.uri_for to point to static resources either inside the
# /root/static structure or explicit URIs. Assumes
MACRO static(res, versioned, query) BLOCK;
uri_params = query || {};
IF res.match('^https?://') || res.match('^/');
res;
ELSIF versioned && static_build;
uri_params.ver = uri_params.ver || static_build;
c.uri_for( static_root, res, uri_params );
ELSE;
c.uri_for( static_root, res );
END;
END;
( run in 0.552 second using v1.01-cache-2.11-cpan-ceb78f64989 )