Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

let the renderer handle bundled templates

  • Loading branch information...
commit 79d2731c970245c8af8903f03e30da3c587e0374 1 parent e904f08
@kraih authored
View
7 lib/Mojo/Parameters.pm
@@ -6,7 +6,6 @@ use overload
fallback => 1;
use Mojo::Util qw(decode encode url_escape url_unescape);
-use Mojo::URL;
has charset => 'UTF-8';
has pair_separator => '&';
@@ -168,7 +167,7 @@ sub to_string {
my $charset = $self->charset;
if (defined(my $string = $self->{string})) {
$string = encode $charset, $string if $charset;
- return url_escape $string, "^$Mojo::URL::UNRESERVED!\$&'()*+,;=%:@/?";
+ return url_escape $string, '^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?';
}
# Build pairs
@@ -180,11 +179,11 @@ sub to_string {
# Escape and replace whitespace with "+"
$name = encode $charset, $name if $charset;
- $name = url_escape $name, "^$Mojo::URL::UNRESERVED!\$'()*,%:@/?";
+ $name = url_escape $name, '^A-Za-z0-9\-._~!$\'()*,%:@/?';
$name =~ s/\%20/\+/g;
if ($value) {
$value = encode $charset, $value if $charset;
- $value = url_escape $value, "^$Mojo::URL::UNRESERVED!\$'()*,%:@/?";
+ $value = url_escape $value, '^A-Za-z0-9\-._~!$\'()*,%:@/?';
$value =~ s/\%20/\+/g;
}
View
3  lib/Mojo/Path.pm
@@ -6,7 +6,6 @@ use overload
fallback => 1;
use Mojo::Util qw(encode url_escape url_unescape);
-use Mojo::URL;
has [qw(leading_slash trailing_slash)];
has parts => sub { [] };
@@ -99,7 +98,7 @@ sub to_string {
my $self = shift;
# Escape
- my $chars = "^$Mojo::URL::UNRESERVED$Mojo::URL::SUBDELIM:@";
+ my $chars = '^A-Za-z0-9\-._~!$&\'()*+,;=:@';
my @parts = map { url_escape(encode('UTF-8', $_), $chars) } @{$self->parts};
# Format
View
8 lib/Mojo/URL.pm
@@ -12,10 +12,6 @@ use Mojo::Util qw(punycode_decode punycode_encode url_escape url_unescape);
has [qw(fragment host port scheme userinfo)];
has base => sub { Mojo::URL->new };
-# Characters (RFC 3986)
-our $UNRESERVED = 'A-Za-z0-9\-._~';
-our $SUBDELIM = '!$&\'()*+,;=';
-
# "Homer, it's easy to criticize.
# Fun, too."
sub new { shift->SUPER::new->parse(@_) }
@@ -39,7 +35,7 @@ sub authority {
# Format
if (my $userinfo = $self->userinfo) {
- $authority .= url_escape($userinfo, "^$UNRESERVED$SUBDELIM\:") . '@';
+ $authority .= url_escape($userinfo, '^A-Za-z0-9\-._~!$&\'()*+,;=\:') . '@';
}
$authority .= lc($self->ihost || '');
if (my $port = $self->port) { $authority .= ":$port" }
@@ -225,7 +221,7 @@ sub to_string {
# Fragment
if (my $fragment = $self->fragment) {
- $url .= '#' . url_escape $fragment, "^$UNRESERVED$SUBDELIM%:@/?";
+ $url .= '#' . url_escape $fragment, '^A-Za-z0-9\-._~!$&\'()*+,;=%:@/?';
}
return $url;
View
4 lib/Mojo/UserAgent/Transactor.pm
@@ -214,7 +214,7 @@ sub _multipart {
if (ref $values eq 'HASH') {
$filename = delete $values->{filename} || $name;
$filename = encode $encoding, $filename if $encoding;
- $filename = url_escape $filename, "^$Mojo::URL::UNRESERVED";
+ $filename = url_escape $filename, '^A-Za-z0-9\-._~';
push @parts, $part->asset(delete $values->{file});
$headers->from_hash($values);
}
@@ -230,7 +230,7 @@ sub _multipart {
# Content-Disposition
$name = encode $encoding, $name if $encoding;
- $name = url_escape $name, "^$Mojo::URL::UNRESERVED";
+ $name = url_escape $name, '^A-Za-z0-9\-._~';
my $disposition = qq{form-data; name="$name"};
$disposition .= qq{; filename="$filename"} if $filename;
$headers->content_disposition($disposition);
View
30 lib/Mojolicious/Controller.pm
@@ -5,7 +5,6 @@ use Carp ();
use Mojo::ByteStream;
use Mojo::Cookie::Response;
use Mojo::Exception;
-use Mojo::Home;
use Mojo::Transaction::HTTP;
use Mojo::URL;
use Mojo::Util;
@@ -20,15 +19,6 @@ has match => sub {
};
has tx => sub { Mojo::Transaction::HTTP->new };
-# Bundled templates
-our $H = Mojo::Home->new;
-$H->parse($H->parse($H->mojo_lib_dir)->rel_dir('Mojolicious/templates'));
-our $MOJOBAR = $H->slurp_rel_file('mojobar.html.ep');
-my $EXCEPTION = $H->slurp_rel_file('exception.html.ep');
-my $DEV_EXCEPTION = $H->slurp_rel_file('exception.development.html.ep');
-my $NOT_FOUND = $H->slurp_rel_file('not_found.html.ep');
-my $DEV_NOT_FOUND = $H->slurp_rel_file('not_found.development.html.ep');
-
# Reserved stash values
my %RESERVED = map { $_ => 1 } (
qw(action app cb controller data extends format handler json layout),
@@ -256,16 +246,18 @@ sub render_exception {
grep { !/^mojo\./ and defined $stash->{$_} } keys %$stash;
# Render with fallbacks
- my $mode = $app->mode;
- my $options = {
+ my $mode = $app->mode;
+ my $renderer = $app->renderer;
+ my $options = {
exception => $e,
snapshot => \%snapshot,
template => "exception.$mode",
- format => $stash->{format} || $app->renderer->default_format,
+ format => $stash->{format} || $renderer->default_format,
handler => undef,
status => 500
};
- my $inline = $mode eq 'development' ? $DEV_EXCEPTION : $EXCEPTION;
+ my $inline = $renderer->_bundled(
+ $mode eq 'development' ? 'exception.development' : 'exception');
return if $self->_fallbacks($options, 'exception', $inline);
$self->_fallbacks({%$options, format => 'html'}, 'exception', $inline);
}
@@ -282,12 +274,14 @@ sub render_not_found {
my $self = shift;
# Render with fallbacks
- my $app = $self->app;
- my $mode = $app->mode;
- my $format = $self->stash->{format} || $app->renderer->default_format;
+ my $app = $self->app;
+ my $mode = $app->mode;
+ my $renderer = $app->renderer;
+ my $format = $self->stash->{format} || $renderer->default_format;
my $options
= {template => "not_found.$mode", format => $format, status => 404};
- my $inline = $mode eq 'development' ? $DEV_NOT_FOUND : $NOT_FOUND;
+ my $inline = $renderer->_bundled(
+ $mode eq 'development' ? 'not_found.development' : 'not_found');
return if $self->_fallbacks($options, 'not_found', $inline);
$self->_fallbacks({%$options, format => 'html'}, 'not_found', $inline);
}
View
9 lib/Mojolicious/Plugin/PODRenderer.pm
@@ -11,9 +11,6 @@ use Pod::Simple::Search;
# Paths
my @PATHS = map { $_, "$_/pods" } @INC;
-# Bundled files
-my $PERLDOC = $Mojolicious::Controller::H->slurp_rel_file('perldoc.html.ep');
-
# "This is my first visit to the Galaxy of Terror and I'd like it to be a
# pleasant one."
sub register {
@@ -21,7 +18,8 @@ sub register {
# Add "pod" handler
my $preprocess = $conf->{preprocess} || 'ep';
- $app->renderer->add_handler(
+ my $renderer = $app->renderer;
+ $renderer->add_handler(
$conf->{name} || 'pod' => sub {
my ($r, $c, $output, $options) = @_;
@@ -36,6 +34,7 @@ sub register {
$app->helper(pod_to_html => sub { shift; b(_pod_to_html(@_)) });
# Perldoc
+ my $template = $renderer->_bundled('perldoc');
return $app->routes->any(
'/perldoc/*module' => {module => 'Mojolicious/Guides'} => sub {
my $self = shift;
@@ -105,7 +104,7 @@ sub register {
# Combine everything to a proper response
$self->content_for(perldoc => "$dom");
- $self->render(inline => $PERLDOC, title => $title, parts => \@parts);
+ $self->render(inline => $template, title => $title, parts => \@parts);
$self->res->headers->content_type('text/html;charset="UTF-8"');
}
) unless $conf->{no_perldoc};
View
8 lib/Mojolicious/Renderer.pm
@@ -16,6 +16,12 @@ has encoding => 'UTF-8';
has [qw(handlers 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 { $_ => $HOME->slurp_rel_file($_) } @{$HOME->list_files};
+
# "This is not how Xmas is supposed to be.
# In my day Xmas was about bringing people together,
# not blowing them apart."
@@ -176,6 +182,8 @@ sub template_path {
return catfile($self->paths->[0], split '/', $name);
}
+sub _bundled { $TEMPLATES{"@{[pop]}.html.ep"} }
+
sub _detect_handler {
my ($self, $options) = @_;
View
2  lib/Mojolicious/templates/exception.development.html.ep
@@ -98,7 +98,7 @@
% end
</head>
<body onload="prettyPrint()">
- %= include inline => $Mojolicious::Controller::MOJOBAR
+ %= include inline => app->renderer->_bundled('mojobar')
<div id="wrapperlicious">
<div id="nothing" class="box spaced"></div>
% my $cv = begin
View
2  lib/Mojolicious/templates/not_found.development.html.ep
@@ -74,7 +74,7 @@
% end
</head>
<body onload="prettyPrint()">
- %= include inline => $Mojolicious::Controller::MOJOBAR
+ %= include inline => app->renderer->_bundled('mojobar')
<div id="wrapperlicious">
<div id="routes">
<h1>Page not found... yet!</h1>
View
2  lib/Mojolicious/templates/perldoc.html.ep
@@ -61,7 +61,7 @@
% end
</head>
<body onload="prettyPrint()">
- %= include inline => $Mojolicious::Controller::MOJOBAR
+ %= include inline => app->renderer->_bundled('mojobar')
% my $link = begin
%= link_to shift, shift, class => "mojoscroll"
% end
Please sign in to comment.
Something went wrong with that request. Please try again.