pagy 5.10.1 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/config/pagy.rb +32 -31
- data/lib/javascripts/pagy-dev.js +2 -2
- data/lib/javascripts/pagy-module.js +1 -1
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/de.yml +1 -1
- data/lib/locales/ko.yml +1 -1
- data/lib/locales/nn.yml +22 -0
- data/lib/pagy/backend.rb +1 -1
- data/lib/pagy/calendar/day.rb +13 -3
- data/lib/pagy/calendar/helper.rb +61 -0
- data/lib/pagy/calendar/month.rb +6 -2
- data/lib/pagy/calendar/quarter.rb +6 -2
- data/lib/pagy/calendar/week.rb +13 -8
- data/lib/pagy/calendar/year.rb +6 -2
- data/lib/pagy/calendar.rb +18 -8
- data/lib/pagy/console.rb +1 -1
- data/lib/pagy/countless.rb +2 -2
- data/lib/pagy/extras/arel.rb +1 -1
- data/lib/pagy/extras/array.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +6 -6
- data/lib/pagy/extras/bulma.rb +1 -1
- data/lib/pagy/extras/calendar.rb +12 -29
- data/lib/pagy/extras/countless.rb +1 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +2 -11
- data/lib/pagy/extras/foundation.rb +1 -1
- data/lib/pagy/extras/gearbox.rb +1 -1
- data/lib/pagy/extras/headers.rb +1 -1
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/items.rb +1 -1
- data/lib/pagy/extras/materialize.rb +4 -4
- data/lib/pagy/extras/meilisearch.rb +14 -20
- data/lib/pagy/extras/metadata.rb +1 -1
- data/lib/pagy/extras/navs.rb +3 -3
- data/lib/pagy/extras/overflow.rb +2 -2
- data/lib/pagy/extras/searchkick.rb +3 -11
- data/lib/pagy/extras/semantic.rb +1 -1
- data/lib/pagy/extras/standalone.rb +5 -4
- data/lib/pagy/extras/support.rb +1 -1
- data/lib/pagy/extras/trim.rb +1 -1
- data/lib/pagy/extras/uikit.rb +1 -1
- data/lib/pagy/frontend.rb +2 -2
- data/lib/pagy/i18n.rb +1 -1
- data/lib/pagy/url_helpers.rb +4 -19
- data/lib/pagy.rb +17 -5
- data/lib/templates/bootstrap_nav.html.erb +1 -1
- data/lib/templates/bootstrap_nav.html.haml +1 -1
- data/lib/templates/bootstrap_nav.html.slim +1 -1
- data/lib/templates/nav.html.erb +1 -1
- data/lib/templates/nav.html.haml +1 -1
- data/lib/templates/nav.html.slim +1 -1
- metadata +7 -19
data/lib/pagy/calendar.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/calendar
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'active_support'
|
@@ -12,6 +12,9 @@ require 'pagy'
|
|
12
12
|
class Pagy # :nodoc:
|
13
13
|
# Base class for time units subclasses (Year, Quarter, Month, Week, Day)
|
14
14
|
class Calendar < Pagy
|
15
|
+
# Specific out of range error
|
16
|
+
class OutOfRangeError < StandardError; end
|
17
|
+
|
15
18
|
# List of units in desc order of duration. It can be used for custom units.
|
16
19
|
UNITS = %i[year quarter month week day] # rubocop:disable Style/MutableConstant
|
17
20
|
|
@@ -45,6 +48,14 @@ class Pagy # :nodoc:
|
|
45
48
|
|
46
49
|
protected
|
47
50
|
|
51
|
+
# The page that includes time
|
52
|
+
def page_at(time)
|
53
|
+
raise OutOfRangeError unless time.between?(@initial, @final)
|
54
|
+
|
55
|
+
offset = page_offset_at(time) # offset starts from 0
|
56
|
+
@order == :asc ? offset + 1 : @pages - offset
|
57
|
+
end
|
58
|
+
|
48
59
|
# Base class method for the setup of the unit variables (subclasses must implement it and call super)
|
49
60
|
def setup_unit_vars
|
50
61
|
raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
|
@@ -52,10 +63,9 @@ class Pagy # :nodoc:
|
|
52
63
|
unless %i[asc desc].include?(@order = @vars[:order])
|
53
64
|
|
54
65
|
@starting, @ending = @vars[:period]
|
55
|
-
raise VariableError.new(self, :period, 'to be a an Array of min and max
|
56
|
-
unless @starting.is_a?(
|
57
|
-
|
58
|
-
@with_zone = @starting.is_a?(ActiveSupport::TimeWithZone) # remove in 6.0 and replace Time in the line above
|
66
|
+
raise VariableError.new(self, :period, 'to be a an Array of min and max TimeWithZone instances', @vars[:period]) \
|
67
|
+
unless @starting.is_a?(ActiveSupport::TimeWithZone) \
|
68
|
+
&& @ending.is_a?(ActiveSupport::TimeWithZone) && @starting <= @ending
|
59
69
|
end
|
60
70
|
|
61
71
|
# Apply the strftime format to the time (overridden by the i18n extra when localization is required)
|
@@ -63,9 +73,9 @@ class Pagy # :nodoc:
|
|
63
73
|
time.strftime(opts[:format])
|
64
74
|
end
|
65
75
|
|
66
|
-
# Number of units to offset from the @initial time, in order to get the ordered starting time for the page.
|
67
|
-
# Used in starting_time_for(page)
|
68
|
-
def
|
76
|
+
# Number of time units to offset from the @initial time, in order to get the ordered starting time for the page.
|
77
|
+
# Used in starting_time_for(page) where page starts from 1 (e.g. page to starting_time means subtracting 1)
|
78
|
+
def time_offset_for(page)
|
69
79
|
@order == :asc ? page - 1 : @pages - page
|
70
80
|
end
|
71
81
|
|
data/lib/pagy/console.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See Pagy::Console API documentation: https://ddnexus.github.io/pagy/api/console
|
1
|
+
# See Pagy::Console API documentation: https://ddnexus.github.io/pagy/docs/api/console
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy' # so you can require just the extra in the console
|
data/lib/pagy/countless.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/countless
|
1
|
+
# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/countless
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy'
|
@@ -30,7 +30,7 @@ class Pagy
|
|
30
30
|
|
31
31
|
# Override the original series.
|
32
32
|
# Return nil if :countless_minimal is enabled
|
33
|
-
def series(
|
33
|
+
def series(*, **)
|
34
34
|
super unless @vars[:countless_minimal]
|
35
35
|
end
|
36
36
|
end
|
data/lib/pagy/extras/arel.rb
CHANGED
data/lib/pagy/extras/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bootstrap
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy/extras/frontend_helpers'
|
@@ -12,7 +12,7 @@ class Pagy # :nodoc:
|
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
14
14
|
|
15
|
-
html = +%(<nav#{p_id} class="pagy-bootstrap-nav"
|
15
|
+
html = +%(<nav#{p_id} class="pagy-bootstrap-nav"><ul class="pagination">)
|
16
16
|
html << pagy_bootstrap_prev_html(pagy, link)
|
17
17
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
@@ -40,7 +40,7 @@ class Pagy # :nodoc:
|
|
40
40
|
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
41
41
|
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }
|
42
42
|
|
43
|
-
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bootstrap-nav-js"
|
43
|
+
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bootstrap-nav-js" #{
|
44
44
|
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
|
45
45
|
end
|
46
46
|
|
@@ -51,17 +51,17 @@ class Pagy # :nodoc:
|
|
51
51
|
p_page = pagy.page
|
52
52
|
p_pages = pagy.pages
|
53
53
|
input = %(<input type="number" min="1" max="#{p_pages}" value="#{
|
54
|
-
p_page}"
|
54
|
+
p_page}" style="padding: 0; border: none; text-align: center; width: #{
|
55
55
|
p_pages.to_s.length + 1}rem;">)
|
56
56
|
|
57
|
-
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination"
|
57
|
+
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination"><div class="btn-group" role="group" #{
|
58
58
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
59
59
|
if (p_prev = pagy.prev)
|
60
60
|
link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"'
|
61
61
|
else
|
62
62
|
%(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>)
|
63
63
|
end
|
64
|
-
}<div class="pagy-combo-input btn btn-
|
64
|
+
}<div class="pagy-combo-input btn btn-secondary" style="white-space: nowrap;">#{
|
65
65
|
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
|
66
66
|
if (p_next = pagy.next)
|
67
67
|
link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"'
|
data/lib/pagy/extras/bulma.rb
CHANGED
data/lib/pagy/extras/calendar.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/calendar
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/calendar
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy/calendar'
|
5
|
+
require 'pagy/calendar/helper'
|
5
6
|
|
6
7
|
class Pagy # :nodoc:
|
7
8
|
# Add pagination filtering by calendar unit (:year, :quarter, :month, :week, :day) to the regular pagination
|
@@ -18,47 +19,29 @@ class Pagy # :nodoc:
|
|
18
19
|
raise ArgumentError, "keys must be in #{CONF_KEYS.inspect} and object values must be Hashes; got #{conf.inspect}"
|
19
20
|
end
|
20
21
|
|
21
|
-
conf[:pagy]
|
22
|
-
|
23
|
-
|
22
|
+
conf[:pagy] = {} unless conf[:pagy] # use default Pagy object when omitted
|
23
|
+
unless conf.key?(:active) && !conf[:active]
|
24
|
+
calendar, from, to = Calendar::Helper.send(:init, conf, pagy_calendar_period(collection), params)
|
25
|
+
collection = pagy_calendar_filter(collection, from, to)
|
26
|
+
end
|
27
|
+
pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
|
24
28
|
[calendar, pagy, results]
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
units = Calendar::UNITS & conf.keys # get the units in time length desc order
|
30
|
-
raise ArgumentError, 'no calendar unit found in pagy_calendar configuration' if units.empty?
|
31
|
-
|
32
|
-
page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
|
33
|
-
units.each do |unit| # set all the :page_param vars for later deletion
|
34
|
-
unit_page_param = :"#{unit}_#{page_param}"
|
35
|
-
conf[unit][:page_param] = unit_page_param
|
36
|
-
conf[unit][:page] = params[unit_page_param]
|
37
|
-
end
|
38
|
-
calendar = {}
|
39
|
-
last_obj = nil
|
40
|
-
units.each_with_index do |unit, index|
|
41
|
-
params_to_delete = units[(index + 1), units.size].map { |sub| conf[sub][:page_param] } + [page_param]
|
42
|
-
conf[unit][:params] = lambda do |params| # delete page_param from the sub-units
|
43
|
-
params_to_delete.each { |p| params.delete(p.to_s) } # Hash#except missing from ruby 2.5 baseline
|
44
|
-
params
|
45
|
-
end
|
46
|
-
conf[unit][:period] = last_obj&.send(:active_period) || pagy_calendar_period(collection)
|
47
|
-
calendar[unit] = last_obj = Calendar.send(:create, unit, conf[unit])
|
48
|
-
end
|
49
|
-
[calendar, pagy_calendar_filter(collection, last_obj.from, last_obj.to)]
|
31
|
+
def pagy_calendar_url_at(calendar, time)
|
32
|
+
pagy_url_for(calendar.send(:last_object_at, time), 1)
|
50
33
|
end
|
51
34
|
|
52
35
|
# This method must be implemented by the application
|
53
36
|
def pagy_calendar_period(*)
|
54
37
|
raise NoMethodError, 'the pagy_calendar_period method must be implemented by the application ' \
|
55
|
-
'(see https://ddnexus.github.io/pagy/extras/calendar
|
38
|
+
'(see https://ddnexus.github.io/pagy/docs/extras/calendar/#pagy-calendar-period-collection)'
|
56
39
|
end
|
57
40
|
|
58
41
|
# This method must be implemented by the application
|
59
42
|
def pagy_calendar_filter(*)
|
60
43
|
raise NoMethodError, 'the pagy_calendar_filter method must be implemented by the application ' \
|
61
|
-
'(see https://ddnexus.github.io/pagy/extras/calendar
|
44
|
+
'(see https://ddnexus.github.io/pagy/docs/extras/calendar/#pagy-calendar-filter-collection-from-to)'
|
62
45
|
end
|
63
46
|
end
|
64
47
|
end
|
@@ -1,18 +1,9 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/elasticsearch_rails
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
DEFAULT[:elasticsearch_rails_search] ||= :search
|
6
|
-
DEFAULT[:elasticsearch_rails_pagy_search] ||=
|
7
|
-
# :nocov:
|
8
|
-
Warning.warn '[PAGY WARNING] The :elasticsearch_rails_search_method variable ' \
|
9
|
-
'has been deprecated and will be ignored from pagy 6. ' \
|
10
|
-
'Use :elasticsearch_rails_pagy_search instead.'
|
11
|
-
DEFAULT[:elasticsearch_rails_search_method]
|
12
|
-
# :nocov:
|
13
|
-
else
|
14
|
-
:pagy_search
|
15
|
-
end
|
6
|
+
DEFAULT[:elasticsearch_rails_pagy_search] ||= :pagy_search
|
16
7
|
|
17
8
|
# Paginate ElasticsearchRails response objects
|
18
9
|
module ElasticsearchRailsExtra
|
data/lib/pagy/extras/gearbox.rb
CHANGED
data/lib/pagy/extras/headers.rb
CHANGED
data/lib/pagy/extras/i18n.rb
CHANGED
data/lib/pagy/extras/items.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/materialize
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy/extras/frontend_helpers'
|
@@ -12,7 +12,7 @@ class Pagy # :nodoc:
|
|
12
12
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
13
|
link = pagy_link_proc(pagy, link_extra: link_extra)
|
14
14
|
|
15
|
-
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation"
|
15
|
+
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation"><ul class="pagination">)
|
16
16
|
html << pagy_materialize_prev_html(pagy, link)
|
17
17
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
18
|
html << case item
|
@@ -38,7 +38,7 @@ class Pagy # :nodoc:
|
|
38
38
|
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
39
39
|
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }
|
40
40
|
|
41
|
-
%(<div#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize-nav-js" role="navigation"
|
41
|
+
%(<div#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize-nav-js" role="navigation" #{
|
42
42
|
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></div>)
|
43
43
|
end
|
44
44
|
|
@@ -53,7 +53,7 @@ class Pagy # :nodoc:
|
|
53
53
|
p_page}" style="text-align: center; width: #{p_pages.to_s.length + 1}rem;">)
|
54
54
|
|
55
55
|
html = %(<ul#{p_id} class="pagy-materialize-combo-nav-js pagination chip" role="navigation")
|
56
|
-
%(#{html}
|
56
|
+
%(#{html} style="padding-right: 0" #{
|
57
57
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
58
58
|
pagy_materialize_prev_html pagy, link, style}<li class="pagy-combo-input">#{
|
59
59
|
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</li>#{
|
@@ -2,16 +2,8 @@
|
|
2
2
|
|
3
3
|
class Pagy # :nodoc:
|
4
4
|
DEFAULT[:meilisearch_search] ||= :ms_search
|
5
|
-
DEFAULT[:meilisearch_pagy_search] ||=
|
6
|
-
|
7
|
-
Warning.warn '[PAGY WARNING] The :meilisearch_search_method variable ' \
|
8
|
-
'has been deprecated and will be ignored from pagy 6. ' \
|
9
|
-
'Use :meilisearch_pagy_search instead.'
|
10
|
-
DEFAULT[:meilisearch_search_method]
|
11
|
-
# :nocov:
|
12
|
-
else
|
13
|
-
:pagy_search
|
14
|
-
end
|
5
|
+
DEFAULT[:meilisearch_pagy_search] ||= :pagy_search
|
6
|
+
|
15
7
|
# Paginate Meilisearch results
|
16
8
|
module MeilisearchExtra
|
17
9
|
module Meilisearch # :nodoc:
|
@@ -27,9 +19,10 @@ class Pagy # :nodoc:
|
|
27
19
|
module Pagy
|
28
20
|
# Create a Pagy object from a Meilisearch results
|
29
21
|
def new_from_meilisearch(results, vars = {})
|
30
|
-
vars[:items] = results.raw_answer['
|
31
|
-
vars[:page] =
|
32
|
-
vars[:count] = results.raw_answer['
|
22
|
+
vars[:items] = results.raw_answer['hitsPerPage']
|
23
|
+
vars[:page] = results.raw_answer['page']
|
24
|
+
vars[:count] = results.raw_answer['totalHits']
|
25
|
+
|
33
26
|
new(vars)
|
34
27
|
end
|
35
28
|
end
|
@@ -40,13 +33,14 @@ class Pagy # :nodoc:
|
|
40
33
|
|
41
34
|
# Return Pagy object and results
|
42
35
|
def pagy_meilisearch(pagy_search_args, vars = {})
|
43
|
-
model, term, options
|
44
|
-
vars
|
45
|
-
options[:
|
46
|
-
options[:
|
47
|
-
results
|
48
|
-
vars[:count]
|
49
|
-
|
36
|
+
model, term, options = pagy_search_args
|
37
|
+
vars = pagy_meilisearch_get_vars(nil, vars)
|
38
|
+
options[:hits_per_page] = vars[:items]
|
39
|
+
options[:page] = vars[:page]
|
40
|
+
results = model.send(:ms_search, term, **options)
|
41
|
+
vars[:count] = results.raw_answer['totalHits']
|
42
|
+
|
43
|
+
pagy = ::Pagy.new(vars)
|
50
44
|
# with :last_page overflow we need to re-run the method in order to get the hits
|
51
45
|
return pagy_meilisearch(pagy_search_args, vars.merge(page: pagy.page)) \
|
52
46
|
if defined?(::Pagy::OverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
|
data/lib/pagy/extras/metadata.rb
CHANGED
data/lib/pagy/extras/navs.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/navs
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy/extras/frontend_helpers'
|
@@ -18,7 +18,7 @@ class Pagy # :nodoc:
|
|
18
18
|
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
|
19
19
|
'after' => pagy_nav_next_html(pagy, link) }
|
20
20
|
|
21
|
-
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-nav-js pagination"
|
21
|
+
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-nav-js pagination" #{
|
22
22
|
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
|
23
23
|
end
|
24
24
|
|
@@ -31,7 +31,7 @@ class Pagy # :nodoc:
|
|
31
31
|
input = %(<input type="number" min="1" max="#{p_pages}" value="#{
|
32
32
|
p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length + 1}rem;">)
|
33
33
|
|
34
|
-
%(<nav#{p_id} class="pagy-combo-nav-js pagination"
|
34
|
+
%(<nav#{p_id} class="pagy-combo-nav-js pagination" #{
|
35
35
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
36
36
|
pagy_nav_prev_html pagy, link
|
37
37
|
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/overflow
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/overflow
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
@@ -41,7 +41,7 @@ class Pagy # :nodoc:
|
|
41
41
|
|
42
42
|
# Special series for empty page
|
43
43
|
module Series
|
44
|
-
def series(
|
44
|
+
def series(*, **)
|
45
45
|
@page = @last # series for last page
|
46
46
|
super.tap do |s| # call original series
|
47
47
|
s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
|
@@ -1,18 +1,10 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/searchkick
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/searchkick
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
DEFAULT[:searchkick_search] ||= :search
|
6
|
-
DEFAULT[:searchkick_pagy_search] ||=
|
7
|
-
|
8
|
-
Warning.warn '[PAGY WARNING] The :searchkick_search_method variable ' \
|
9
|
-
'has been deprecated and will be ignored from pagy 6. ' \
|
10
|
-
'Use :searchkick_pagy_search instead.'
|
11
|
-
DEFAULT[:searchkick_search_method]
|
12
|
-
# :nocov:
|
13
|
-
else
|
14
|
-
:pagy_search
|
15
|
-
end
|
6
|
+
DEFAULT[:searchkick_pagy_search] ||= :pagy_search
|
7
|
+
|
16
8
|
# Paginate Searchkick::Results objects
|
17
9
|
module SearchkickExtra
|
18
10
|
module Searchkick # :nodoc:
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/standalone
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/standalone
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'uri'
|
@@ -8,6 +8,7 @@ class Pagy # :nodoc:
|
|
8
8
|
# even in the irb/rails console without any app or config.
|
9
9
|
module StandaloneExtra
|
10
10
|
# Extracted from Rack::Utils and reformatted for rubocop
|
11
|
+
# :nocov:
|
11
12
|
module QueryUtils
|
12
13
|
module_function
|
13
14
|
|
@@ -32,6 +33,7 @@ class Pagy # :nodoc:
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
36
|
+
# :nocov:
|
35
37
|
|
36
38
|
# Return the URL for the page. If there is no pagy.vars[:url]
|
37
39
|
# it works exactly as the regular #pagy_url_for, relying on the params method and Rack.
|
@@ -45,9 +47,8 @@ class Pagy # :nodoc:
|
|
45
47
|
params = pagy.params.is_a?(Hash) ? pagy.params.clone : {} # safe when it gets reused
|
46
48
|
params[page_param] = page
|
47
49
|
params[items_param] = vars[:items] if vars[:items_extra]
|
48
|
-
|
49
|
-
|
50
|
-
# query_string = "?#{Rack::Utils.build_nested_query(params)}" # add in 6.0
|
50
|
+
params = pagy.params.call(params) if pagy.params.is_a?(Proc)
|
51
|
+
query_string = "?#{QueryUtils.build_nested_query(params)}"
|
51
52
|
query_string = query_string.gsub('&', '&') if html_escaped # the only unescaped entity
|
52
53
|
"#{vars[:url]}#{query_string}#{vars[:fragment]}"
|
53
54
|
end
|
data/lib/pagy/extras/support.rb
CHANGED
data/lib/pagy/extras/trim.rb
CHANGED
data/lib/pagy/extras/uikit.rb
CHANGED
data/lib/pagy/frontend.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# See Pagy::Frontend API documentation: https://ddnexus.github.io/pagy/api/frontend
|
1
|
+
# See Pagy::Frontend API documentation: https://ddnexus.github.io/pagy/docs/api/frontend
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pagy/url_helpers'
|
@@ -21,7 +21,7 @@ class Pagy
|
|
21
21
|
p_prev = pagy.prev
|
22
22
|
p_next = pagy.next
|
23
23
|
|
24
|
-
html = +%(<nav#{p_id} class="pagy-nav pagination"
|
24
|
+
html = +%(<nav#{p_id} class="pagy-nav pagination">)
|
25
25
|
html << if p_prev
|
26
26
|
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
27
27
|
else
|
data/lib/pagy/i18n.rb
CHANGED
data/lib/pagy/url_helpers.rb
CHANGED
@@ -8,32 +8,17 @@ class Pagy
|
|
8
8
|
# For non-rack environments you can use the standalone extra
|
9
9
|
def pagy_url_for(pagy, page, absolute: false, html_escaped: false)
|
10
10
|
vars = pagy.vars
|
11
|
+
request_path = vars[:request_path].to_s.empty? ? request.path : vars[:request_path]
|
11
12
|
page_param = vars[:page_param].to_s
|
12
13
|
items_param = vars[:items_param].to_s
|
13
14
|
params = pagy.params.is_a?(Hash) ? pagy.params.transform_keys(&:to_s) : {}
|
14
15
|
params = request.GET.merge(params)
|
15
16
|
params[page_param] = page
|
16
17
|
params[items_param] = vars[:items] if vars[:items_extra]
|
17
|
-
|
18
|
-
|
19
|
-
# query_string = "?#{Rack::Utils.build_nested_query(params)}" # add in 6.0
|
18
|
+
params = pagy.params.call(params) if pagy.params.is_a?(Proc)
|
19
|
+
query_string = "?#{Rack::Utils.build_nested_query(params)}"
|
20
20
|
query_string = query_string.gsub('&', '&') if html_escaped # the only unescaped entity
|
21
|
-
"#{request.base_url if absolute}#{
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# Transitional code to handle params deprecations. It will be removed in version 6.0
|
27
|
-
def pagy_deprecated_params(pagy, params) # remove in 6.0
|
28
|
-
if pagy.params.is_a?(Proc) # new code
|
29
|
-
pagy.params.call(params)
|
30
|
-
elsif respond_to?(:pagy_massage_params) # deprecated code
|
31
|
-
Warning.warn '[PAGY WARNING] The pagy_massage_params method has been deprecated and it will be ignored from version 6. ' \
|
32
|
-
'Set the :params variable to a Proc with the same code as the pagy_massage_params method.'
|
33
|
-
pagy_massage_params(params)
|
34
|
-
else
|
35
|
-
params # no massage params
|
36
|
-
end
|
21
|
+
"#{request.base_url if absolute}#{request_path}#{query_string}#{vars[:fragment]}"
|
37
22
|
end
|
38
23
|
end
|
39
24
|
end
|
data/lib/pagy.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# See Pagy API documentation: https://ddnexus.github.io/pagy/api/pagy
|
1
|
+
# See Pagy API documentation: https://ddnexus.github.io/pagy/docs/api/pagy
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
|
6
6
|
# Core class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '
|
8
|
+
VERSION = '6.0.1'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
@@ -22,9 +22,10 @@ class Pagy
|
|
22
22
|
fragment: '',
|
23
23
|
link_extra: '',
|
24
24
|
i18n_key: 'pagy.item_name',
|
25
|
-
cycle: false
|
25
|
+
cycle: false,
|
26
|
+
request_path: '' }
|
26
27
|
|
27
|
-
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :in, :from, :to, :prev, :next, :params
|
28
|
+
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :in, :from, :to, :prev, :next, :params, :request_path
|
28
29
|
|
29
30
|
# Merge and validate the options, do some simple arithmetic and set the instance variables
|
30
31
|
def initialize(vars)
|
@@ -34,6 +35,7 @@ class Pagy
|
|
34
35
|
setup_pages_var
|
35
36
|
setup_offset_var
|
36
37
|
setup_params_var
|
38
|
+
setup_request_path_var
|
37
39
|
raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
|
38
40
|
|
39
41
|
@from = [@offset - @outset + 1, @count].min
|
@@ -92,7 +94,7 @@ class Pagy
|
|
92
94
|
def setup_vars(name_min)
|
93
95
|
name_min.each do |name, min|
|
94
96
|
raise VariableError.new(self, name, ">= #{min}", @vars[name]) \
|
95
|
-
unless @vars[name] && instance_variable_set(:"@#{name}", @vars[name].to_i) >= min
|
97
|
+
unless @vars[name]&.respond_to?(:to_i) && instance_variable_set(:"@#{name}", @vars[name].to_i) >= min
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
@@ -116,6 +118,16 @@ class Pagy
|
|
116
118
|
raise VariableError.new(self, :params, 'must be a Hash or a Proc', @params) \
|
117
119
|
unless (@params = @vars[:params]).is_a?(Hash) || @params.is_a?(Proc)
|
118
120
|
end
|
121
|
+
|
122
|
+
def setup_request_path_var
|
123
|
+
request_path = @vars[:request_path]
|
124
|
+
return if request_path.to_s.empty?
|
125
|
+
|
126
|
+
raise VariableError.new(self, :request_path, 'must be a bare path like "/foo"', request_path) \
|
127
|
+
if !request_path.start_with?('/') || request_path.include?('?')
|
128
|
+
|
129
|
+
@request_path = request_path
|
130
|
+
end
|
119
131
|
end
|
120
132
|
|
121
133
|
require 'pagy/backend'
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy, link_extra: 'class="page-link"') -%>
|
9
|
-
<%# -%><nav
|
9
|
+
<%# -%><nav class="pagy-bootstrap-nav" role="navigation">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
12
|
<% else -%> <li class="page-item prev disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.prev') %></a></li>
|