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

#️⃣ 🚀 🔞

This commit is contained in:
Akira Matsuda 2016-12-01 02:19:50 +09:00
parent 99f9bf6d66
commit df586c73c1
21 changed files with 44 additions and 44 deletions

View file

@ -147,37 +147,37 @@ Run the following generator command, then edit the generated file.
* specifying the "inner window" size (4 by default)
<%= paginate @users, :window => 2 %>
<%= paginate @users, window: 2 %>
This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
* specifying the "outer window" size (0 by default)
<%= paginate @users, :outer_window => 3 %>
<%= paginate @users, outer_window: 3 %>
This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
* outer window can be separately specified by +left+, +right+ (0 by default)
<%= paginate @users, :left => 1, :right => 3 %>
<%= paginate @users, left: 1, right: 3 %>
This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
* changing the parameter name (:+param_name+) for the links
<%= paginate @users, :param_name => :pagina %>
<%= paginate @users, param_name: :pagina %>
This would modify the query parameter name on each links.
* extra parameters (:+params+) for the links
<%= paginate @users, :params => {:controller => 'foo', :action => 'bar'} %>
<%= paginate @users, params: {controller: 'foo', action: 'bar'} %>
This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
* Ajax links (crazy simple, but works perfectly!)
<%= paginate @users, :remote => true %>
<%= paginate @users, remote: true %>
This would add <tt>data-remote="true"</tt> to all the links inside.
* specifying an alternative views directory (default is <tt>kaminari/</tt>)
<%= paginate @users, :views_prefix => 'templates' %>
<%= paginate @users, views_prefix: 'templates' %>
This would search for partials in <tt>app/views/templates/kaminari</tt>. This option makes it easier to do things like A/B testing pagination templates/themes, using new/old templates at the same time as well as better integration with other gems such as {cells}[https://github.com/apotonick/cells].
* the +link_to_next_page+ and +link_to_previous_page+ helper method
@ -195,7 +195,7 @@ Run the following generator command, then edit the generated file.
The namespace will be cut out and only the last name will be used.
Override this with the <tt>:entry_name</tt> parameter:
<%= page_entries_info @posts, :entry_name => 'item' %>
<%= page_entries_info @posts, entry_name: 'item' %>
#-> Displaying items 6 - 10 of 26 in total
* the +rel_next_prev_link_tags+ helper method
@ -281,7 +281,7 @@ Kaminari includes a handy template generator.
Next, reference that directory when calling the +paginate+ method:
<%= paginate @users, :theme => 'my_custom_theme' %>
<%= paginate @users, theme: 'my_custom_theme' %>
Customize away!
@ -304,22 +304,22 @@ You can specify the +total_count+ value through options Hash. This would be help
Because of the +page+ parameter and Rails 3 routing, you can easily generate SEO and user-friendly URLs. For any resource you'd like to paginate, just add the following to your +routes.rb+:
resources :my_resources do
get 'page/:page', :action => :index, :on => :collection
get 'page/:page', action: :index, on: :collection
end
If you are using Rails 4 or later, you can simplify route definitions by using `concern`:
concern :paginatable do
get '(page/:page)', :action => :index, :on => :collection, :as => ''
get '(page/:page)', action: :index, on: :collection, as: ''
end
resources :my_resources, :concerns => :paginatable
resources :my_resources, concerns: :paginatable
This will create URLs like <tt>/my_resources/page/33</tt> instead of <tt>/my_resources?page=33</tt>. This is now a friendly URL, but it also has other added benefits...
Because the +page+ parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!
NOTE: In this example, I've pointed the route to my <tt>:index</tt> action. You may have defined a custom pagination action in your controller - you should point <tt>:action => :your_custom_action</tt> instead.
NOTE: In this example, I've pointed the route to my <tt>:index</tt> action. You may have defined a custom pagination action in your controller - you should point <tt>action: :your_custom_action</tt> instead.
== Sinatra/Padrino support

View file

@ -1,7 +1,7 @@
source 'https://rubygems.org'
gem 'railties', '~> 4.1.0'
gem 'activerecord', '~> 4.1.0', :require => 'active_record'
gem 'activerecord', '~> 4.1.0', require: 'active_record'
platforms :ruby do
if RUBY_VERSION > "2.1.0"
@ -20,4 +20,4 @@ platforms :rbx do
gem 'rubinius-developer_tools'
end
gemspec :path => '../'
gemspec path: '../'

View file

@ -1,7 +1,7 @@
source 'https://rubygems.org'
gem 'railties', '~> 4.2.0'
gem 'activerecord', '~> 4.2.0', :require => 'active_record'
gem 'activerecord', '~> 4.2.0', require: 'active_record'
platforms :ruby do
if RUBY_VERSION > "2.1.0"
@ -20,4 +20,4 @@ platforms :rbx do
gem 'rubinius-developer_tools'
end
gemspec :path => '../'
gemspec path: '../'

View file

@ -1,8 +1,8 @@
source 'https://rubygems.org'
gem 'railties', '~> 5.0.0'
gem 'activerecord', '~> 5.0.0', :require => 'active_record'
gem 'actionview', '~> 5.0.0', :require => 'action_view'
gem 'activerecord', '~> 5.0.0', require: 'active_record'
gem 'actionview', '~> 5.0.0', require: 'action_view'
platforms :ruby do
gem 'sqlite3'
@ -17,4 +17,4 @@ platforms :rbx do
gem 'rubinius-developer_tools'
end
gemspec :path => '../'
gemspec path: '../'

View file

@ -2,12 +2,12 @@ source 'https://rubygems.org'
git 'git://github.com/rails/rails.git' do
gem 'railties'
gem 'activerecord', :require => 'active_record'
gem 'actionview', :require => 'action_view'
gem 'activerecord', require: 'active_record'
gem 'actionview', require: 'action_view'
end
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'arel', :github => 'rails/arel'
gem 'rack', git: 'git://github.com/rack/rack.git'
gem 'arel', github: 'rails/arel'
platforms :ruby do
if RUBY_VERSION > "2.1.0"
@ -26,4 +26,4 @@ platforms :rbx do
gem 'rubinius-developer_tools'
end
gemspec :path => '../'
gemspec path: '../'

View file

@ -7,5 +7,5 @@
remote: data-remote
-%>
<span class="first">
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote %>
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
</span>

View file

@ -6,4 +6,4 @@
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.first
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote

View file

@ -6,5 +6,5 @@
per_page : number of items to fetch per page
remote : data-remote
span.first
== link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
== link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote
'

View file

@ -7,5 +7,5 @@
remote: data-remote
-%>
<span class="last">
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote %>
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote %>
</span>

View file

@ -6,4 +6,4 @@
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.last
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote

View file

@ -6,5 +6,5 @@
per_page : number of items to fetch per page
remote : data-remote
span.last
== link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
== link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote
'

View file

@ -7,5 +7,5 @@
remote: data-remote
-%>
<span class="next">
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote %>
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
</span>

View file

@ -6,4 +6,4 @@
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.next
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote

View file

@ -6,5 +6,5 @@
per_page : number of items to fetch per page
remote : data-remote
span.next
== link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
== link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote
'

View file

@ -8,5 +8,5 @@
remote: data-remote
-%>
<span class="page<%= ' current' if page.current? %>">
<%= link_to_unless page.current?, page, url, {:remote => remote, :rel => page.rel} %>
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
</span>

View file

@ -6,5 +6,5 @@
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span{:class => "page#{' current' if page.current?}"}
= link_to_unless page.current?, page, url, {:remote => remote, :rel => page.rel}
%span{class: "page#{' current' if page.current?}"}
= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel}

View file

@ -7,5 +7,5 @@
per_page : number of items to fetch per page
remote : data-remote
span class="page#{' current' if page.current?}"
== link_to_unless page.current?, page, url, {:remote => remote, :rel => page.rel}
== link_to_unless page.current?, page, url, {remote: remote, rel: page.rel}
'

View file

@ -7,5 +7,5 @@
remote: data-remote
-%>
<span class="prev">
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote %>
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
</span>

View file

@ -6,4 +6,4 @@
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.prev
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote

View file

@ -6,5 +6,5 @@
per_page : number of items to fetch per page
remote : data-remote
span.prev
== link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
== link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote
'

View file

@ -33,7 +33,7 @@ module Kaminari
#
# Ajax:
#
# <%= link_to_previous_page @items, 'Previous Page', :remote => true %>
# <%= 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.
@ -61,7 +61,7 @@ module Kaminari
#
# Ajax:
#
# <%= link_to_next_page @items, 'Next Page', :remote => true %>
# <%= link_to_next_page @items, 'Next Page', remote: true %>
#
# By default, it renders nothing if there are no more results on the next page.
# You can customize this output by passing a block.
@ -94,7 +94,7 @@ module Kaminari
# The namespace will be cutted out and only the last name will be used.
# Override this with the <tt>:entry_name</tt> parameter:
#
# <%= page_entries_info @posts, :entry_name => 'item' %>
# <%= page_entries_info @posts, entry_name: 'item' %>
# #-> Displaying items 6 - 10 of 26 in total
def page_entries_info(collection, entry_name: nil)
entry_name = if entry_name