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

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 {

lib/Catalyst/Helper/View/TT/Bootstrap/YUI.pm  view on Meta::CPAN

    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});
                };
            }
        }
    }

lib/Catalyst/Helper/View/TT/Bootstrap/YUI/Manual.pm  view on Meta::CPAN


The generated View sets the following configuration key/values:

 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 => {
    # All date formats to define:
    date => {
        'date'  => '%D',
        'short' => '%b %e, %G',
        'long'  => '%F %l:%M %p'
    }
 }

=head3 Formatting and Dynamic Filters

The generated View.pm class defines filters for (at the moment) doing DateTime
formatting, complete with locale and timezone settings.

Either a DateTime object or a string that can be parsed as a Date/Time can be
passed in to the filters:

    [% dt_object | date_long %]

This will set the timezone, and then format according to the configuration.

If you just have a string, it is useful for doing standard date formatting
in your application:



( run in 0.676 second using v1.01-cache-2.11-cpan-ceb78f64989 )