Compare commits

...

4 Commits

3 changed files with 30 additions and 4 deletions

View File

@ -9,7 +9,7 @@ sub add_my_helpers ($self) {
# a utility somewhere to do this already but I didn't find it.
accept_nnint => sub ($self, $maybe_nn) {
my $verdict = do {
if ($maybe_nn =~ m/^[[:digit:]]+$/) {
if ((defined $maybe_nn) && ($maybe_nn =~ m/^[[:digit:]]+$/)) {
$maybe_nn;
} elsif ((!defined $maybe_nn) || ($maybe_nn eq '')) {
0;
@ -39,6 +39,11 @@ sub add_my_helpers ($self) {
return $self->config->{'default-rows-per-page'};
}
);
$self->helper(
gutenberg_url => sub ($self, $gid) {
return "https://gutenberg.org/ebooks/" . $gid;
}
);
$self->helper(
logname => sub ($self) { $self->session('logname'); }
);
@ -52,6 +57,17 @@ sub add_my_helpers ($self) {
$self->session('rows_per_page') // $self->default_rpp;
}
);
$self->helper(
trct => sub ($self, $str, $len) {
do {
if (length($str) <= $len) {
$str;
} else {
substr($str, 0, $len - 1) . '…';
}
};
}
);
return;
}

View File

@ -12,7 +12,10 @@ Books by <strong><%= $author->name %></strong>
</tr>
% for my $book ($book_page->all) {
<tr>
<td><%= $book->title %></td>
<td><%= link_to(
trct($book->title, 100) => gutenberg_url($book->gutenberg_id)
) %>
</td>
</tr>
% }
</table>

View File

@ -2,6 +2,10 @@
% title 'Books';
<h1><%= title %></h1>
Some books have no associated author. To search for these, use
author like '[no author]'.
<p/>
<%# On a new search, reset the page number to 1. %>
%= form_for books => { page_number => 1 } => begin
%= label_for title_like => 'Title like'
@ -20,9 +24,12 @@
</tr>
% for my $book ($book_page->all) {
<tr>
<td><%= $book->title %></td>
<td><%= link_to(
trct($book->title, 50) => gutenberg_url($book->gutenberg_id)
) %>
</td>
<td>
<%= link_to($book->author->name => 'author' =>
<%= link_to(trct($book->author->name, 40) => 'author' =>
{ id => $book->author->id, page_number => 1 }) %>
</td>
</tr>