PerlDancer / PerlDancer/Dancer2
Having multiple views directory support, AngularJS structure
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
I am writing a slew of apps based on angularjs, grunt, bower and yeoman. I like their setup and would not like to change that ... however I do need be able to present the partial layouts and template views. Hence the need for the template engine to look at more than one directory. Hence my enhancement to both default_tmpl_ext and views to be able to support generation of the angularjs template with extension *.html under ./app/ and ./app/views directories.
Here the suggested changes to accomplish this...
in config.yml specify list of view directories.
views:
- ./app
- ./app/views
default_tmpl_ext: html
in Role::Template.pm line 45, I have the isa commented out since it can be an array or a single entry.
has views => (
is => 'rw',
#isa => Maybe [Array],
);
in Role::Template.pm line 95 -105 - adding multiple view support in apply_renderer subroutine.
sub apply_renderer {
my ( $self, $view, $tokens ) = @_;
$tokens = $self->_prepare_tokens_options($tokens);
$self->execute_hook( 'engine.template.before_render', $tokens );
my $viewarray = ref $self->views eq 'ARRAY' ? $self->views : [ $self->views ];
my $content;
foreach my $v ( @{ $viewarray } ) {
my $vt = path( $v, $self->_template_name($view) );
if ( -f $vt ) {
$content = $self->render( $vt, $tokens );
last;
} else {
printf "warning: template %s not found!\n",$vt;
}
}
$self->execute_hook( 'engine.template.after_render', \$content );
# make sure to avoid ( undef ) in list context return
defined $content and return $content;
return;
}
in Core:App I have added the template extensions, I needed it to just use yeoman and angularjs generated templates for their views. (line 163)
$engine_attrs->{default_tmpl_ext} ||= $config->{default_tmpl_ext} || 'tt';
NOTE: I know here is a default_tmpl_ext property in the template however it cannot be reached configuration wise, the only thing that is in the config has his location and environment....
in Template::TemplateToolkit.pm adding the new view paths to the Template Toolkit include path so they can be found.
my $view = [$self->views] if ref($self->views) ne 'ARRAY';
$tt_config{'INCLUDE_PATH'} ||= $view;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review config.yml and the mentioned implementations in Role::Template.pm, Core::App, and Template::TemplateToolkit.pm. Start with the existing views and template-extension handling, then verify that both single and multiple view directories and the configured default extension work for AngularJS templates. Done means the requested configuration is supported consistently across rendering and Template Toolkit lookup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angularjs, perl
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100