kaminari-core 1.0.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1 -0
- data/README.md +2 -2
- data/app/views/kaminari/_paginator.html.erb +1 -1
- data/kaminari-core.gemspec +3 -2
- 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 +3 -0
- data/lib/kaminari/config.rb +26 -14
- 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 +108 -35
- data/lib/kaminari/helpers/paginator.rb +10 -8
- data/lib/kaminari/helpers/tags.rb +29 -2
- data/lib/kaminari/models/array_extension.rb +2 -1
- data/lib/kaminari/models/configuration_methods.rb +4 -1
- data/lib/kaminari/models/page_scope_methods.rb +15 -6
- data/lib/kaminari/railtie.rb +1 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 073f49d2cee52f15a94e03ea16932a7a35c140e21126fcaf32be27b16dd9126b
|
4
|
+
data.tar.gz: d18374c251ef627e9ddb5b57cd0350c0092b139f2926d578b8f006f07db3403c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d22379f9e5189f50288741c894323d9e36d5dc983e7eda26034db2f1900f4593223c53a3084b03fcacd391af039680bf9a22d41a3d503c291f7e7513a964b02
|
7
|
+
data.tar.gz: a1b5d908d102b3929e58e8cbeec729b07c8a1b084aac2675562db0580bdc9970d41ef9c37e6d085781f78dc1510c0b41f78f0d5a1592df518129129aaa80747d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
See https://github.com/kaminari/kaminari/tree/master/CHANGELOG.md for changes.
|
data/README.md
CHANGED
@@ -18,12 +18,12 @@ And bundle.
|
|
18
18
|
|
19
19
|
This gem is basically an internal gem that will be automatically bundled from kaminari gem or kaminari adapter gems.
|
20
20
|
|
21
|
-
See [Kaminari README](https://github.com/
|
21
|
+
See [Kaminari README](https://github.com/kaminari/kaminari/blob/master/README.md) for the documentation.
|
22
22
|
|
23
23
|
|
24
24
|
## Contributing
|
25
25
|
|
26
|
-
Pull requests are welcome on GitHub at https://github.com/
|
26
|
+
Pull requests are welcome on GitHub at https://github.com/kaminari/kaminari.
|
27
27
|
|
28
28
|
|
29
29
|
## License
|
@@ -7,7 +7,7 @@
|
|
7
7
|
paginator: the paginator that renders the pagination tags inside
|
8
8
|
-%>
|
9
9
|
<%= paginator.render do -%>
|
10
|
-
<nav class="pagination">
|
10
|
+
<nav class="pagination" role="navigation" aria-label="pager">
|
11
11
|
<%= first_page_tag unless current_page.first? %>
|
12
12
|
<%= prev_page_tag unless current_page.first? %>
|
13
13
|
<% each_page do |page| -%>
|
data/kaminari-core.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
2
|
+
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'kaminari/core/version'
|
@@ -12,8 +12,9 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = "Kaminari's core pagination library"
|
14
14
|
spec.description = 'kaminari-core includes pagination logic independent from ORMs and view libraries'
|
15
|
-
spec.homepage = 'https://github.com/
|
15
|
+
spec.homepage = 'https://github.com/kaminari/kaminari'
|
16
16
|
spec.license = "MIT"
|
17
|
+
spec.required_ruby_version = '>= 2.0.0'
|
17
18
|
|
18
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
20
|
spec.require_paths = ["lib"]
|
@@ -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
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Kaminari
|
3
4
|
module Generators
|
4
5
|
# rails g kaminari:views THEME
|
@@ -110,6 +111,8 @@ BANNER
|
|
110
111
|
end
|
111
112
|
|
112
113
|
module GitHubApiHelper
|
114
|
+
require 'open-uri'
|
115
|
+
|
113
116
|
def get_files_in_master
|
114
117
|
master_tree_sha = open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
|
115
118
|
ActiveSupport::JSON.decode(json.read)['object']['sha']
|
data/lib/kaminari/config.rb
CHANGED
@@ -1,28 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'active_support/configurable'
|
3
2
|
|
4
3
|
module Kaminari
|
5
4
|
# Configures global settings for Kaminari
|
6
5
|
# Kaminari.configure do |config|
|
7
6
|
# config.default_per_page = 10
|
8
7
|
# end
|
9
|
-
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
yield config
|
11
|
+
end
|
12
|
+
|
13
|
+
def config
|
14
|
+
@_config ||= Config.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Config
|
19
|
+
attr_accessor :default_per_page, :max_per_page, :window, :outer_window, :left, :right, :page_method_name, :max_pages, :params_on_first_page
|
20
|
+
attr_writer :param_name
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
def initialize
|
23
|
+
@default_per_page = 25
|
24
|
+
@max_per_page = nil
|
25
|
+
@window = 4
|
26
|
+
@outer_window = 0
|
27
|
+
@left = 0
|
28
|
+
@right = 0
|
29
|
+
@page_method_name = :page
|
30
|
+
@param_name = :page
|
31
|
+
@max_pages = nil
|
32
|
+
@params_on_first_page = false
|
33
|
+
end
|
22
34
|
|
23
35
|
# If param_name was given as a callable object, call it when returning
|
24
36
|
def param_name
|
25
|
-
|
37
|
+
@param_name.respond_to?(:call) ? @param_name.call : @param_name
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
data/lib/kaminari/core.rb
CHANGED
data/lib/kaminari/engine.rb
CHANGED
data/lib/kaminari/exceptions.rb
CHANGED
@@ -1,6 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kaminari
|
2
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
|
+
|
3
93
|
module HelperMethods
|
94
|
+
include UrlHelper
|
95
|
+
|
4
96
|
# A helper that renders the pagination links.
|
5
97
|
#
|
6
98
|
# <%= paginate @articles %>
|
@@ -20,7 +112,7 @@ module Kaminari
|
|
20
112
|
options[:total_pages] ||= scope.total_pages
|
21
113
|
options.reverse_merge! current_page: scope.current_page, per_page: scope.limit_value, remote: false
|
22
114
|
|
23
|
-
paginator = paginator_class.new (template || self), options
|
115
|
+
paginator = paginator_class.new (template || self), **options
|
24
116
|
paginator.to_s
|
25
117
|
end
|
26
118
|
|
@@ -47,8 +139,10 @@ module Kaminari
|
|
47
139
|
options.except! :params, :param_name
|
48
140
|
options[:rel] ||= 'prev'
|
49
141
|
|
50
|
-
|
51
|
-
|
142
|
+
if prev_page
|
143
|
+
link_to name, prev_page, options
|
144
|
+
elsif block_given?
|
145
|
+
yield
|
52
146
|
end
|
53
147
|
end
|
54
148
|
alias link_to_prev_page link_to_previous_page
|
@@ -76,8 +170,10 @@ module Kaminari
|
|
76
170
|
options.except! :params, :param_name
|
77
171
|
options[:rel] ||= 'next'
|
78
172
|
|
79
|
-
|
80
|
-
|
173
|
+
if next_page
|
174
|
+
link_to name, next_page, options
|
175
|
+
elsif block_given?
|
176
|
+
yield
|
81
177
|
end
|
82
178
|
end
|
83
179
|
|
@@ -99,7 +195,7 @@ module Kaminari
|
|
99
195
|
# #-> Displaying items 6 - 10 of 26 in total
|
100
196
|
def page_entries_info(collection, entry_name: nil)
|
101
197
|
entry_name = if entry_name
|
102
|
-
entry_name.pluralize(collection.size)
|
198
|
+
entry_name.pluralize(collection.size, I18n.locale)
|
103
199
|
else
|
104
200
|
collection.entry_name(count: collection.size).downcase
|
105
201
|
end
|
@@ -107,7 +203,10 @@ module Kaminari
|
|
107
203
|
if collection.total_pages < 2
|
108
204
|
t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count)
|
109
205
|
else
|
110
|
-
|
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)
|
111
210
|
end.html_safe
|
112
211
|
end
|
113
212
|
|
@@ -134,36 +233,10 @@ module Kaminari
|
|
134
233
|
prev_page = path_to_prev_page(scope, options)
|
135
234
|
|
136
235
|
output = String.new
|
137
|
-
output <<
|
138
|
-
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
|
139
238
|
output.html_safe
|
140
239
|
end
|
141
|
-
|
142
|
-
# A helper that calculates the path to the next page.
|
143
|
-
#
|
144
|
-
# ==== Examples
|
145
|
-
# Basic usage:
|
146
|
-
#
|
147
|
-
# <%= path_to_next_page @items %>
|
148
|
-
# #-> /items?page=2
|
149
|
-
#
|
150
|
-
# It will return `nil` if there is no next page.
|
151
|
-
def path_to_next_page(scope, options = {})
|
152
|
-
Kaminari::Helpers::NextPage.new(self, options.reverse_merge(current_page: scope.current_page)).url if scope.next_page
|
153
|
-
end
|
154
|
-
|
155
|
-
# A helper that calculates the path to the previous page.
|
156
|
-
#
|
157
|
-
# ==== Examples
|
158
|
-
# Basic usage:
|
159
|
-
#
|
160
|
-
# <%= path_to_prev_page @items %>
|
161
|
-
# #-> /items
|
162
|
-
#
|
163
|
-
# It will return `nil` if there is no previous page.
|
164
|
-
def path_to_prev_page(scope, options = {})
|
165
|
-
Kaminari::Helpers::PrevPage.new(self, options.reverse_merge(current_page: scope.current_page)).url if scope.prev_page
|
166
|
-
end
|
167
240
|
end
|
168
241
|
end
|
169
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
|
|
@@ -6,11 +7,8 @@ module Kaminari
|
|
6
7
|
module Helpers
|
7
8
|
# The main container tag
|
8
9
|
class Paginator < Tag
|
9
|
-
def initialize(template, window: nil, outer_window:
|
10
|
-
outer_window
|
11
|
-
left ||= Kaminari.config.left
|
12
|
-
right ||= Kaminari.config.right
|
13
|
-
@window_options = {window: window || inner_window || Kaminari.config.window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right}
|
10
|
+
def initialize(template, window: nil, outer_window: Kaminari.config.outer_window, left: Kaminari.config.left, right: Kaminari.config.right, inner_window: Kaminari.config.window, **options) #:nodoc:
|
11
|
+
@window_options = {window: window || inner_window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right}
|
14
12
|
|
15
13
|
@template, @options, @theme, @views_prefix, @last = template, options, options[:theme], options[:views_prefix], nil
|
16
14
|
@window_options.merge! @options
|
@@ -29,7 +27,11 @@ module Kaminari
|
|
29
27
|
# render given block as a view template
|
30
28
|
def render(&block)
|
31
29
|
instance_eval(&block) if @options[:total_pages] > 1
|
32
|
-
|
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
|
33
35
|
end
|
34
36
|
|
35
37
|
# enumerate each page providing PageProxy object as the block parameter
|
@@ -57,13 +59,13 @@ module Kaminari
|
|
57
59
|
private :relevant_pages
|
58
60
|
|
59
61
|
def page_tag(page)
|
60
|
-
@last = Page.new @template,
|
62
|
+
@last = Page.new @template, **@options.merge(page: page)
|
61
63
|
end
|
62
64
|
|
63
65
|
%w[first_page prev_page next_page last_page gap].each do |tag|
|
64
66
|
eval <<-DEF, nil, __FILE__, __LINE__ + 1
|
65
67
|
def #{tag}_tag
|
66
|
-
@last = #{tag.classify}.new @template,
|
68
|
+
@last = #{tag.classify}.new @template, **@options
|
67
69
|
end
|
68
70
|
DEF
|
69
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, :original_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
|
|
@@ -117,6 +118,19 @@ module Kaminari
|
|
117
118
|
# The "previous" page of the current page
|
118
119
|
class PrevPage < Tag
|
119
120
|
include Link
|
121
|
+
|
122
|
+
# TODO: Remove this initializer before 1.3.0.
|
123
|
+
def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) #:nodoc:
|
124
|
+
# params in Rails 5 may not be a Hash either,
|
125
|
+
# so it must be converted to a Hash to be merged into @params
|
126
|
+
if params && params.respond_to?(:to_unsafe_h)
|
127
|
+
ActiveSupport::Deprecation.warn 'Explicitly passing params to helpers could be omitted.'
|
128
|
+
params = params.to_unsafe_h
|
129
|
+
end
|
130
|
+
|
131
|
+
super(template, params: params, param_name: param_name, theme: theme, views_prefix: views_prefix, **options)
|
132
|
+
end
|
133
|
+
|
120
134
|
def page #:nodoc:
|
121
135
|
@options[:current_page] - 1
|
122
136
|
end
|
@@ -125,6 +139,19 @@ module Kaminari
|
|
125
139
|
# The "next" page of the current page
|
126
140
|
class NextPage < Tag
|
127
141
|
include Link
|
142
|
+
|
143
|
+
# TODO: Remove this initializer before 1.3.0.
|
144
|
+
def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) #:nodoc:
|
145
|
+
# params in Rails 5 may not be a Hash either,
|
146
|
+
# so it must be converted to a Hash to be merged into @params
|
147
|
+
if params && params.respond_to?(:to_unsafe_h)
|
148
|
+
ActiveSupport::Deprecation.warn 'Explicitly passing params to helpers could be omitted.'
|
149
|
+
params = params.to_unsafe_h
|
150
|
+
end
|
151
|
+
|
152
|
+
super(template, params: params, param_name: param_name, theme: theme, views_prefix: views_prefix, **options)
|
153
|
+
end
|
154
|
+
|
128
155
|
def page #:nodoc:
|
129
156
|
@options[:current_page] + 1
|
130
157
|
end
|
@@ -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,4 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
2
5
|
module Kaminari
|
3
6
|
module ConfigurationMethods #:nodoc:
|
4
7
|
extend ActiveSupport::Concern
|
@@ -49,7 +52,7 @@ module Kaminari
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def max_pages_per(val)
|
52
|
-
ActiveSupport::Deprecation.warn 'max_pages_per is deprecated. Use max_pages instead.'
|
55
|
+
ActiveSupport::Deprecation.warn 'max_pages_per is deprecated. Use max_pages instead.'
|
53
56
|
max_pages val
|
54
57
|
end
|
55
58
|
end
|
@@ -1,18 +1,17 @@
|
|
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
|
5
6
|
# Model.page(3).per(10)
|
6
7
|
def per(num, max_per_page: nil)
|
7
8
|
max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
|
8
|
-
@_per = num
|
9
|
-
if num.
|
10
|
-
limit(max_per_page).offset(offset_value / limit_value * max_per_page)
|
11
|
-
elsif (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
|
9
|
+
@_per = (num || default_per_page).to_i
|
10
|
+
if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
|
12
11
|
self
|
13
12
|
elsif n.zero?
|
14
13
|
limit(n)
|
15
|
-
elsif max_per_page && max_per_page < n
|
14
|
+
elsif max_per_page && (max_per_page < n)
|
16
15
|
limit(max_per_page).offset(offset_value / limit_value * max_per_page)
|
17
16
|
else
|
18
17
|
limit(n).offset(offset_value / limit_value * n)
|
@@ -21,7 +20,8 @@ module Kaminari
|
|
21
20
|
|
22
21
|
def max_paginates_per(new_max_per_page)
|
23
22
|
@_max_per_page = new_max_per_page
|
24
|
-
|
23
|
+
|
24
|
+
per (defined?(@_per) && @_per) || default_per_page, max_per_page: new_max_per_page
|
25
25
|
end
|
26
26
|
|
27
27
|
def padding(num)
|
@@ -54,6 +54,15 @@ module Kaminari
|
|
54
54
|
raise ZeroPerPageOperation, "Current page was incalculable. Perhaps you called .per(0)?"
|
55
55
|
end
|
56
56
|
|
57
|
+
# Current per-page number
|
58
|
+
def current_per_page
|
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
|
64
|
+
end
|
65
|
+
|
57
66
|
# Next page number in the collection
|
58
67
|
def next_page
|
59
68
|
current_page + 1 unless last_page? || out_of_range?
|
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.1
|
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-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- CHANGELOG.md
|
49
50
|
- MIT-LICENSE
|
50
51
|
- README.md
|
51
52
|
- app/views/kaminari/_first_page.html.erb
|
@@ -86,7 +87,7 @@ files:
|
|
86
87
|
- lib/kaminari/models/configuration_methods.rb
|
87
88
|
- lib/kaminari/models/page_scope_methods.rb
|
88
89
|
- lib/kaminari/railtie.rb
|
89
|
-
homepage: https://github.com/
|
90
|
+
homepage: https://github.com/kaminari/kaminari
|
90
91
|
licenses:
|
91
92
|
- MIT
|
92
93
|
metadata: {}
|
@@ -98,15 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
99
|
requirements:
|
99
100
|
- - ">="
|
100
101
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
+
version: 2.0.0
|
102
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
104
|
requirements:
|
104
105
|
- - ">="
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.6.8
|
109
|
+
rubygems_version: 3.2.0.pre1
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Kaminari's core pagination library
|