site: extend extended_pager
Make it return a hash for page numbers and shortcuts. Move logic handling for the shortcuts from the templates to the helper. Make the pager length configurable. Add a helper for producing the shortcuts' links.
This commit is contained in:
parent
dd492db92e
commit
1a0a224edc
2 changed files with 36 additions and 21 deletions
|
@ -1,24 +1,18 @@
|
|||
% if (my $pager = stash("pager")) {
|
||||
% my @pages = extended_pager($pager);
|
||||
% my ($pages, $shortcuts) = {extended_pager($pager)}->@{qw(pages shortcuts)};
|
||||
<footer>
|
||||
<nav class="text-center pager">
|
||||
<%= link_to "<<" => url_with->query({page => $pager->{first_page}})
|
||||
if $pager->{first_page} < $pages[0] %>
|
||||
<%= link_to "<" => url_with->query({page => $pager->{previous_page}})
|
||||
if defined($pager->{previous_page}) &&
|
||||
$pager->{previous_page} > 3 %>
|
||||
% for my $page (@pages) {
|
||||
<%= tag_for_pager_shortcut "<<", $shortcuts->{first_page} %>
|
||||
<%= tag_for_pager_shortcut "<", $shortcuts->{previous_page} %>
|
||||
% for my $page ($pages->@*) {
|
||||
% if ($page == $pager->{current_page}) {
|
||||
<span><%= $pager->{current_page} %></span>
|
||||
% } else {
|
||||
<%= link_to $page => url_with->query({page => $page}) %>
|
||||
% }
|
||||
% }
|
||||
<%= link_to ">" => url_with->query({page => $pager->{next_page}})
|
||||
if defined($pager->{next_page}) &&
|
||||
$pager->{next_page} < $pager->{last_page} - 2 %>
|
||||
<%= link_to ">>" => url_with->query({page => $pager->{last_page}})
|
||||
if $pager->{last_page} > $pages[-1] %>
|
||||
<%= tag_for_pager_shortcut ">", $shortcuts->{next_page} %>
|
||||
<%= tag_for_pager_shortcut ">>", $shortcuts->{last_page} %>
|
||||
</nav>
|
||||
</footer>
|
||||
% }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue