RapidApp

 view release on metacpan or  search on metacpan

lib/RapidApp/Template/Controller.pm  view on Meta::CPAN


    $c->dispatcher->register( $c => Catalyst::Action->new({
      name      => 'tpl',
      code      => $self->can('tpl'),
      class     => $self->meta->name,
      namespace => $ns,
      reverse   => join('/',$ns,'tpl'),
      attributes => {
        Chained    => ['/'],
        PathPrefix => [''],
      }
    }));
  }
  
  if($self->edit_alias_path) {
    my $path = $self->edit_alias_path;
    $path =~ s/^\///;
    $c->dispatcher->register( $c => Catalyst::Action->new({
      name      => 'tple',
      code      => $self->can('tple'),
      class     => $self->meta->name,
      namespace => $ns,
      reverse   => join('/',$ns,'tple'),
      attributes => {
        Chained    => ['/'],
        PathPrefix => [''],
      }
    }));
  }
}



sub tpl_path {
  my $self = shift;
  # Return the edit alias patgh first or fall back to the read alias:
  return $self->edit_alias_path || $self->read_alias_path;
}
## -----


has 'context_class', is => 'ro', default => 'RapidApp::Template::Context';
has 'provider_class', is => 'ro', default => 'RapidApp::Template::Provider';
has 'access_class', is => 'ro', default => 'RapidApp::Template::Access';
has 'access_params', is => 'ro', isa => 'HashRef', default => sub {{}};
has 'include_paths', is => 'ro', isa => 'ArrayRef[Str]', default => sub {[]};
has 'store_class', is => 'ro',  default => sub {undef}; # Will be 'RapidApp::Template::Store' if undef
has 'store_params', is => 'ro', default => sub {undef};


# -- 
# Only these TT plugins and filters will be allowed in Templates
# This is *very* important for security if non-admin users will
# have access to modify templates. These templates and filters
# are from the built-in list and are known to be safe. Examples
# of unsafe plugins are things like 'Datafile' and 'DBI', and
# examples of unsafe filters are things like 'eval', 'redirect', etc.
# It is critical that these types of things are never exposed
# to web interfaces. It is also important to note that TT was
# not originally designed with "limited" access in mind - it was
# only meant to be used by the programmer, not users. In hindsight,
# it might have been better to go with Text::Xslate for this reason
#
# (note: these get accessed/used within RapidApp::Template::Context)
has 'allowed_plugins', is => 'ro', default => sub {[qw(
  Assert Date Dumper Format HTML Iterator 
  Scalar String Table URL Wrap
)]}, isa => 'ArrayRef';

has 'allowed_filters', is => 'ro', default => sub {[qw(
  format upper lower ucfirst lcfirst trim collapse 
  html html_entity xml html_para html_break 
  html_para_break html_line_break uri url indent 
  truncate repeat remove replace null
)]}, isa => 'ArrayRef';
# --

has 'default_template_extension', is => 'ro', isa => 'Maybe[Str]', default => 'tt';

# If true, mouse-over edit controls will always be available for editable
# templates. Otherwise, query string ?editable=1 is required. Note that
# editable controls are *only* available in the context of an AutoPanel tab
has 'auto_editable', is => 'ro', isa => 'Bool', default => 0;

has 'Access', is => 'ro', lazy => 1, default => sub {
  my $self = shift;
  Module::Runtime::require_module($self->access_class);
  return $self->access_class->new({ 
    %{ $self->access_params },
    Controller => $self 
  });
}, isa => 'RapidApp::Template::Access';

# Maintain two separate Template instances - one that wraps divs and one that
# doesn't. Can't use the same one because compiled templates are cached
has 'Template_raw', is => 'ro', lazy => 1, default => sub {
  my $self = shift;
  return $self->_new_Template({ div_wrap => 0 });
}, isa => 'Template';

has 'Template_wrap', is => 'ro', lazy => 1, default => sub {
  my $self = shift;
  return $self->_new_Template({ div_wrap => 1 });
}, isa => 'Template';

sub _new_Template {
  my ($self,$opt) = @_;
  Module::Runtime::require_module($self->context_class);
  Module::Runtime::require_module($self->provider_class);
  return Template->new({
    CONTEXT => $self->context_class->new({
      Controller => $self,
      Access => $self->Access,
      # TODO: turn STRICT back on once I figure out how to make the errors useful:
      #STRICT => 1,
      LOAD_TEMPLATES => [
        $self->provider_class->new({
          Controller => $self,
          Access => $self->Access,
          store_class  => $self->store_class,
          store_params => $self->store_params,



( run in 0.842 second using v1.01-cache-2.11-cpan-71847e10f99 )