Skip to content

Commit

Permalink
improve rendering of built-in templates to show actual template names…
Browse files Browse the repository at this point in the history
… in log messages
  • Loading branch information
kraih committed Oct 20, 2015
1 parent 429563e commit c810342
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -2,6 +2,8 @@
6.25 2015-10-20
- Improved Mojo::DOM::CSS to support selectors with leading and trailing
whitespace.
- Improved rendering of built-in templates to show actual template names in
log messages.
- Fixed "0" value bug in Mojo::JSON::Pointer.

6.24 2015-10-13
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -105,14 +105,14 @@ sub _development {
status => $page eq 'exception' ? 500 : 404,
template => "$page.$mode"
};
my $inline = $renderer->_bundled($mode eq 'development' ? $mode : $page);
return $c if _fallbacks($c, $options, $page, $inline);
_fallbacks($c, {%$options, format => 'html'}, $page, $inline);
my $bundled = 'mojo/' . ($mode eq 'development' ? $mode : $page);
return $c if _fallbacks($c, $options, $page, $bundled);
_fallbacks($c, {%$options, format => 'html'}, $page, $bundled);
return $c;
}

sub _fallbacks {
my ($c, $options, $template, $inline) = @_;
my ($c, $options, $template, $bundled) = @_;

# Mode specific template
return 1 if $c->render_maybe(%$options);
Expand All @@ -124,7 +124,7 @@ sub _fallbacks {
my $stash = $c->stash;
return undef unless $stash->{format} eq 'html';
delete @$stash{qw(extends layout)};
return $c->render_maybe(%$options, inline => $inline, handler => 'ep');
return $c->render_maybe($bundled, %$options, handler => 'ep');
}

sub _inactivity_timeout {
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -77,8 +77,7 @@ sub _html {

# Combine everything to a proper response
$c->content_for(perldoc => "$dom");
my $template = $c->app->renderer->_bundled('perldoc');
$c->render(inline => $template, title => $title, parts => \@parts);
$c->render('mojo/perldoc', title => $title, parts => \@parts);
}

sub _perldoc {
Expand Down
13 changes: 5 additions & 8 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -24,10 +24,8 @@ has helpers => sub { {} };
has paths => sub { [] };

# Bundled templates
my $HOME = Mojo::Home->new;
$HOME->parse(
$HOME->parse($HOME->mojo_lib_dir)->rel_dir('Mojolicious/templates'));
my %TEMPLATES = map { $_ => slurp $HOME->rel_file($_) } @{$HOME->list_files};
my $TEMPLATES = Mojo::Home->new(Mojo::Home->new->mojo_lib_dir)
->rel_dir('Mojolicious/templates');

sub DESTROY { Mojo::Util::_teardown($_) for @{shift->{namespaces}} }

Expand Down Expand Up @@ -201,16 +199,14 @@ sub template_path {
return undef unless my $name = $self->template_name(shift);

# Search all paths
for my $path (@{$self->paths}) {
for my $path (@{$self->paths}, $TEMPLATES) {
my $file = catfile $path, split('/', $name);
return $file if -r $file;
}

return undef;
}

sub _bundled { $TEMPLATES{"@{[pop]}.html.ep"} }

sub _extends {
my ($self, $stash) = @_;
my $layout = delete $stash->{layout};
Expand Down Expand Up @@ -240,7 +236,8 @@ sub _warmup {

# Handlers for templates
s/\.(\w+)$// and push @{$templates->{$_}}, $1
for map { sort @{Mojo::Home->new($_)->list_files} } @{$self->paths};
for map { sort @{Mojo::Home->new($_)->list_files} } @{$self->paths},
$TEMPLATES;

# Handlers and classes for DATA templates
for my $class (reverse @{$self->classes}) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Static.pm
Expand Up @@ -13,8 +13,8 @@ has classes => sub { ['main'] };
has paths => sub { [] };

# Bundled files
my $HOME = Mojo::Home->new;
my $PUBLIC = $HOME->parse($HOME->mojo_lib_dir)->rel_dir('Mojolicious/public');
my $PUBLIC = Mojo::Home->new(Mojo::Home->new->mojo_lib_dir)
->rel_dir('Mojolicious/public');

sub dispatch {
my ($self, $c) = @_;
Expand Down
Expand Up @@ -129,7 +129,7 @@
</style>
</head>
<body>
%= include inline => app->renderer->_bundled('mojobar')
%= include 'mojo/mojobar'
<script>
function mojoDrawer (handle, drawer) {
$(handle).click(function () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -90,7 +90,7 @@
</style>
</head>
<body>
%= include inline => app->renderer->_bundled('mojobar')
%= include 'mojo/mojobar'
<div id="wrapperlicious">
<div id="perldoc">
<div id="source">
Expand Down

0 comments on commit c810342

Please sign in to comment.