kaminari-core 1.1.1 → 1.2.1

This diff has not been reviewed by any users.
Log in in order to be able to vote.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8c36b983453967adcb35acf8e5a07c87fdc811c9d285428a599ec2ced09064e
4
- data.tar.gz: 1309e2966e772d9410a1fd9c02bc09bb51f6c46d0a73316b3332597c5f2675bc
3
+ metadata.gz: 073f49d2cee52f15a94e03ea16932a7a35c140e21126fcaf32be27b16dd9126b
4
+ data.tar.gz: d18374c251ef627e9ddb5b57cd0350c0092b139f2926d578b8f006f07db3403c
5
5
  SHA512:
6
- metadata.gz: aeb83e6fa8f491923a819512390353f2de9193f986bcdecf9f9ec4f4c1f5b4a8924a0561654dd24b020b076168651f2294e1008794c46d22b80b31320255a5be
7
- data.tar.gz: e97a0d7f44ae639a019afcde742caa0219c37c7867a905763ea451964a6e6e4be2b946c2262cf62127c6a80cc621be8c717853b9b2aa4e6b65f97e3f573e872b
6
+ metadata.gz: 4d22379f9e5189f50288741c894323d9e36d5dc983e7eda26034db2f1900f4593223c53a3084b03fcacd391af039680bf9a22d41a3d503c291f7e7513a964b02
7
+ data.tar.gz: a1b5d908d102b3929e58e8cbeec729b07c8a1b084aac2675562db0580bdc9970d41ef9c37e6d085781f78dc1510c0b41f78f0d5a1592df518129129aaa80747d
@@ -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'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  module Generators
4
5
  # rails g kaminari:config
@@ -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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  end
4
5
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  module Core
4
- VERSION = '1.1.1'
5
+ VERSION = '1.2.1'
5
6
  end
6
7
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari #:nodoc:
3
4
  class Engine < ::Rails::Engine #:nodoc:
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  class ZeroPerPageOperation < ZeroDivisionError; end
4
5
  end
@@ -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
- link_to_if prev_page, name, prev_page, options do
53
- yield if block_given?
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
- link_to_if next_page, name, next_page, options do
82
- yield if block_given?
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
- t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: collection.offset_value + 1, last: [collection.offset_value + collection.limit_value, collection.total_count].min, total: collection.total_count)
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 << tag(:link, rel: "next", href: next_page) if next_page
140
- output << tag(:link, rel: "prev", href: prev_page) if prev_page
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
- @output_buffer
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, @options.merge(page: page)
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, @options
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
- PARAM_KEY_BLACKLIST = [:authenticity_token, :commit, :utf8, :_method, :script_name].freeze
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!(*PARAM_KEY_BLACKLIST)
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
- def self.included(base)
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
- per current_per_page, max_per_page: new_max_per_page
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
- (defined?(@_per) && @_per) || default_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
58
64
  end
59
65
 
60
66
  # Next page number in the collection
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  class Railtie < ::Rails::Railtie #:nodoc:
4
5
  # Doesn't actually do anything. Just keeping this hook point, mainly for compatibility
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.1.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: 2017-10-21 00:00:00.000000000 Z
11
+ date: 2020-05-27 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
- rubyforge_project:
110
- rubygems_version: 2.6.14
109
+ rubygems_version: 3.2.0.pre1
111
110
  signing_key:
112
111
  specification_version: 4
113
112
  summary: Kaminari's core pagination library