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

Merge branch 'patch-1' of https://github.com/timgremore/kaminari into timgremore-patch-1

This commit is contained in:
Akira Matsuda 2012-02-19 21:03:22 +09:00
commit 118927a42e
2 changed files with 52 additions and 0 deletions

View file

@ -19,6 +19,31 @@ module Kaminari
paginator.to_s
end
# A simple "Twitter like" pagination link that creates a link to the previous page.
#
# ==== Examples
# Basic usage:
#
# <%= link_to_previous_page @items, 'Previous Page' %>
#
# Ajax:
#
# <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
#
# By default, it renders nothing if there are no more results on the previous page.
# You can customize this output by passing a block.
#
# <%= link_to_previous_page @users, 'Previous Page' do %>
# <span>At the Beginning</span>
# <% end %>
def link_to_previous_page(scope, name, options = {}, &block)
params = options.delete(:params) || {}
param_name = options.delete(:param_name) || Kaminari.config.param_name
link_to_unless scope.first_page?, name, params.merge(param_name => (scope.current_page - 1)), options.reverse_merge(:rel => 'previous') do
block.call if block
end
end
# A simple "Twitter like" pagination link that creates a link to the next page.
#
# ==== Examples

View file

@ -16,6 +16,33 @@ describe 'Kaminari::ActionViewExtension' do
end
end
describe '#link_to_previous_page' do
before do
50.times {|i| User.create! :name => "user#{i}"}
end
context 'having previous pages' do
before do
@users = User.page(50)
end
context 'the default behaviour' do
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
it { should be_a String }
it { should match /rel="previous"/ }
end
context 'overriding rel=' do
subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
it { should match /rel="external"/ }
end
end
context 'the first page' do
before do
@users = User.page(1)
end
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
it { should_not be }
end
end
describe '#link_to_next_page' do
before do
50.times {|i| User.create! :name => "user#{i}"}