kaminari-core 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/kaminari-core.gemspec +1 -1
- data/lib/generators/kaminari/config_generator.rb +1 -0
- data/lib/generators/kaminari/templates/kaminari_config.rb +2 -0
- data/lib/generators/kaminari/views_generator.rb +1 -0
- data/lib/kaminari/core.rb +1 -0
- data/lib/kaminari/core/version.rb +2 -1
- data/lib/kaminari/engine.rb +1 -0
- data/lib/kaminari/exceptions.rb +1 -0
- data/lib/kaminari/helpers/helper_methods.rb +105 -34
- data/lib/kaminari/helpers/paginator.rb +8 -3
- data/lib/kaminari/helpers/tags.rb +3 -2
- data/lib/kaminari/models/array_extension.rb +2 -1
- data/lib/kaminari/models/configuration_methods.rb +4 -4
- data/lib/kaminari/models/page_scope_methods.rb +8 -2
- data/lib/kaminari/railtie.rb +1 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b5e5dc2c53e8e1194787c1d7767b4f68a2f74ea42125b9be84a52b14c47576
|
4
|
+
data.tar.gz: 0d515874f25e93549891b1d633fb34159075ec32148e93e289b47fb24e45a81a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2a5687801a8e2b4ae370b206b8d6df3a488fd920f9592a66946c5069b2d90ef72b6f7970517fdc639224e4412b1e4e78cf8da239a484d3452fd62df77b65009
|
7
|
+
data.tar.gz: 8f6e7fad6773b7669002c5df184439b193bc0021cb212a1492fca7adb5735ec92df0c126d2fa3aee50dce82b2ca1ade0bbbf65bf4ede0603cd497f6df456f78c
|
data/kaminari-core.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Kaminari.configure do |config|
|
3
4
|
# config.default_per_page = 25
|
4
5
|
# config.max_per_page = nil
|
@@ -8,5 +9,6 @@ Kaminari.configure do |config|
|
|
8
9
|
# config.right = 0
|
9
10
|
# config.page_method_name = :page
|
10
11
|
# config.param_name = :page
|
12
|
+
# config.max_pages = nil
|
11
13
|
# config.params_on_first_page = false
|
12
14
|
end
|
data/lib/kaminari/core.rb
CHANGED
data/lib/kaminari/engine.rb
CHANGED
data/lib/kaminari/exceptions.rb
CHANGED
@@ -2,7 +2,97 @@
|
|
2
2
|
|
3
3
|
module Kaminari
|
4
4
|
module Helpers
|
5
|
+
|
6
|
+
# The Kaminari::Helpers::UrlHelper module provides useful methods for
|
7
|
+
# generating a path or url to a particlar page. A class must implement the
|
8
|
+
# following methods:
|
9
|
+
#
|
10
|
+
# * <tt>url_for</tt>: A method that generates an actual path
|
11
|
+
# * <tt>params</tt>: A method that returns query string parameters
|
12
|
+
# * <tt>request</tt>: A method that returns a Rack::Request object
|
13
|
+
#
|
14
|
+
# A normal Rails controller implements all the methods, which makes it
|
15
|
+
# trivial to use this module:
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# class UsersController < ApplicationController
|
20
|
+
# include Kaminari::Helpers::UrlHelper
|
21
|
+
#
|
22
|
+
# def index
|
23
|
+
# @users = User.page(1)
|
24
|
+
#
|
25
|
+
# path_to_next_page(@items)
|
26
|
+
# # => /items?page=2
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
module UrlHelper
|
31
|
+
|
32
|
+
# A helper that calculates the url to the next page.
|
33
|
+
#
|
34
|
+
# ==== Examples
|
35
|
+
# Basic usage:
|
36
|
+
#
|
37
|
+
# <%= next_page_url @items %>
|
38
|
+
# #-> http://www.example.org/items?page=2
|
39
|
+
#
|
40
|
+
# It will return `nil` if there is no next page.
|
41
|
+
def next_page_url(scope, options = {})
|
42
|
+
"#{request.base_url}#{next_page_path(scope, options)}" if scope.next_page
|
43
|
+
end
|
44
|
+
alias path_to_next_url next_page_url
|
45
|
+
|
46
|
+
# A helper that calculates the url to the previous page.
|
47
|
+
#
|
48
|
+
# ==== Examples
|
49
|
+
# Basic usage:
|
50
|
+
#
|
51
|
+
# <%= prev_page_url @items %>
|
52
|
+
# #-> http://www.example.org/items
|
53
|
+
#
|
54
|
+
# It will return `nil` if there is no previous page.
|
55
|
+
def prev_page_url(scope, options = {})
|
56
|
+
"#{request.base_url}#{prev_page_path(scope, options)}" if scope.prev_page
|
57
|
+
end
|
58
|
+
alias previous_page_url prev_page_url
|
59
|
+
alias url_to_prev_page prev_page_url
|
60
|
+
alias url_to_previous_page prev_page_url
|
61
|
+
|
62
|
+
# A helper that calculates the path to the next page.
|
63
|
+
#
|
64
|
+
# ==== Examples
|
65
|
+
# Basic usage:
|
66
|
+
#
|
67
|
+
# <%= path_to_next_page @items %>
|
68
|
+
# #-> /items?page=2
|
69
|
+
#
|
70
|
+
# It will return `nil` if there is no next page.
|
71
|
+
def next_page_path(scope, options = {})
|
72
|
+
Kaminari::Helpers::NextPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.next_page
|
73
|
+
end
|
74
|
+
alias path_to_next_page next_page_path
|
75
|
+
|
76
|
+
# A helper that calculates the path to the previous page.
|
77
|
+
#
|
78
|
+
# ==== Examples
|
79
|
+
# Basic usage:
|
80
|
+
#
|
81
|
+
# <%= path_to_prev_page @items %>
|
82
|
+
# #-> /items
|
83
|
+
#
|
84
|
+
# It will return `nil` if there is no previous page.
|
85
|
+
def prev_page_path(scope, options = {})
|
86
|
+
Kaminari::Helpers::PrevPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.prev_page
|
87
|
+
end
|
88
|
+
alias previous_page_path prev_page_path
|
89
|
+
alias path_to_previous_page prev_page_path
|
90
|
+
alias path_to_prev_page prev_page_path
|
91
|
+
end
|
92
|
+
|
5
93
|
module HelperMethods
|
94
|
+
include UrlHelper
|
95
|
+
|
6
96
|
# A helper that renders the pagination links.
|
7
97
|
#
|
8
98
|
# <%= paginate @articles %>
|
@@ -22,7 +112,7 @@ module Kaminari
|
|
22
112
|
options[:total_pages] ||= scope.total_pages
|
23
113
|
options.reverse_merge! current_page: scope.current_page, per_page: scope.limit_value, remote: false
|
24
114
|
|
25
|
-
paginator = paginator_class.new (template || self), options
|
115
|
+
paginator = paginator_class.new (template || self), **options
|
26
116
|
paginator.to_s
|
27
117
|
end
|
28
118
|
|
@@ -49,8 +139,10 @@ module Kaminari
|
|
49
139
|
options.except! :params, :param_name
|
50
140
|
options[:rel] ||= 'prev'
|
51
141
|
|
52
|
-
|
53
|
-
|
142
|
+
if prev_page
|
143
|
+
link_to name, prev_page, options
|
144
|
+
elsif block_given?
|
145
|
+
yield
|
54
146
|
end
|
55
147
|
end
|
56
148
|
alias link_to_prev_page link_to_previous_page
|
@@ -78,8 +170,10 @@ module Kaminari
|
|
78
170
|
options.except! :params, :param_name
|
79
171
|
options[:rel] ||= 'next'
|
80
172
|
|
81
|
-
|
82
|
-
|
173
|
+
if next_page
|
174
|
+
link_to name, next_page, options
|
175
|
+
elsif block_given?
|
176
|
+
yield
|
83
177
|
end
|
84
178
|
end
|
85
179
|
|
@@ -109,7 +203,10 @@ module Kaminari
|
|
109
203
|
if collection.total_pages < 2
|
110
204
|
t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count)
|
111
205
|
else
|
112
|
-
|
206
|
+
from = collection.offset_value + 1
|
207
|
+
to = collection.offset_value + (collection.respond_to?(:records) ? collection.records : collection.to_a).size
|
208
|
+
|
209
|
+
t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: from, last: to, total: collection.total_count)
|
113
210
|
end.html_safe
|
114
211
|
end
|
115
212
|
|
@@ -136,36 +233,10 @@ module Kaminari
|
|
136
233
|
prev_page = path_to_prev_page(scope, options)
|
137
234
|
|
138
235
|
output = String.new
|
139
|
-
output <<
|
140
|
-
output <<
|
236
|
+
output << %Q|<link rel="next" href="#{next_page}"></link>| if next_page
|
237
|
+
output << %Q|<link rel="prev" href="#{prev_page}"></link>| if prev_page
|
141
238
|
output.html_safe
|
142
239
|
end
|
143
|
-
|
144
|
-
# A helper that calculates the path to the next page.
|
145
|
-
#
|
146
|
-
# ==== Examples
|
147
|
-
# Basic usage:
|
148
|
-
#
|
149
|
-
# <%= path_to_next_page @items %>
|
150
|
-
# #-> /items?page=2
|
151
|
-
#
|
152
|
-
# It will return `nil` if there is no next page.
|
153
|
-
def path_to_next_page(scope, options = {})
|
154
|
-
Kaminari::Helpers::NextPage.new(self, options.reverse_merge(current_page: scope.current_page)).url if scope.next_page
|
155
|
-
end
|
156
|
-
|
157
|
-
# A helper that calculates the path to the previous page.
|
158
|
-
#
|
159
|
-
# ==== Examples
|
160
|
-
# Basic usage:
|
161
|
-
#
|
162
|
-
# <%= path_to_prev_page @items %>
|
163
|
-
# #-> /items
|
164
|
-
#
|
165
|
-
# It will return `nil` if there is no previous page.
|
166
|
-
def path_to_prev_page(scope, options = {})
|
167
|
-
Kaminari::Helpers::PrevPage.new(self, options.reverse_merge(current_page: scope.current_page)).url if scope.prev_page
|
168
|
-
end
|
169
240
|
end
|
170
241
|
end
|
171
242
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'active_support/inflector'
|
3
4
|
require 'kaminari/helpers/tags'
|
4
5
|
|
@@ -26,7 +27,11 @@ module Kaminari
|
|
26
27
|
# render given block as a view template
|
27
28
|
def render(&block)
|
28
29
|
instance_eval(&block) if @options[:total_pages] > 1
|
29
|
-
|
30
|
+
|
31
|
+
# This allows for showing fall-back HTML when there's only one page:
|
32
|
+
#
|
33
|
+
# <%= paginate(@search_results) || "Showing all search results" %>
|
34
|
+
@output_buffer.presence
|
30
35
|
end
|
31
36
|
|
32
37
|
# enumerate each page providing PageProxy object as the block parameter
|
@@ -54,13 +59,13 @@ module Kaminari
|
|
54
59
|
private :relevant_pages
|
55
60
|
|
56
61
|
def page_tag(page)
|
57
|
-
@last = Page.new @template,
|
62
|
+
@last = Page.new @template, **@options.merge(page: page)
|
58
63
|
end
|
59
64
|
|
60
65
|
%w[first_page prev_page next_page last_page gap].each do |tag|
|
61
66
|
eval <<-DEF, nil, __FILE__, __LINE__ + 1
|
62
67
|
def #{tag}_tag
|
63
|
-
@last = #{tag.classify}.new @template,
|
68
|
+
@last = #{tag.classify}.new @template, **@options
|
64
69
|
end
|
65
70
|
DEF
|
66
71
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Kaminari
|
3
4
|
module Helpers
|
4
|
-
|
5
|
+
PARAM_KEY_EXCEPT_LIST = [:authenticity_token, :commit, :utf8, :_method, :script_name].freeze
|
5
6
|
|
6
7
|
# A tag stands for an HTML tag inside the paginator.
|
7
8
|
# Basically, a tag has its own partial template file, so every tag can be
|
@@ -23,7 +24,7 @@ module Kaminari
|
|
23
24
|
# @params in Rails 5 no longer inherits from Hash
|
24
25
|
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
|
25
26
|
@params = @params.with_indifferent_access
|
26
|
-
@params.except!(*
|
27
|
+
@params.except!(*PARAM_KEY_EXCEPT_LIST)
|
27
28
|
@params.merge! params
|
28
29
|
end
|
29
30
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'active_support/core_ext/module'
|
3
4
|
module Kaminari
|
4
5
|
# Kind of Array that can paginate
|
@@ -34,7 +35,7 @@ module Kaminari
|
|
34
35
|
|
35
36
|
# Used for page_entry_info
|
36
37
|
def entry_name(options = {})
|
37
|
-
I18n.t('helpers.page_entries_info.entry', options.reverse_merge(default: ENTRY.pluralize(options[:count])))
|
38
|
+
I18n.t('helpers.page_entries_info.entry', **options.reverse_merge(default: ENTRY.pluralize(options[:count])))
|
38
39
|
end
|
39
40
|
|
40
41
|
# items at the specified "page"
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
2
5
|
module Kaminari
|
3
6
|
module ConfigurationMethods #:nodoc:
|
4
|
-
|
5
|
-
base.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
7
|
+
extend ActiveSupport::Concern
|
8
8
|
module ClassMethods #:nodoc:
|
9
9
|
# Overrides the default +per_page+ value per model
|
10
10
|
# class Article < ActiveRecord::Base
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Kaminari
|
3
4
|
module PageScopeMethods
|
4
5
|
# Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
|
@@ -19,7 +20,8 @@ module Kaminari
|
|
19
20
|
|
20
21
|
def max_paginates_per(new_max_per_page)
|
21
22
|
@_max_per_page = new_max_per_page
|
22
|
-
|
23
|
+
|
24
|
+
per (defined?(@_per) && @_per) || default_per_page, max_per_page: new_max_per_page
|
23
25
|
end
|
24
26
|
|
25
27
|
def padding(num)
|
@@ -54,7 +56,11 @@ module Kaminari
|
|
54
56
|
|
55
57
|
# Current per-page number
|
56
58
|
def current_per_page
|
57
|
-
|
59
|
+
ActiveSupport::Deprecation.warn '#current_per_page is deprecated and will be removed in the next major ' \
|
60
|
+
'version. Please use #limit_value instead.'
|
61
|
+
|
62
|
+
limit_value
|
63
|
+
# (defined?(@_per) && @_per) || default_per_page
|
58
64
|
end
|
59
65
|
|
60
66
|
# Next page number in the collection
|
data/lib/kaminari/railtie.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaminari-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.6.14
|
109
|
+
rubygems_version: 3.1.2
|
111
110
|
signing_key:
|
112
111
|
specification_version: 4
|
113
112
|
summary: Kaminari's core pagination library
|