mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
refs #30 add real first/last page links, and use them by default instead of outer window
* :window, :outer_window, :left, :right will be interpreted similarly to how they were, except the supplied N would be the number of pages you actually get. 0 means disable for the outer windows * outer windows will be disabled by default in favor of first/last links * include a "disabled" class when appropriate, and always include the label text (but no link tag when current page). Users that want these tags to disappear completely when inapplicable can style them to display: none. (Similarly for "first" and "last".) * changed the default labels - double angle quotes for "first" and "last", single angle quotes for "previous" and "next". (Consider a standard set of video or audio transport controls: << < stop > >>)
This commit is contained in:
parent
4beef97cea
commit
393943a50e
21 changed files with 105 additions and 109 deletions
11
app/views/kaminari/_first_page.html.erb
Normal file
11
app/views/kaminari/_first_page.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<%# Link to the "First" page
|
||||
- available local variables
|
||||
url: url to the first page
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="first<%= ' disabled' if current_page == 1 %>">
|
||||
<%= link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :class => 'prev', :rel => 'prev', :remote => remote %>
|
||||
</span>
|
9
app/views/kaminari/_first_page.html.haml
Normal file
9
app/views/kaminari/_first_page.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
|||
-# Link to the "First" page
|
||||
- available local variables
|
||||
url: url to the first page
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span{:class => "first#{' disabled' if current_page == 1}"}
|
||||
= link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :class => 'prev', :rel => 'prev', :remote => remote
|
11
app/views/kaminari/_last_page.html.erb
Normal file
11
app/views/kaminari/_last_page.html.erb
Normal file
|
@ -0,0 +1,11 @@
|
|||
<%# Link to the "Last" page
|
||||
- available local variables
|
||||
url: url to the last page
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="last<%= ' disabled' if current_page == num_pages %>">
|
||||
<%= link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, :class => 'last', :remote => remote %>
|
||||
</span>
|
9
app/views/kaminari/_last_page.html.haml
Normal file
9
app/views/kaminari/_last_page.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
|||
-# Link to the "Last" page
|
||||
- available local variables
|
||||
url: url to the last page
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span{:class => "last#{' disabled' if current_page == num_pages}"}
|
||||
= link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, :class => 'last', :remote => remote
|
|
@ -1,4 +1,4 @@
|
|||
<%# "Next" with link
|
||||
<%# Link to the "Next" page
|
||||
- available local variables
|
||||
url: url to the next page
|
||||
current_page: the page number of currently displayed page
|
||||
|
@ -6,6 +6,6 @@
|
|||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="next">
|
||||
<%= link_to raw(t 'views.pagination.next'), url, :class => 'next', :rel => 'next', :remote => remote %>
|
||||
<span class="next<%= ' disabled' if current_page == num_pages %>">
|
||||
<%= link_to_unless current_page == num_pages, raw(t 'views.pagination.next'), url, :class => 'next', :rel => 'next', :remote => remote %>
|
||||
</span>
|
|
@ -1,4 +1,4 @@
|
|||
-# "Next" with link
|
||||
-# Link to the "Next" page
|
||||
- available local variables
|
||||
url: url to the next page
|
||||
current_page: the page number of currently displayed page
|
||||
|
@ -6,4 +6,4 @@
|
|||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span.next
|
||||
= link_to raw(t 'views.pagination.next'), url, :class => 'next', :rel => 'next', :remote => remote
|
||||
= link_to_unless current_page == num_pages, raw(t 'views.pagination.next'), url, :class => 'next', :rel => 'next', :remote => remote
|
|
@ -1,8 +0,0 @@
|
|||
<%# "Next" without link
|
||||
- available local variables
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="next"></span>
|
|
@ -1,7 +0,0 @@
|
|||
-# "Next" without link
|
||||
- available local variables
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span.next
|
|
@ -8,14 +8,16 @@
|
|||
-%>
|
||||
<%= paginator.render do -%>
|
||||
<nav class="pagination">
|
||||
<%= current_page > 1 ? prev_link_tag : prev_span_tag %>
|
||||
<%= first_page_tag %>
|
||||
<%= prev_page_tag %>
|
||||
<% each_page do |page| -%>
|
||||
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
|
||||
<%= page_tag page %>
|
||||
<% elsif !page.was_truncated? -%>
|
||||
<%= truncated_span_tag %>
|
||||
<%= gap_tag %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<%= num_pages > current_page ? next_link_tag : next_span_tag %>
|
||||
<%= next_page_tag %>
|
||||
<%= last_page_tag %>
|
||||
</nav>
|
||||
<% end -%>
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
paginator: the paginator that renders the pagination tags inside
|
||||
= paginator.render do
|
||||
%nav.pagination
|
||||
= current_page > 1 ? prev_link_tag : prev_span_tag
|
||||
= first_page_tag
|
||||
= prev_page_tag
|
||||
- each_page do |page|
|
||||
- if page.left_outer? || page.right_outer? || page.inside_window?
|
||||
= page_tag page
|
||||
- elsif !page.was_truncated?
|
||||
= truncated_span_tag
|
||||
= num_pages > current_page ? next_link_tag : next_span_tag
|
||||
= gap_tag
|
||||
= next_page_tag
|
||||
= last_page_tag
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%# "Previous" with link
|
||||
<%# Link to the "Previous" page
|
||||
- available local variables
|
||||
url: url to the previous page
|
||||
current_page: the page number of currently displayed page
|
||||
|
@ -6,6 +6,6 @@
|
|||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="prev">
|
||||
<%= link_to raw(t 'views.pagination.previous'), url, :class => 'prev', :rel => 'prev', :remote => remote %>
|
||||
<span class="prev<%= ' disabled' if current_page == 1 %>">
|
||||
<%= link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :class => 'prev', :rel => 'prev', :remote => remote %>
|
||||
</span>
|
|
@ -1,4 +1,4 @@
|
|||
-# "Previous" with link
|
||||
-# Link to the "Previous" page
|
||||
- available local variables
|
||||
url: url to the previous page
|
||||
current_page: the page number of currently displayed page
|
||||
|
@ -6,4 +6,4 @@
|
|||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span.prev
|
||||
= link_to raw(t 'views.pagination.previous'), url, :class => 'prev', :rel => 'prev', :remote => remote
|
||||
= link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :class => 'prev', :rel => 'prev', :remote => remote
|
|
@ -1,8 +0,0 @@
|
|||
<%# "Previous" without link
|
||||
- available local variables
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
-%>
|
||||
<span class="prev"></span>
|
|
@ -1,7 +0,0 @@
|
|||
-# "Previous" without link
|
||||
- available local variables
|
||||
current_page: the page number of currently displayed page
|
||||
num_pages: total number of pages
|
||||
per_page: number of items to fetch per page
|
||||
remote: data-remote
|
||||
%span.prev
|
|
@ -3,6 +3,8 @@
|
|||
en:
|
||||
views:
|
||||
pagination:
|
||||
previous: "« Prev"
|
||||
next: "Next »"
|
||||
first: "« First"
|
||||
last: "Last »"
|
||||
previous: "‹ Prev"
|
||||
next: "Next ›"
|
||||
truncate: "..."
|
||||
|
|
|
@ -9,10 +9,10 @@ module Kaminari
|
|||
# <%= paginate @articles %>
|
||||
#
|
||||
# ==== Options
|
||||
# * <tt>:window</tt> - The "inner window" size (2 by default).
|
||||
# * <tt>:outer_window</tt> - The "outer window" size (1 by default).
|
||||
# * <tt>:left</tt> - The "left outer window" size (1 by default).
|
||||
# * <tt>:right</tt> - The "right outer window" size (1 by default).
|
||||
# * <tt>:window</tt> - The "inner window" size (4 by default).
|
||||
# * <tt>:outer_window</tt> - The "outer window" size (0 by default).
|
||||
# * <tt>:left</tt> - The "left outer window" size (0 by default).
|
||||
# * <tt>:right</tt> - The "right outer window" size (0 by default).
|
||||
# * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
|
||||
# * <tt>:param_name</tt> - parameter name for page number in the links (:page by default)
|
||||
# * <tt>:remote</tt> - Ajax? (false by default)
|
||||
|
|
|
@ -39,8 +39,8 @@ module Kaminari
|
|||
@window_options = {}.tap do |h|
|
||||
h[:window] = options.delete(:window) || options.delete(:inner_window) || 4
|
||||
outer_window = options.delete(:outer_window)
|
||||
h[:left] = options.delete(:left) || outer_window || 1
|
||||
h[:right] = options.delete(:right) || outer_window || 1
|
||||
h[:left] = options.delete(:left) || outer_window || 0
|
||||
h[:right] = options.delete(:right) || outer_window || 0
|
||||
end
|
||||
@template = TemplateWrapper.new(template, options)
|
||||
end
|
||||
|
|
|
@ -94,7 +94,7 @@ module Kaminari
|
|||
@last = Page.new @template, :page => page
|
||||
end
|
||||
|
||||
%w[prev_link prev_span next_link next_span truncated_span].each do |tag|
|
||||
%w[first_page prev_page next_page last_page gap].each do |tag|
|
||||
eval <<-DEF
|
||||
def #{tag}_tag
|
||||
@last = #{tag.classify}.new @template
|
||||
|
@ -136,12 +136,12 @@ module Kaminari
|
|||
|
||||
# within the left outer window or not
|
||||
def left_outer?
|
||||
@page <= @options[:left] + 1
|
||||
@page <= @options[:left]
|
||||
end
|
||||
|
||||
# within the right outer window or not
|
||||
def right_outer?
|
||||
@options[:num_pages] - @page <= @options[:right]
|
||||
@options[:num_pages] - @page < @options[:right]
|
||||
end
|
||||
|
||||
# inside the inner window or not
|
||||
|
@ -151,7 +151,7 @@ module Kaminari
|
|||
|
||||
# The last rendered tag was "truncated" or not
|
||||
def was_truncated?
|
||||
@last.is_a? TruncatedSpan
|
||||
@last.is_a? Gap
|
||||
end
|
||||
|
||||
def to_i
|
||||
|
@ -171,6 +171,7 @@ module Kaminari
|
|||
# Tag that contains a link
|
||||
module Link
|
||||
include Renderable
|
||||
# target page number
|
||||
def page
|
||||
raise 'Override page with the actual page value to be a Page.'
|
||||
end
|
||||
|
@ -195,54 +196,41 @@ module Kaminari
|
|||
end
|
||||
end
|
||||
|
||||
# Tag that doesn't contain a link
|
||||
module NonLink
|
||||
include Renderable
|
||||
# Link with page number that appears at the leftmost
|
||||
class FirstPage < Tag
|
||||
include Link
|
||||
def page #:nodoc:
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
# Link with page number that appears at the rightmost
|
||||
class LastPage < Tag
|
||||
include Link
|
||||
def page #:nodoc:
|
||||
@options[:num_pages]
|
||||
end
|
||||
end
|
||||
|
||||
# The "previous" page of the current page
|
||||
module Prev
|
||||
include Renderable
|
||||
end
|
||||
|
||||
# "Previous" without link
|
||||
class PrevSpan < Tag
|
||||
include NonLink
|
||||
include Prev
|
||||
end
|
||||
|
||||
# "Previous" with link
|
||||
class PrevLink < Tag
|
||||
class PrevPage < Tag
|
||||
include Link
|
||||
include Prev
|
||||
def page #:nodoc:
|
||||
@options[:current_page] - 1
|
||||
end
|
||||
end
|
||||
|
||||
# The "next" page of the current page
|
||||
module Next
|
||||
include Renderable
|
||||
end
|
||||
|
||||
# "Next" without link
|
||||
class NextSpan < Tag
|
||||
include NonLink
|
||||
include Next
|
||||
end
|
||||
|
||||
# "Next" with link
|
||||
class NextLink < Tag
|
||||
class NextPage < Tag
|
||||
include Link
|
||||
include Next
|
||||
def page #:nodoc:
|
||||
@options[:current_page] + 1
|
||||
end
|
||||
end
|
||||
|
||||
# Non-link tag that stands for skipped pages...
|
||||
class TruncatedSpan < Tag
|
||||
include NonLink
|
||||
class Gap < Tag
|
||||
include Renderable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,29 +7,21 @@ describe 'Kaminari::Helpers' do
|
|||
subject { Paginator }
|
||||
its(:ancestor_renderables) { should == [Paginator] }
|
||||
end
|
||||
describe 'PrevLink' do
|
||||
subject { PrevLink }
|
||||
its(:ancestor_renderables) { should == [PrevLink, Prev, Link] }
|
||||
end
|
||||
describe 'PrevSpan' do
|
||||
subject { PrevSpan }
|
||||
its(:ancestor_renderables) { should == [PrevSpan, Prev, NonLink] }
|
||||
describe 'PrevPage' do
|
||||
subject { PrevPage }
|
||||
its(:ancestor_renderables) { should == [PrevPage, Link] }
|
||||
end
|
||||
describe 'Page' do
|
||||
subject { Page }
|
||||
its(:ancestor_renderables) { should == [Page, Link] }
|
||||
end
|
||||
describe 'TruncatedSpan' do
|
||||
subject { TruncatedSpan }
|
||||
its(:ancestor_renderables) { should == [TruncatedSpan, NonLink] }
|
||||
describe 'Gap' do
|
||||
subject { Gap }
|
||||
its(:ancestor_renderables) { should == [Gap] }
|
||||
end
|
||||
describe 'NextLink' do
|
||||
subject { NextLink }
|
||||
its(:ancestor_renderables) { should == [NextLink, Next, Link] }
|
||||
end
|
||||
describe 'NextSpan' do
|
||||
subject { NextSpan }
|
||||
its(:ancestor_renderables) { should == [NextSpan, Next, NonLink] }
|
||||
describe 'NextPage' do
|
||||
subject { NextPage }
|
||||
its(:ancestor_renderables) { should == [NextPage, Link] }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,11 +124,11 @@ describe 'Kaminari::Helpers' do
|
|||
before do
|
||||
stub(@template = Object.new).options { {} }
|
||||
end
|
||||
context 'last.is_a? TruncatedSpan' do
|
||||
subject { Paginator::PageProxy.new({}, 10, TruncatedSpan.new(@template)) }
|
||||
context 'last.is_a? Gap' do
|
||||
subject { Paginator::PageProxy.new({}, 10, Gap.new(@template)) }
|
||||
its(:was_truncated?) { should be_true }
|
||||
end
|
||||
context 'last.is not a TruncatedSpan' do
|
||||
context 'last.is not a Gap' do
|
||||
subject { Paginator::PageProxy.new({}, 10, Page.new(@template)) }
|
||||
its(:was_truncated?) { should_not be_true }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue