Skip to content

Commit

Permalink
deprecated Mojolicious::Controller->render_content in favor of conten…
Browse files Browse the repository at this point in the history
…t helper
  • Loading branch information
kraih committed Aug 27, 2012
1 parent ba08389 commit 5f0e0e1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

3.35 2012-08-27
- Deprecated Mojolicious::Controller->render_content in favor of content
helper.
- Improved Mojolicious::Plugin::Config to accept mode specific config files
without a normal config file. (alexbyk, sri)
- Improved documentation.
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious.pm
Expand Up @@ -75,10 +75,10 @@ sub new {

# Hide controller attributes/methods and "handler"
$r->hide(qw(AUTOLOAD DESTROY app cookie finish flash handler on param));
$r->hide(qw(redirect_to render render_content render_data));
$r->hide(qw(render_exception render_json render_not_found render_partial));
$r->hide(qw(render_static render_text rendered req res respond_to send));
$r->hide(qw(session signed_cookie stash tx ua url_for write write_chunk));
$r->hide(qw(redirect_to render render_data render_exception render_json));
$r->hide(qw(render_not_found render_partial render_static render_text));
$r->hide(qw(rendered req res respond_to send session signed_cookie stash));
$r->hide(qw(tx ua url_for write write_chunk));

# Prepare log
my $mode = $self->mode;
Expand Down
35 changes: 0 additions & 35 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -204,31 +204,6 @@ sub render {
return !!$self->rendered($stash->{status});
}

sub render_content {
my $self = shift;
my $name = shift || 'content';
my $content = pop;

# Set
my $stash = $self->stash;
my $c = $stash->{'mojo.content'} ||= {};
if (defined $content) {

# Reset with multiple values
if (@_) {
$c->{$name}
= join('', map({ref $_ eq 'CODE' ? $_->() : $_} @_, $content));
}

# First come
else { $c->{$name} ||= ref $content eq 'CODE' ? $content->() : $content }
}

# Get
$content = $c->{$name} // '';
return Mojo::ByteStream->new("$content");
}

sub render_data { shift->render(data => @_) }

# "The path to robot hell is paved with human flesh.
Expand Down Expand Up @@ -710,16 +685,6 @@ Render content using L<Mojolicious::Renderer/"render">, if no template is
provided a default one based on controller and action or route name will be
generated. All additional values get merged into the C<stash>.
=head2 C<render_content>
my $output = $c->render_content;
my $output = $c->render_content('header');
my $output = $c->render_content(header => 'Hello world!');
my $output = $c->render_content(header => sub { 'Hello world!' });
Contains partial rendered content, used for the renderers C<layout> and
C<extends> features.
=head2 C<render_data>
$c->render_data($bytes);
Expand Down
41 changes: 38 additions & 3 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -30,7 +30,7 @@ sub register {
$app->helper(config => sub { shift->app->config(@_) });

# Add "content" helper
$app->helper(content => sub { shift->render_content(@_) });
$app->helper(content => \&_content);

# Add "content_for" helper
$app->helper(content_for => \&_content_for);
Expand Down Expand Up @@ -70,13 +70,46 @@ sub register {
}
);

# DEPRECATED in Rainbow!
$app->helper(
render_content => sub {
warn "Mojolicious::Controller->render_content has been DEPRECATED!\n";
shift->content(@_);
}
);

# Add "url_with" helper
$app->helper(url_with => \&_url_with);
}

sub _content {
my $self = shift;
my $name = shift || 'content';
my $content = pop;

# Set
my $stash = $self->stash;
my $c = $stash->{'mojo.content'} ||= {};
if (defined $content) {

# Reset with multiple values
if (@_) {
$c->{$name}
= join('', map({ref $_ eq 'CODE' ? $_->() : $_} @_, $content));
}

# First come
else { $c->{$name} ||= ref $content eq 'CODE' ? $content->() : $content }
}

# Get
$content = $c->{$name} // '';
return Mojo::ByteStream->new("$content");
}

sub _content_for {
my ($self, $name) = (shift, shift);
$self->render_content($name, $self->render_content($name), @_);
_content($self, $name, _content($self, $name), @_);
}

sub _current_route {
Expand Down Expand Up @@ -152,10 +185,12 @@ Alias for L<Mojo/"config">.
%= content foo => begin
test
% end
%= content bar => 'Hello World!'
%= content 'foo'
%= content 'bar'
%= content
Store content and retrieve it.
Store partial rendered content and retrieve it.
=head2 C<content_for>
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -1393,7 +1393,7 @@ Just works!\
@@ layouts/layout.html.epl
% my $self = shift;
<%= $self->title %><%= $self->render_content %> with layout
<%= $self->title %><%= $self->content %> with layout
@@ autostash.html.ep
% $self->layout('layout');
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/templates/layouts/default.html.epl
Expand Up @@ -3,6 +3,6 @@
<html>
<head></head>
<body>
<%= $self->render_partial(template => '23') %><%= $self->render_content %>
<%= $self->render_partial(template => '23') %><%= $self->content %>
</body>
</html>
2 changes: 1 addition & 1 deletion t/mojolicious/templates/layouts/green.html.epl
Expand Up @@ -3,6 +3,6 @@
<html>
<head></head>
<body>
Same old in green <%= $self->render_content %>
Same old in green <%= $self->content %>
</body>
</html>

0 comments on commit 5f0e0e1

Please sign in to comment.