Compare commits
2 Commits
3dc4410342
...
74ae6e1745
Author | SHA1 | Date |
---|---|---|
barnold | 74ae6e1745 | |
barnold | c9c248a4b3 |
15
lib/MyApp.pm
15
lib/MyApp.pm
|
@ -1,12 +1,27 @@
|
|||
package MyApp;
|
||||
use Mojo::Base 'Mojolicious', -signatures;
|
||||
|
||||
# Define home-made helpers.
|
||||
sub add_my_helpers ($self) {
|
||||
$self->helper(
|
||||
commify => sub ($self, $number) {
|
||||
my $rev = reverse $number;
|
||||
while ($rev =~ s/(\d{3})(\d)/$1,$2/) {};
|
||||
return scalar reverse $rev;
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sub startup ($self) {
|
||||
# Set a "secret" for signing cookies, preventing "Your secret
|
||||
# passphrase needs to be changed" in the log, using my_app.yml.
|
||||
my $config = $self->plugin('NotYAMLConfig');
|
||||
$self->secrets([ $config->{secrets} ]);
|
||||
|
||||
# Add home-made helper(s).
|
||||
$self->add_my_helpers;
|
||||
|
||||
# Set routes.
|
||||
my $r = $self->routes;
|
||||
# Home gets an explicit name, else its name is an empty string. A
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<p/>
|
||||
Page <%= $pager->current_page %> of <%= $pager->last_page %>
|
||||
Page <%= commify($pager->current_page) %>
|
||||
of <%= commify($pager->last_page) %>
|
||||
|
||||
|
||||
<%= link_to url_with(page_number => 1) => begin %>◄ First<% end %>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
% layout 'default';
|
||||
% title 'Author: ' . $author->name;
|
||||
<h1>Author: <%= $author->name %></h1>
|
||||
<h1><%= title %></h1>
|
||||
|
||||
<strong><%= $author->name %></strong> wrote <%= $author->books->count %> books.
|
||||
<strong><%= $author->name %></strong>
|
||||
% my $count = $author->books->count;
|
||||
wrote <%= $count %> book<%= "s" if ($count > 1) %>.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
% layout 'default';
|
||||
% title 'Authors';
|
||||
<h1>Author page</h1>
|
||||
<h1>Authors</h1>
|
||||
|
||||
<%# On a new search, reset the page number to 1. %>
|
||||
%= form_for authors => { page_number => 1 } => begin
|
||||
|
@ -10,17 +10,19 @@
|
|||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> authors found.
|
||||
<%= commify($pager->total_entries) %> authors found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Books</th>
|
||||
<th>Authored by</th>
|
||||
</tr>
|
||||
% for my $author ($author_page->all) {
|
||||
<tr>
|
||||
<td><%= link_to($author->name => 'author' => { id => $author->id}) %></td>
|
||||
<td style="text-align:right"><%= $author->books->count %></td>
|
||||
<td style="padding-left:1em"><%= link_to($author->name => 'author' => { id => $author->id}) %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
% layout 'default';
|
||||
% title 'Books';
|
||||
<h1>Book page</h1>
|
||||
<h1>Books</h1>
|
||||
|
||||
<%# On a new search, reset the page number to 1. %>
|
||||
%= form_for books => { page_number => 1 } => begin
|
||||
|
@ -10,7 +10,7 @@
|
|||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> books found.
|
||||
<%= commify($pager->total_entries) %> books found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
|
@ -21,7 +21,9 @@
|
|||
% for my $book ($book_page->all) {
|
||||
<tr>
|
||||
<td><%= $book->title %></td>
|
||||
<td><%= $book->author->name %></td>
|
||||
<td>
|
||||
<%= link_to($book->author->name => 'author' => { id => $book->author->id}) %>
|
||||
</td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue