Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use more perl lines instead of tags in template examples
  • Loading branch information
kraih committed Sep 20, 2011
1 parent bceca8e commit dc45512
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 177 deletions.
10 changes: 5 additions & 5 deletions lib/Mojolicious.pm
Expand Up @@ -305,9 +305,9 @@ Web development for humans, making hard things possible and everything fun.
@@ clock.html.ep
% use Time::Piece;
% my $now = localtime;
<%= link_to clock => begin %>
%= link_to clock => begin
The time is <%= $now->hms %>.
<% end %>
% end
Single file prototypes can easily grow into well-structured applications.
A controller collects several actions together.
Expand Down Expand Up @@ -392,9 +392,9 @@ exactly the same.
% use Time::Piece;
% my $now = localtime;
<%= link_to clock => begin %>
%= link_to clock => begin
The time is <%= $now->hms %>.
<% end %>
% end
Mojolicious has been designed from the ground up for a fun and unique
workflow.
Expand Down Expand Up @@ -583,7 +583,7 @@ and the application object, as well as a function in C<ep> templates.
my $result = $self->add(2, 3);
# Template
<%= add 2, 3 %>
%= add 2, 3
=head2 C<hook>
Expand Down
6 changes: 0 additions & 6 deletions lib/Mojolicious/Guides/Cheatsheet.pod
Expand Up @@ -48,12 +48,6 @@ Controller to dispatch to.

Turn raw bytes into a response.

=head2 C<exception>

<%= $exception %>

L<Mojo::Exception> object for exception templates.

=head2 C<extends>

$self->render(extends => 'template');
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -634,14 +634,14 @@ time to time.

<%= javascript
'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js' %>
<%= javascript begin %>
%= javascript begin
if (typeof jQuery == 'undefined') {
var e = document.createElement('script');
e.src = '/js/jquery.js';
e.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(e);
}
<% end %>
% end

=head1 MORE

Expand Down
23 changes: 12 additions & 11 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -436,24 +436,25 @@ like this.

@@ index.html.ep
% layout 'default';
<%= form_for index => begin %>
<% if (param 'user') { %>
%= form_for index => begin
% if (param 'user') {
<b>Wrong name or password, please try again.</b><br>
<% } %>
% }
Name:<br>
<%= text_field 'user' %><br>
Password:<br>
<%= password_field 'pass' %><br>
<%= submit_button 'Login' %>
<% end %>
%= text_field 'user'
<br>Password:<br>
%= password_field 'pass'
<br>
%= submit_button 'Login'
% end

@@ protected.html.ep
% layout 'default';
<% if (my $message = flash 'message') { %>
% if (my $message = flash 'message') {
<b><%= $message %></b><br>
<% } %>
% }
Welcome <%= session 'user' %>!<br>
<%= link_to Logout => 'logout' %>
%= link_to Logout => 'logout'

A list of all built-in helpers can be found in
L<Mojolicious::Plugin::DefaultHelpers> and
Expand Down
62 changes: 31 additions & 31 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -234,19 +234,19 @@ Perl data types.
$self->stash(frameworks => [qw/Catalyst Mojolicious/]);
$self->stash(examples => {tweetylicious => 'a microblogging app'});

<%= $author %>
<%= $frameworks->[1] %>
<%= $examples->{tweetylicious} %>
%= $author
%= $frameworks->[1]
%= $examples->{tweetylicious}

Since everything is just Perl normal control structures just work.

<% for my $framework (@$frameworks) { %>
% for my $framework (@$frameworks) {
<%= $framework %> was written by <%= $author %>.
<% } %>
% }

<% while (my ($app, $description) = each %$examples) { %>
% while (my ($app, $description) = each %$examples) {
<%= $app %> is a <%= $description %>.
<% } %>
% }

=head2 Content Negotiation

Expand Down Expand Up @@ -292,7 +292,7 @@ used or an empty C<204> response rendered automatically.

Helpers are little functions you can use in templates and controller code.

<%= dumper [1, 2, 3] %>
%= dumper [1, 2, 3]

my $serialized = $self->dumper([1, 2, 3]);

Expand All @@ -302,11 +302,11 @@ We differentiate between C<default helpers> which are more general purpose
like C<dumper> and C<tag helpers>, which are template specific and mostly
used to generate C<HTML> tags.

<%= javascript '/script.js' %>
%= javascript '/script.js'

<%= javascript begin %>
%= javascript begin
var a = 'b';
<% end %>
% end

A list of all built-in helpers can be found in
L<Mojolicious::Plugin::DefaultHelpers> and
Expand Down Expand Up @@ -369,7 +369,7 @@ a little easier.

@@ foo/bar.html.ep
<!doctype html><html>
<%= include 'header' %>
%= include 'header'
<body>Bar!</body>
</html>

Expand All @@ -381,7 +381,7 @@ argument.

@@ foo/bar.html.ep
<!doctype html><html>
<%= $self->render('header', partial => 1) %>
%= $self->render('header', partial => 1)
<body>Bar!</body>
</html>

Expand All @@ -394,7 +394,7 @@ in the partial template.

@@ foo/bar.html.ep
<!doctype html><html>
<%= include 'header', title => 'Hello!' %>
%= include 'header', title => 'Hello!'
<body>Bar!</body>
</html>

Expand Down Expand Up @@ -444,13 +444,13 @@ of the template to the layout.

@@ foo/bar.html.ep
% layout 'mylayout';
<% content_for header => begin %>
% content_for header => begin
<title>MyApp!</title>
<% end %>
% end
Hello World!
<% content_for header => begin %>
% content_for header => begin
<meta http-equiv="Pragma" content="no-cache">
<% end %>
% end

@@ layouts/mylayout.html.ep
<!doctype html><html>
Expand All @@ -469,27 +469,27 @@ templates don't get prefixed with C<layouts/>.
@@ first.html.ep
%# "<div>First header!First footer!</div>"
<div>
<%= content header => begin %>
%= content header => begin
First header!
<% end %>
<%= content footer => begin %>
% end
%= content footer => begin
First footer!
<% end %>
% end
</div>

@@ second.html.ep
%# "<div>Second header!First footer!</div>"
% extends 'first';
<% content header => begin %>
% content header => begin
Second header!
<% end %>
% end

@@ third.html.ep
%# "<div>Second header!Third footer!</div>"
% extends 'second';
<% content footer => begin %>
% content footer => begin
Third footer!
<% end %>
% end

This chain could go on and on to allow a very high level of template reuse.

Expand All @@ -499,9 +499,9 @@ Compiled templates are always cached in memory, but with the C<memorize>
helper you can go one step further and prevent template blocks from being
executed more than once.

<%= memorize begin %>
%= memorize begin
This template was compiled at <%= localtime time %>.
<% end %>
% end %>

=head2 Adding Helpers

Expand Down Expand Up @@ -545,11 +545,11 @@ allows very pleasant to use tag helpers and filters.
__DATA__

@@ index.html.ep
<%= trim_newline begin %>
%= trim_newline begin
Some text.
<%= 1 + 1 %>
%= 1 + 1
More text.
<% end %>
% end

Wrapping the helper result into a L<Mojo::ByteStream> object can prevent
accidental double escaping.
Expand Down
30 changes: 15 additions & 15 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -264,15 +264,15 @@ delimited by the C<begin> and C<end> keywords.
__DATA__
@@ block.html.ep
<% my $link = begin %>
<% my ($url, $name) = @_; %>
% my $link = begin
% my ($url, $name) = @_;
Try <%= link_to $url => begin %><%= $name %><% end %>!
<% end %>
% end
<!doctype html><html>
<head><title>Sebastians Frameworks!</title></head>
<body>
<%= $link->('http://mojolicio.us', 'Mojolicious') %>
<%= $link->('http://catalystframework.org', 'Catalyst') %>
%= $link->('http://mojolicio.us', 'Mojolicious')
%= $link->('http://catalystframework.org', 'Catalyst')
</body>
</html>
Expand All @@ -291,19 +291,19 @@ content.
@@ captured.html.ep
% layout 'blue', title => 'Green!';
<% content_for header => begin %>
% content_for header => begin
<meta http-equiv="Pragma" content="no-cache">
<% end %>
% end
Hello World!
<% content_for header => begin %>
% content_for header => begin
<meta http-equiv="Expires" content="-1">
<% end %>
% end
@@ layouts/blue.html.ep
<!doctype html><html>
<head>
<title><%= title %></title>
<%= content_for 'header' %>
%= content_for 'header'
</head>
<body><%= content %></body>
</html>
Expand Down Expand Up @@ -617,11 +617,11 @@ C<250KB> will be automatically streamed into a temporary file.
<!doctype html><html>
<head><title>Upload</title></head>
<body>
<%= form_for upload =>
(method => 'post', enctype => 'multipart/form-data') => begin %>
<%= file_field 'example' %>
<%= submit_button 'Upload' %>
<% end %>
% my @attrs = (method => 'POST', enctype => 'multipart/form-data');
%= form_for upload => @attrs => begin
%= file_field 'example'
%= submit_button 'Upload'
% end
</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -180,8 +180,8 @@ L<Mojolicious::Plugin::Config> implements the following helpers.
=head2 C<config>
<%= config 'something' %>
<%= config->{something} %>
%= config 'something'
%= config->{something}
Access config values.
Expand Down

0 comments on commit dc45512

Please sign in to comment.