1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

refs #30 simplify rel attribute

* do not output rel="start" by default
* do not output rel on first_page and last_page
This commit is contained in:
Akira Matsuda 2011-02-27 19:20:40 +09:00
parent 1c6f72802b
commit afc7dc1b44
9 changed files with 18 additions and 22 deletions

View file

@ -7,5 +7,5 @@
remote: data-remote remote: data-remote
-%> -%>
<span class="first<%= ' disabled' if current_page == 1 %>"> <span class="first<%= ' disabled' if current_page == 1 %>">
<%= link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :rel => (current_page == 2) ? 'start prev':'start', :remote => remote %> <%= link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :remote => remote %>
</span> </span>

View file

@ -6,4 +6,4 @@
per_page: number of items to fetch per page per_page: number of items to fetch per page
remote: data-remote remote: data-remote
%span{:class => "first#{' disabled' if current_page == 1}"} %span{:class => "first#{' disabled' if current_page == 1}"}
= link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :rel => (current_page == 2) ? 'start prev':'start', :remote => remote = link_to_unless current_page == 1, raw(t 'views.pagination.first'), url, :remote => remote

View file

@ -7,6 +7,5 @@
remote: data-remote remote: data-remote
-%> -%>
<span class="last<%= ' disabled' if current_page == num_pages %>"> <span class="last<%= ' disabled' if current_page == num_pages %>">
<% opts = {:remote => remote}; opts[:rel] = 'next' if current_page == num_pages - 1 %> <%= link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, {:remote => remote} %>
<%= link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, opts %>
</span> </span>

View file

@ -6,6 +6,4 @@
per_page: number of items to fetch per page per_page: number of items to fetch per page
remote: data-remote remote: data-remote
%span{:class => "last#{' disabled' if current_page == num_pages}"} %span{:class => "last#{' disabled' if current_page == num_pages}"}
- opts = {:remote => remote}; = link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, {:remote => remote}
- opts[:rel] = 'next' if current_page == num_pages - 1
= link_to_unless current_page == num_pages, raw(t 'views.pagination.last'), url, opts

View file

@ -8,11 +8,5 @@
remote: data-remote remote: data-remote
-%> -%>
<span class="page<%= ' current' if page.current? %>"> <span class="page<%= ' current' if page.current? %>">
<% <%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
opts = {:remote => remote}
opts[:rel] = 'start' if page.first?
opts[:rel] = 'next' if page.number == current_page + 1
opts[:rel] = opts[:rel].nil? ? 'prev' : opts[:rel] + ' prev' if page.number == current_page - 1
%>
<%= link_to_unless page.current?, page, url, opts %>
</span> </span>

View file

@ -6,10 +6,5 @@
num_pages: total number of pages num_pages: total number of pages
per_page: number of items to fetch per page per_page: number of items to fetch per page
remote: data-remote remote: data-remote
%span{:class => "page#{' current' if page.current?}"} %span{:class => "page#{' current' if page.current?}"}
- opts = {:remote => remote} = link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
- opts[:rel] = 'start' if page.first?
- opts[:rel] = 'next' if page.number == current_page + 1
- opts[:rel] = opts[:rel].nil? ? 'prev' : opts[:rel] + ' prev' if page.number == current_page - 1
= link_to_unless page.current?, page, url, opts

View file

@ -7,5 +7,5 @@
remote: data-remote remote: data-remote
-%> -%>
<span class="prev<%= ' disabled' if current_page == 1 %>"> <span class="prev<%= ' disabled' if current_page == 1 %>">
<%= link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :rel => (current_page == 2) ? 'start prev':'prev', :remote => remote %> <%= link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
</span> </span>

View file

@ -6,4 +6,4 @@
per_page: number of items to fetch per page per_page: number of items to fetch per page
remote: data-remote remote: data-remote
%span{:class => "prev#{' disabled' if current_page == 1}"} %span{:class => "prev#{' disabled' if current_page == 1}"}
= link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :rel => (current_page == 2) ? 'start prev':'prev', :remote => remote = link_to_unless current_page == 1, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote

View file

@ -134,6 +134,16 @@ module Kaminari
@page == @options[:num_pages] @page == @options[:num_pages]
end end
# the previous page or not
def prev?
@page == @options[:current_page] - 1
end
# the next page or not
def next?
@page == @options[:current_page] + 1
end
# within the left outer window or not # within the left outer window or not
def left_outer? def left_outer?
@page <= @options[:left] @page <= @options[:left]