pagy 5.10.1 → 6.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/config/pagy.rb +36 -31
  4. data/lib/javascripts/pagy-dev.js +2 -2
  5. data/lib/javascripts/pagy-module.js +1 -1
  6. data/lib/javascripts/pagy.js +1 -1
  7. data/lib/locales/da.yml +2 -2
  8. data/lib/locales/de.yml +1 -1
  9. data/lib/locales/ko.yml +1 -1
  10. data/lib/locales/nn.yml +22 -0
  11. data/lib/pagy/backend.rb +1 -1
  12. data/lib/pagy/calendar/day.rb +13 -3
  13. data/lib/pagy/calendar/helper.rb +61 -0
  14. data/lib/pagy/calendar/month.rb +6 -2
  15. data/lib/pagy/calendar/quarter.rb +6 -2
  16. data/lib/pagy/calendar/week.rb +13 -8
  17. data/lib/pagy/calendar/year.rb +6 -2
  18. data/lib/pagy/calendar.rb +18 -8
  19. data/lib/pagy/console.rb +1 -1
  20. data/lib/pagy/countless.rb +2 -2
  21. data/lib/pagy/extras/arel.rb +1 -1
  22. data/lib/pagy/extras/array.rb +1 -1
  23. data/lib/pagy/extras/bootstrap.rb +6 -6
  24. data/lib/pagy/extras/bulma.rb +1 -1
  25. data/lib/pagy/extras/calendar.rb +12 -29
  26. data/lib/pagy/extras/countless.rb +1 -1
  27. data/lib/pagy/extras/elasticsearch_rails.rb +2 -11
  28. data/lib/pagy/extras/foundation.rb +4 -2
  29. data/lib/pagy/extras/gearbox.rb +1 -1
  30. data/lib/pagy/extras/headers.rb +1 -1
  31. data/lib/pagy/extras/i18n.rb +1 -1
  32. data/lib/pagy/extras/items.rb +1 -1
  33. data/lib/pagy/extras/materialize.rb +4 -4
  34. data/lib/pagy/extras/meilisearch.rb +15 -20
  35. data/lib/pagy/extras/metadata.rb +1 -1
  36. data/lib/pagy/extras/navs.rb +3 -3
  37. data/lib/pagy/extras/overflow.rb +2 -2
  38. data/lib/pagy/extras/searchkick.rb +3 -11
  39. data/lib/pagy/extras/semantic.rb +1 -1
  40. data/lib/pagy/extras/standalone.rb +5 -4
  41. data/lib/pagy/extras/support.rb +1 -1
  42. data/lib/pagy/extras/trim.rb +2 -2
  43. data/lib/pagy/extras/uikit.rb +1 -1
  44. data/lib/pagy/frontend.rb +2 -2
  45. data/lib/pagy/i18n.rb +1 -1
  46. data/lib/pagy/url_helpers.rb +4 -19
  47. data/lib/pagy.rb +17 -5
  48. data/lib/templates/bootstrap_nav.html.erb +1 -1
  49. data/lib/templates/bootstrap_nav.html.haml +1 -1
  50. data/lib/templates/bootstrap_nav.html.slim +1 -1
  51. data/lib/templates/nav.html.erb +1 -1
  52. data/lib/templates/nav.html.haml +1 -1
  53. data/lib/templates/nav.html.slim +1 -1
  54. 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 local Time instances', @vars[:period]) \
56
- unless @starting.is_a?(Time) && @ending.is_a?(Time) && !@starting.utc? && !@ending.utc? && @starting <= @ending
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) with a logic equivalent to: @initial + (offset_units_for(page) * unit_time_length)
68
- def offset_units_for(page)
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
@@ -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
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/arel
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/arel
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/array
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/array
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -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" aria-label="pager"><ul class="pagination">)
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" aria-label="pager" #{
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}" class="text-primary" style="padding: 0; border: none; text-align: center; width: #{
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" aria-label="pager"><div class="btn-group" role="group" #{
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-primary disabled" style="white-space: nowrap;">#{
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"'
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/bulma
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/extras/frontend_helpers'
@@ -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] = {} unless conf[:pagy] # use default Pagy object when omitted
22
- calendar, collection = pagy_setup_calendar(collection, conf) unless conf.key?(:active) && !conf[:active]
23
- pagy, results = send(conf[:pagy][:backend] || :pagy, collection, conf[:pagy]) # use backend: :pagy when omitted
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
- # Setup and return the calendar objects and the filtered collection
28
- def pagy_setup_calendar(collection, conf)
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#pagy_calendar_periodcollection)'
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#pagy_calendar_filtercollection-from-to)'
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,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/countless
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/countless
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/countless'
@@ -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] ||= if DEFAULT[:elasticsearch_rails_search_method] # remove in 6.0
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
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/foundation
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/extras/frontend_helpers'
@@ -59,7 +59,9 @@ class Pagy # :nodoc:
59
59
  else
60
60
  %(<a style="margin-bottom: 0" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
61
61
  end
62
- }<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
62
+ }#{
63
+ pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
64
+ .sub!('<label>', '<label class="input-group-label">')}#{ # add the class to the official dictionary string
63
65
  if (p_next = pagy.next)
64
66
  link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0" aria-label="next" class="next button primary"'
65
67
  else
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/gearbox
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/gearbox
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/headers
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/headers
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/url_helpers'
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/i18n
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/i18n
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/items
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/extras/frontend_helpers'
@@ -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" aria-label="pager"><ul class="pagination">)
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" aria-label="pager" #{
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} aria-label="pager" style="padding-right: 0" #{
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>#{
@@ -1,17 +1,10 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/meilisearch
1
2
  # frozen_string_literal: true
2
3
 
3
4
  class Pagy # :nodoc:
4
5
  DEFAULT[:meilisearch_search] ||= :ms_search
5
- DEFAULT[:meilisearch_pagy_search] ||= if DEFAULT[:meilisearch_search_method] # remove in 6.0
6
- # :nocov:
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
6
+ DEFAULT[:meilisearch_pagy_search] ||= :pagy_search
7
+
15
8
  # Paginate Meilisearch results
16
9
  module MeilisearchExtra
17
10
  module Meilisearch # :nodoc:
@@ -27,9 +20,10 @@ class Pagy # :nodoc:
27
20
  module Pagy
28
21
  # Create a Pagy object from a Meilisearch results
29
22
  def new_from_meilisearch(results, vars = {})
30
- vars[:items] = results.raw_answer['limit']
31
- vars[:page] = (results.raw_answer['offset'] / vars[:items]) + 1
32
- vars[:count] = results.raw_answer['nbHits']
23
+ vars[:items] = results.raw_answer['hitsPerPage']
24
+ vars[:page] = results.raw_answer['page']
25
+ vars[:count] = results.raw_answer['totalHits']
26
+
33
27
  new(vars)
34
28
  end
35
29
  end
@@ -40,13 +34,14 @@ class Pagy # :nodoc:
40
34
 
41
35
  # Return Pagy object and results
42
36
  def pagy_meilisearch(pagy_search_args, vars = {})
43
- model, term, options = pagy_search_args
44
- vars = pagy_meilisearch_get_vars(nil, vars)
45
- options[:limit] = vars[:items]
46
- options[:offset] = (vars[:page] - 1) * vars[:items]
47
- results = model.send(DEFAULT[:meilisearch_search], term, **options)
48
- vars[:count] = results.raw_answer['nbHits']
49
- pagy = ::Pagy.new(vars)
37
+ model, term, options = pagy_search_args
38
+ vars = pagy_meilisearch_get_vars(nil, vars)
39
+ options[:hits_per_page] = vars[:items]
40
+ options[:page] = vars[:page]
41
+ results = model.send(:ms_search, term, **options)
42
+ vars[:count] = results.raw_answer['totalHits']
43
+
44
+ pagy = ::Pagy.new(vars)
50
45
  # with :last_page overflow we need to re-run the method in order to get the hits
51
46
  return pagy_meilisearch(pagy_search_args, vars.merge(page: pagy.page)) \
52
47
  if defined?(::Pagy::OverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/metadata
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/metadata
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/url_helpers'
@@ -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" aria-label="pager" #{
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" aria-label="pager" #{
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;">#{
@@ -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] ||= if DEFAULT[:searchkick_search_method] # remove in 6.0
7
- # :nocov:
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:
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/semantic
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/extras/frontend_helpers'
@@ -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
- query_string = "?#{QueryUtils.build_nested_query(pagy_deprecated_params(pagy, params))}" # remove in 6.0
49
- # params = pagy.params.call(params) if pagy.params.is_a?(Proc) # add in 6.0
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('&', '&amp;') if html_escaped # the only unescaped entity
52
53
  "#{vars[:url]}#{query_string}#{vars[:fragment]}"
53
54
  end
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/support
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/support
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/trim
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Pagy # :nodoc:
@@ -14,7 +14,7 @@ class Pagy # :nodoc:
14
14
 
15
15
  lambda do |page, text = pagy.label_for(page), extra = ''|
16
16
  link = +link_proc.call(page, text, extra)
17
- return link unless page == 1
17
+ return link unless page.to_s == '1'
18
18
 
19
19
  pagy_trim(pagy, link)
20
20
  end
@@ -1,4 +1,4 @@
1
- # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/uikit
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/uikit
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'pagy/extras/frontend_helpers'
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" aria-label="pager">)
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
@@ -1,4 +1,4 @@
1
- # See Pagy::I18n API documentation https://ddnexus.github.io/pagy/api/i18n
1
+ # See Pagy::I18n API documentation https://ddnexus.github.io/pagy/docs/api/i18n
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'yaml'
@@ -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
- query_string = "?#{Rack::Utils.build_nested_query(pagy_deprecated_params(pagy, params))}" # remove in 6.0
18
- # params = pagy.params.call(params) if pagy.params.is_a?(Proc) # add in 6.0
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('&', '&amp;') if html_escaped # the only unescaped entity
21
- "#{request.base_url if absolute}#{request.path}#{query_string}#{vars[:fragment]}"
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