Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
document and test render semantics
  • Loading branch information
kraih committed Mar 15, 2012
1 parent 967eeb9 commit 527cba9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
35 changes: 14 additions & 21 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -233,9 +233,7 @@ sub render {
$res->body($output) unless $res->body;
my $headers = $res->headers;
$headers->content_type($type) unless $headers->content_type;
$self->rendered($stash->{status});

return 1;
return $self->rendered($stash->{status});
}

# "She's built like a steakhouse, but she handles like a bistro!"
Expand Down Expand Up @@ -351,15 +349,11 @@ sub render_partial {

sub render_static {
my ($self, $file) = @_;

my $app = $self->app;
$app->log->debug(
qq/Static file "$file" not found, public directory missing?/)
$app->log->debug(qq/File "$file" not found, public directory missing?/)
and return
unless $app->static->serve($self, $file);
$self->rendered;

return 1;
return $self->rendered;
}

sub render_text { shift->render(text => shift, @_) }
Expand Down Expand Up @@ -769,16 +763,15 @@ C<url_for>.
=head2 C<render>
$c->render;
$c->render(controller => 'foo', action => 'bar');
$c->render({controller => 'foo', action => 'bar'});
$c->render(text => 'Hello!');
$c->render(template => 'index');
$c->render(template => 'foo/index');
$c->render(template => 'index', format => 'html', handler => 'epl');
$c->render(handler => 'something');
$c->render('foo/bar');
$c->render('foo/bar', format => 'html');
my $success = $c->render;
my $success = $c->render(controller => 'foo', action => 'bar');
my $success = $c->render({controller => 'foo', action => 'bar'});
my $success = $c->render(text => 'Hello!');
my $success = $c->render(template => 'foo/index');
my $success = $c->render(template => 'index', format => 'html');
my $success = $c->render(handler => 'something');
my $success = $c->render('foo/bar');
my $output = $c->render('foo/bar', partial => 1);
This is a wrapper around L<Mojolicious::Renderer> exposing pretty much all
functionality provided by it. It will set a default template to use based on
Expand Down Expand Up @@ -851,8 +844,8 @@ Same as C<render> but returns the rendered result.
my $success = $c->render_static('images/logo.png');
my $success = $c->render_static('../lib/MyApp.pm');
Render a static file using L<Mojolicious::Static>, relative to the
C<public> directories of your application.
Render a static file using L<Mojolicious::Static>, relative to the C<public>
directories of your application.
=head2 C<render_text>
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -247,7 +247,8 @@ get '/inline/ep/partial' => sub {
get '/source' => sub {
my $self = shift;
my $file = $self->param('fail') ? 'does_not_exist.txt' : '../lite_app.t';
$self->render_static($file)
$self->render('this_does_not_ever_exist')
or $self->render_static($file)
or $self->render_text('does not exist!', status => 404);
};

Expand Down

0 comments on commit 527cba9

Please sign in to comment.