kaminari-core 1.1.0 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13bfdf7c93e9183a36d3e99699eee59895948472c66d31f97bbb99a768ec89d0
4
- data.tar.gz: 44c167d6cfe80ecca307ee3a31ac3ebbd8766c09b259686442cf22d4968df9d3
3
+ metadata.gz: f97cdb29c6cc0f87f4a3b2439bc98d4015894053aece52f9685f9053d828eee2
4
+ data.tar.gz: fda4562a4e0fe69e90af6276b78575dc6dbbe6f42f98ffecd70bd54ddf7cf5cc
5
5
  SHA512:
6
- metadata.gz: 89492adf61154a7eeabd3eac4e4429dc82802596de85d04066f76523f5ca1b6a89d493814b30537dd29e245a2d92f88d263688fb0ed3ce7cdbb979d1ee2ccf71
7
- data.tar.gz: 25cc4d4c811c80e15cd271f49dd0de85ba83749a44411f3ce64de441b32de01f1122448e7d939831eb42cb5ba3269e4953b021a4f8abb29a949e717ee098c67b
6
+ metadata.gz: 0dbaec420bee38126a89931872d0d4dcc37772a7bb22d0c97844399b95c55cc4677a2634d1b908b1c4c5c60a0319ab5b88d8b7bb4f01658db3ecc52400eb9c94
7
+ data.tar.gz: a5294c22cd10b649243d4ebd4ac85481e1ae16b956d2777121926026eb21f2c3ec6c07a799ca02271f0348a76f9cc4fcf409ce0cdbe69672289fdca1e745e800
@@ -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
@@ -113,10 +114,10 @@ BANNER
113
114
  require 'open-uri'
114
115
 
115
116
  def get_files_in_master
116
- master_tree_sha = open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
117
+ master_tree_sha = URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
117
118
  ActiveSupport::JSON.decode(json.read)['object']['sha']
118
119
  end
119
- open('https://api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
120
+ URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
120
121
  blobs = ActiveSupport::JSON.decode(json.read)['tree'].find_all {|i| i['type'] == 'blob' }
121
122
  blobs.map do |blob|
122
123
  [blob['path'], blob['sha']]
@@ -126,7 +127,7 @@ BANNER
126
127
  module_function :get_files_in_master
127
128
 
128
129
  def get_content_for(path)
129
- open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
130
+ URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
130
131
  Base64.decode64(ActiveSupport::JSON.decode(json.read)['content'])
131
132
  end
132
133
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  module Core
4
- VERSION = '1.1.0'
5
+ VERSION = '1.2.2'
5
6
  end
6
7
  end
data/lib/kaminari/core.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Kaminari
3
4
  end
4
5
 
@@ -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,102 @@
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 particular 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 make 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 url_to_next_page next_page_url
45
+
46
+ def path_to_next_url(scope, options = {})
47
+ ActiveSupport::Deprecation.warn 'path_to_next_url is deprecated. Use next_page_url or url_to_next_page instead.'
48
+ next_page_url(scope, options)
49
+ end
50
+
51
+ # A helper that calculates the url to the previous page.
52
+ #
53
+ # ==== Examples
54
+ # Basic usage:
55
+ #
56
+ # <%= prev_page_url @items %>
57
+ # #-> http://www.example.org/items
58
+ #
59
+ # It will return `nil` if there is no previous page.
60
+ def prev_page_url(scope, options = {})
61
+ "#{request.base_url}#{prev_page_path(scope, options)}" if scope.prev_page
62
+ end
63
+ alias previous_page_url prev_page_url
64
+ alias url_to_prev_page prev_page_url
65
+ alias url_to_previous_page prev_page_url
66
+
67
+ # A helper that calculates the path to the next page.
68
+ #
69
+ # ==== Examples
70
+ # Basic usage:
71
+ #
72
+ # <%= path_to_next_page @items %>
73
+ # #-> /items?page=2
74
+ #
75
+ # It will return `nil` if there is no next page.
76
+ def next_page_path(scope, options = {})
77
+ Kaminari::Helpers::NextPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.next_page
78
+ end
79
+ alias path_to_next_page next_page_path
80
+
81
+ # A helper that calculates the path to the previous page.
82
+ #
83
+ # ==== Examples
84
+ # Basic usage:
85
+ #
86
+ # <%= path_to_prev_page @items %>
87
+ # #-> /items
88
+ #
89
+ # It will return `nil` if there is no previous page.
90
+ def prev_page_path(scope, options = {})
91
+ Kaminari::Helpers::PrevPage.new(self, **options.reverse_merge(current_page: scope.current_page)).url if scope.prev_page
92
+ end
93
+ alias previous_page_path prev_page_path
94
+ alias path_to_previous_page prev_page_path
95
+ alias path_to_prev_page prev_page_path
96
+ end
97
+
5
98
  module HelperMethods
99
+ include UrlHelper
100
+
6
101
  # A helper that renders the pagination links.
7
102
  #
8
103
  # <%= paginate @articles %>
@@ -22,7 +117,7 @@ module Kaminari
22
117
  options[:total_pages] ||= scope.total_pages
23
118
  options.reverse_merge! current_page: scope.current_page, per_page: scope.limit_value, remote: false
24
119
 
25
- paginator = paginator_class.new (template || self), options
120
+ paginator = paginator_class.new (template || self), **options
26
121
  paginator.to_s
27
122
  end
28
123
 
@@ -49,8 +144,10 @@ module Kaminari
49
144
  options.except! :params, :param_name
50
145
  options[:rel] ||= 'prev'
51
146
 
52
- link_to_if prev_page, name, prev_page, options do
53
- yield if block_given?
147
+ if prev_page
148
+ link_to name, prev_page, options
149
+ elsif block_given?
150
+ yield
54
151
  end
55
152
  end
56
153
  alias link_to_prev_page link_to_previous_page
@@ -78,8 +175,10 @@ module Kaminari
78
175
  options.except! :params, :param_name
79
176
  options[:rel] ||= 'next'
80
177
 
81
- link_to_if next_page, name, next_page, options do
82
- yield if block_given?
178
+ if next_page
179
+ link_to name, next_page, options
180
+ elsif block_given?
181
+ yield
83
182
  end
84
183
  end
85
184
 
@@ -109,7 +208,10 @@ module Kaminari
109
208
  if collection.total_pages < 2
110
209
  t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count)
111
210
  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)
211
+ from = collection.offset_value + 1
212
+ to = collection.offset_value + (collection.respond_to?(:records) ? collection.records : collection.to_a).size
213
+
214
+ t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: from, last: to, total: collection.total_count)
113
215
  end.html_safe
114
216
  end
115
217
 
@@ -129,43 +231,17 @@ module Kaminari
129
231
  # <%= rel_next_prev_link_tags @items %>
130
232
  # <% end %>
131
233
  #
132
- # #-> <link rel="next" href="/items/page/3" /><link rel="prev" href="/items/page/1" />
234
+ # #-> <link rel="next" href="/items/page/3"><link rel="prev" href="/items/page/1">
133
235
  #
134
236
  def rel_next_prev_link_tags(scope, options = {})
135
237
  next_page = path_to_next_page(scope, options)
136
238
  prev_page = path_to_prev_page(scope, options)
137
239
 
138
240
  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
241
+ output << %Q|<link rel="next" href="#{next_page}">| if next_page
242
+ output << %Q|<link rel="prev" href="#{prev_page}">| if prev_page
141
243
  output.html_safe
142
244
  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
245
  end
170
246
  end
171
247
  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
@@ -12,7 +13,7 @@ module Kaminari
12
13
  # class, so _tag partial is not needed).
13
14
  # e.g.) PrevLink -> app/views/kaminari/_prev_link.html.erb
14
15
  #
15
- # When no matching template were found in your app, the engine's pre
16
+ # When no matching templates were found in your app, the engine's pre
16
17
  # installed template will be used.
17
18
  # e.g.) Paginator -> $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb
18
19
  class Tag
@@ -23,8 +24,8 @@ 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.reverse_merge! params
27
+ @params.except!(*PARAM_KEY_EXCEPT_LIST)
28
+ @params.merge! params
28
29
  end
29
30
 
30
31
  def to_s(locals = {}) #:nodoc:
@@ -65,7 +66,7 @@ module Kaminari
65
66
  "kaminari",
66
67
  @theme,
67
68
  self.class.name.demodulize.underscore
68
- ].compact.join("/")
69
+ ].compact.join("/").gsub('//', '/')
69
70
  end
70
71
  end
71
72
 
@@ -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.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2021-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,7 +91,7 @@ homepage: https://github.com/kaminari/kaminari
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -106,9 +106,8 @@ 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
111
- signing_key:
109
+ rubygems_version: 3.3.0.dev
110
+ signing_key:
112
111
  specification_version: 4
113
112
  summary: Kaminari's core pagination library
114
113
  test_files: []