Catalyst-View-Haml
view release on metacpan or search on metacpan
lib/Catalyst/View/Haml.pm view on Meta::CPAN
package Catalyst::View::Haml;
use Moose;
use Text::Haml;
use Path::Class::File;
use Encode;
use Carp;
use Try::Tiny;
use namespace::autoclean;
extends 'Catalyst::View';
our $VERSION = '1.00';
has 'haml' => ( is => 'rw', isa => 'Text::Haml' );
has 'catalyst_var' => ( is => 'rw', isa => 'Str', default => 'c' );
has 'template_extension' => ( is => 'rw', isa => 'Str', default => '.haml' );
has 'path' => ( is => 'rw', isa => 'ArrayRef' );
has 'charset' => ( is => 'rw', isa => 'Str', default => 'utf-8' );
has 'format' => (
is => 'rw',
isa => 'Str',
default => 'xhtml',
trigger => sub { \&_reset_attribute('format', @_) },
);
has 'vars_as_subs' => (
is => 'rw',
isa => 'Bool',
default => 0,
trigger => sub { \&_reset_attribute('vars_as_subs', @_) },
);
has 'escape_html' => (
is => 'rw',
isa => 'Bool',
default => 1,
trigger => sub { \&_reset_attribute('escape_html', @_) },
);
sub _reset_attribute {
my ($method_name, $self, $value )= @_;
$self->_build_haml() unless $self->haml;
$self->haml->$method_name( $value );
}
sub _build_haml {
my ($self, $c) = @_;
my $haml = Text::Haml->new(
vars_as_subs => $self->vars_as_subs,
encoding => $self->charset,
escape_html => $self->escape_html,
format => $self->format,
);
$self->path([ $c->path_to('root') ]) unless $self->path;
$self->haml( $haml );
}
sub ACCEPT_CONTEXT {
my ($self, $c) = @_;
( run in 2.603 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )