pagy 6.0.0 → 7.0.0
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 +4 -4
- data/LICENSE.txt +1 -1
- data/lib/config/pagy.rb +56 -44
- data/lib/javascripts/pagy-dev.js +3 -3
- data/lib/javascripts/pagy-module.js +2 -2
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/ar.yml +15 -11
- data/lib/locales/be.yml +25 -0
- data/lib/locales/bg.yml +10 -11
- data/lib/locales/bs.yml +12 -11
- data/lib/locales/ca.yml +12 -11
- data/lib/locales/cs.yml +13 -10
- data/lib/locales/da.yml +14 -13
- data/lib/locales/de.yml +10 -11
- data/lib/locales/en.yml +10 -11
- data/lib/locales/es.yml +10 -11
- data/lib/locales/fr.yml +10 -11
- data/lib/locales/hr.yml +12 -11
- data/lib/locales/id.yml +10 -11
- data/lib/locales/it.yml +10 -11
- data/lib/locales/ja.yml +10 -11
- data/lib/locales/km.yml +10 -10
- data/lib/locales/ko.yml +10 -11
- data/lib/locales/nb.yml +10 -11
- data/lib/locales/nl.yml +10 -11
- data/lib/locales/nn.yml +10 -11
- data/lib/locales/pl.yml +12 -11
- data/lib/locales/pt-BR.yml +10 -11
- data/lib/locales/pt.yml +10 -11
- data/lib/locales/ru.yml +14 -11
- data/lib/locales/sr.yml +12 -10
- data/lib/locales/sv-SE.yml +10 -12
- data/lib/locales/sv.yml +10 -12
- data/lib/locales/sw.yml +12 -11
- data/lib/locales/ta.yml +12 -11
- data/lib/locales/tr.yml +10 -11
- data/lib/locales/uk.yml +12 -11
- data/lib/locales/vi.yml +17 -0
- data/lib/locales/zh-CN.yml +10 -11
- data/lib/locales/zh-HK.yml +10 -11
- data/lib/locales/zh-TW.yml +10 -11
- data/lib/pagy/backend.rb +10 -4
- data/lib/pagy/calendar/day.rb +4 -3
- data/lib/pagy/calendar/helper.rb +15 -11
- data/lib/pagy/calendar/month.rb +4 -3
- data/lib/pagy/calendar/quarter.rb +4 -3
- data/lib/pagy/calendar/week.rb +1 -1
- data/lib/pagy/calendar/year.rb +3 -2
- data/lib/pagy/calendar.rb +33 -7
- data/lib/pagy/console.rb +1 -1
- data/lib/pagy/countless.rb +1 -1
- data/lib/pagy/exceptions.rb +1 -1
- data/lib/pagy/extras/arel.rb +1 -1
- data/lib/pagy/extras/array.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +45 -32
- data/lib/pagy/extras/bulma.rb +41 -32
- data/lib/pagy/extras/calendar.rb +17 -13
- data/lib/pagy/extras/countless.rb +1 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +8 -8
- data/lib/pagy/extras/foundation.rb +48 -33
- data/lib/pagy/extras/frontend_helpers.rb +11 -11
- data/lib/pagy/extras/gearbox.rb +1 -1
- data/lib/pagy/extras/headers.rb +8 -8
- data/lib/pagy/extras/i18n.rb +5 -5
- data/lib/pagy/extras/items.rb +19 -12
- data/lib/pagy/extras/jsonapi.rb +79 -0
- data/lib/pagy/extras/materialize.rb +42 -30
- data/lib/pagy/extras/meilisearch.rb +12 -11
- data/lib/pagy/extras/metadata.rb +2 -2
- data/lib/pagy/extras/navs.rb +22 -34
- data/lib/pagy/extras/overflow.rb +9 -7
- data/lib/pagy/extras/searchkick.rb +8 -8
- data/lib/pagy/extras/semantic.rb +41 -28
- data/lib/pagy/extras/standalone.rb +10 -16
- data/lib/pagy/extras/support.rb +19 -33
- data/lib/pagy/extras/trim.rb +4 -4
- data/lib/pagy/extras/uikit.rb +44 -31
- data/lib/pagy/frontend.rb +57 -26
- data/lib/pagy/i18n.rb +3 -3
- data/lib/pagy/url_helpers.rb +15 -12
- data/lib/pagy.rb +57 -41
- metadata +7 -19
- data/lib/templates/bootstrap_nav.html.erb +0 -24
- data/lib/templates/bootstrap_nav.html.haml +0 -34
- data/lib/templates/bootstrap_nav.html.slim +0 -34
- data/lib/templates/bulma_nav.html.erb +0 -24
- data/lib/templates/bulma_nav.html.haml +0 -32
- data/lib/templates/bulma_nav.html.slim +0 -32
- data/lib/templates/foundation_nav.html.erb +0 -24
- data/lib/templates/foundation_nav.html.haml +0 -34
- data/lib/templates/foundation_nav.html.slim +0 -34
- data/lib/templates/nav.html.erb +0 -22
- data/lib/templates/nav.html.haml +0 -30
- data/lib/templates/nav.html.slim +0 -29
- data/lib/templates/uikit_nav.html.erb +0 -15
- data/lib/templates/uikit_nav.html.haml +0 -28
- data/lib/templates/uikit_nav.html.slim +0 -28
data/lib/pagy/extras/headers.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
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'
|
5
5
|
|
6
6
|
class Pagy # :nodoc:
|
7
|
-
DEFAULT[:headers] = { page: '
|
8
|
-
items: '
|
9
|
-
count: '
|
10
|
-
pages: '
|
7
|
+
DEFAULT[:headers] = { page: 'current-page',
|
8
|
+
items: 'page-items',
|
9
|
+
count: 'total-count',
|
10
|
+
pages: 'total-pages' }
|
11
11
|
# Add specialized backend methods to add pagination response headers
|
12
12
|
module HeadersExtra
|
13
13
|
include UrlHelpers
|
@@ -22,7 +22,7 @@ class Pagy # :nodoc:
|
|
22
22
|
# Generate a hash of RFC-8288 compliant http headers
|
23
23
|
def pagy_headers(pagy)
|
24
24
|
pagy_headers_hash(pagy).tap do |hash|
|
25
|
-
hash['
|
25
|
+
hash['link'] = hash['link'].map { |rel, link| %(<#{link}>; rel="#{rel}") }.join(', ')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -32,11 +32,11 @@ class Pagy # :nodoc:
|
|
32
32
|
rel = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
|
33
33
|
rel['last'] = pagy.last unless countless
|
34
34
|
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
|
35
|
-
link = rel.
|
35
|
+
link = rel.filter_map do |r, num|
|
36
36
|
next unless num # rubocop:disable Layout/EmptyLineAfterGuardClause
|
37
37
|
[r, url_str.sub(PAGE_PLACEHOLDER, num.to_s)]
|
38
38
|
end.compact.to_h
|
39
|
-
hash = { '
|
39
|
+
hash = { 'link' => link }
|
40
40
|
headers = pagy.vars[:headers]
|
41
41
|
hash[headers[:page]] = pagy.page.to_s if headers[:page]
|
42
42
|
if headers[:items] && !(defined?(Calendar) && pagy.is_a?(Calendar)) # items is not for Calendar
|
data/lib/pagy/extras/i18n.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
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:
|
5
5
|
# Use ::I18n gem
|
6
6
|
module I18nExtra
|
7
7
|
# Frontend overriding for translation
|
8
|
-
module
|
8
|
+
module FrontendOverride
|
9
9
|
def pagy_t(key, **opts)
|
10
10
|
::I18n.t(key, **opts)
|
11
11
|
end
|
12
12
|
end
|
13
|
+
Frontend.prepend I18nExtra::FrontendOverride
|
13
14
|
|
14
15
|
# Calendar overriding for localization (see also the block in the calendar section of the config/pagy.rb initializer)
|
15
|
-
module
|
16
|
+
module CalendarOverride
|
16
17
|
def localize(time, opts)
|
17
18
|
::I18n.l(time, **opts)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
21
|
-
|
22
|
-
Calendar.prepend I18nExtra::Calendar if defined?(Calendar)
|
22
|
+
Calendar.prepend I18nExtra::CalendarOverride if defined?(Calendar)
|
23
23
|
|
24
24
|
# Add the pagy locales to the I18n.load_path
|
25
25
|
::I18n.load_path += Dir[Pagy.root.join('locales', '*.yml')]
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -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'
|
@@ -11,44 +11,51 @@ class Pagy # :nodoc:
|
|
11
11
|
# Allow the client to request a custom number of items per page with an optional selector UI
|
12
12
|
module ItemsExtra
|
13
13
|
# Additions for the Backend module
|
14
|
-
module
|
14
|
+
module BackendAddOn
|
15
15
|
private
|
16
16
|
|
17
17
|
# Set the items variable considering the params and other pagy variables
|
18
18
|
def pagy_set_items_from_params(vars)
|
19
19
|
return if vars[:items] # :items explicitly set
|
20
20
|
return unless vars.key?(:items_extra) ? vars[:items_extra] : DEFAULT[:items_extra] # :items_extra is false
|
21
|
-
return unless (
|
21
|
+
return unless (items_count = pagy_get_items_size(vars)) # no items from request params
|
22
22
|
|
23
|
-
vars[:items] = [
|
23
|
+
vars[:items] = [items_count.to_i, vars.key?(:max_items) ? vars[:max_items] : DEFAULT[:max_items]].compact.min
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the items count from the params
|
27
|
+
# Overridable by the jsonapi extra
|
28
|
+
def pagy_get_items_size(vars)
|
29
|
+
params[vars[:items_param] || DEFAULT[:items_param]]
|
24
30
|
end
|
25
31
|
end
|
32
|
+
Backend.prepend ItemsExtra::BackendAddOn
|
26
33
|
|
27
34
|
# Additions for the Frontend module
|
28
|
-
module
|
35
|
+
module FrontendAddOn
|
29
36
|
ITEMS_PLACEHOLDER = '__pagy_items__'
|
30
37
|
|
31
38
|
# Return the items selector HTML. For example "Show [20] items per page"
|
32
|
-
def pagy_items_selector_js(pagy, pagy_id: nil, item_name: nil,
|
39
|
+
def pagy_items_selector_js(pagy, pagy_id: nil, item_name: nil, item_i18n_key: nil, link_extra: '')
|
33
40
|
return '' unless pagy.vars[:items_extra]
|
34
41
|
|
35
42
|
p_id = %( id="#{pagy_id}") if pagy_id
|
36
43
|
p_vars = pagy.vars
|
37
44
|
p_items = p_vars[:items]
|
38
45
|
p_vars[:items] = ITEMS_PLACEHOLDER
|
39
|
-
link = pagy_marked_link(pagy_link_proc(pagy, link_extra:
|
46
|
+
link = pagy_marked_link(pagy_link_proc(pagy, link_extra:))
|
40
47
|
p_vars[:items] = p_items # restore the items
|
41
48
|
|
42
49
|
html = +%(<span#{p_id} class="pagy-items-selector-js" #{pagy_data(pagy, :selector, pagy.from, link)}>)
|
43
50
|
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{
|
44
51
|
p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length + 1}rem;">)
|
45
|
-
html << pagy_t('pagy.items_selector_js',
|
46
|
-
|
47
|
-
|
52
|
+
html << pagy_t('pagy.items_selector_js',
|
53
|
+
item_name: item_name || pagy_t(item_i18n_key || p_vars[:item_i18n_key], count: p_items),
|
54
|
+
items_input: input,
|
55
|
+
count: p_items)
|
48
56
|
html << %(</span>)
|
49
57
|
end
|
50
58
|
end
|
59
|
+
Frontend.prepend ItemsExtra::FrontendAddOn
|
51
60
|
end
|
52
|
-
Backend.prepend ItemsExtra::Backend
|
53
|
-
Frontend.prepend ItemsExtra::Frontend
|
54
61
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/jsonapi
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pagy/url_helpers'
|
5
|
+
|
6
|
+
class Pagy # :nodoc:
|
7
|
+
DEFAULT[:jsonapi] = true
|
8
|
+
|
9
|
+
# Add a specialized backend method compliant with JSON:API
|
10
|
+
module JsonApiExtra
|
11
|
+
# JsonApi :page param error
|
12
|
+
class ReservedParamError < StandardError
|
13
|
+
# Inform about the actual value
|
14
|
+
def initialize(value)
|
15
|
+
super("expected reserved :page param to be nil or Hash-like; got #{value.inspect}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Module overriding Backend
|
20
|
+
module BackendOverride
|
21
|
+
private
|
22
|
+
|
23
|
+
include UrlHelpers
|
24
|
+
|
25
|
+
# Return the jsonapi links
|
26
|
+
def pagy_jsonapi_links(pagy, **opts)
|
27
|
+
{ first: pagy_url_for(pagy, 1, **opts),
|
28
|
+
last: pagy_url_for(pagy, pagy.last, **opts),
|
29
|
+
prev: pagy_url_for(pagy, pagy.prev, **opts),
|
30
|
+
next: pagy_url_for(pagy, pagy.next, **opts) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Should skip the jsonapi
|
34
|
+
def pagy_skip_jsonapi?(vars)
|
35
|
+
return true if vars[:jsonapi] == false || (vars[:jsonapi].nil? && DEFAULT[:jsonapi] == false)
|
36
|
+
# check the reserved :page param
|
37
|
+
raise ReservedParamError, params[:page] unless params[:page].respond_to?(:fetch) || params[:page].nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
# Override the Backend method
|
41
|
+
def pagy_get_page(vars)
|
42
|
+
return super if pagy_skip_jsonapi?(vars)
|
43
|
+
return 1 if params[:page].nil?
|
44
|
+
|
45
|
+
params[:page][vars[:page_param] || DEFAULT[:page_param]].to_i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
Backend.prepend BackendOverride
|
49
|
+
|
50
|
+
# Module overriding ItemsExtra
|
51
|
+
module ItemsExtraOverride
|
52
|
+
private
|
53
|
+
|
54
|
+
# Override the ItemsExtra::Backend method
|
55
|
+
def pagy_get_items_size(vars)
|
56
|
+
return super if pagy_skip_jsonapi?(vars)
|
57
|
+
return if params[:page].nil?
|
58
|
+
|
59
|
+
params[:page][vars[:items_param] || DEFAULT[:items_param]]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# :nocov:
|
63
|
+
ItemsExtra::BackendAddOn.prepend ItemsExtraOverride if defined?(ItemsExtra::BackendAddOn)
|
64
|
+
# :nocov:
|
65
|
+
|
66
|
+
# Module overriding UrlHelper
|
67
|
+
module UrlHelperOverride
|
68
|
+
# Override UrlHelper method
|
69
|
+
def pagy_set_query_params(page, vars, params)
|
70
|
+
return super unless vars[:jsonapi]
|
71
|
+
|
72
|
+
params['page'] ||= {}
|
73
|
+
params['page'][vars[:page_param].to_s] = page
|
74
|
+
params['page'][vars[:items_param].to_s] = vars[:items] if vars[:items_extra]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
UrlHelpers.prepend UrlHelperOverride
|
78
|
+
end
|
79
|
+
end
|
@@ -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'
|
@@ -8,75 +8,87 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module MaterializeExtra
|
10
10
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
11
|
-
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '',
|
11
|
+
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '',
|
12
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
12
13
|
p_id = %( id="#{pagy_id}") if pagy_id
|
13
|
-
link = pagy_link_proc(pagy, link_extra:
|
14
|
+
link = pagy_link_proc(pagy, link_extra:)
|
14
15
|
|
15
|
-
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation"
|
16
|
-
|
16
|
+
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" #{
|
17
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}><ul class="pagination">)
|
18
|
+
html << materialize_prev_html(pagy, link)
|
17
19
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
18
20
|
html << case item
|
19
|
-
when Integer
|
20
|
-
|
21
|
-
when
|
22
|
-
|
21
|
+
when Integer
|
22
|
+
%(<li class="waves-effect">#{link.call(item)}</li>)
|
23
|
+
when String
|
24
|
+
%(<li class="active">#{link.call(item)}</li>)
|
25
|
+
when :gap
|
26
|
+
%(<li class="gap disabled"><a href="#" aria-disabled="true">#{pagy_t 'pagy.gap'}</a></li>)
|
27
|
+
else
|
28
|
+
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
23
29
|
end
|
24
30
|
end
|
25
|
-
html <<
|
31
|
+
html << materialize_next_html(pagy, link)
|
26
32
|
html << %(</ul></div>)
|
27
33
|
end
|
28
34
|
|
29
35
|
# Javascript pagination for materialize: it returns a nav and a JSON tag used by the pagy.js file
|
30
|
-
def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '',
|
36
|
+
def pagy_materialize_nav_js(pagy, pagy_id: nil, link_extra: '',
|
37
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
31
38
|
sequels = pagy.sequels(**vars)
|
32
39
|
p_id = %( id="#{pagy_id}") if pagy_id
|
33
|
-
link = pagy_link_proc(pagy, link_extra:
|
40
|
+
link = pagy_link_proc(pagy, link_extra:)
|
34
41
|
|
35
|
-
tags = { 'before' => %(<ul class="pagination">#{
|
36
|
-
'link' => %(<li class="waves-effect">#{
|
37
|
-
'active' => %(<li class="active">#{
|
38
|
-
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.
|
39
|
-
'after' => %(#{
|
42
|
+
tags = { 'before' => %(<ul class="pagination">#{materialize_prev_html pagy, link}),
|
43
|
+
'link' => %(<li class="waves-effect">#{html = link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</li>),
|
44
|
+
'active' => %(<li class="active">#{html}</li>),
|
45
|
+
'gap' => %(<li class="gap disabled"><a href="#" aria-disabled="true">#{pagy_t 'pagy.gap'}</a></li>),
|
46
|
+
'after' => %(#{materialize_next_html pagy, link}</ul>) }
|
40
47
|
|
41
48
|
%(<div#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-materialize-nav-js" role="navigation" #{
|
42
|
-
|
49
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
|
50
|
+
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></div>)
|
43
51
|
end
|
44
52
|
|
45
53
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the pagy.js file
|
46
|
-
def pagy_materialize_combo_nav_js(pagy, pagy_id: nil, link_extra: ''
|
54
|
+
def pagy_materialize_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
|
55
|
+
nav_aria_label: nil, nav_i18n_key: nil)
|
47
56
|
p_id = %( id="#{pagy_id}") if pagy_id
|
48
|
-
link = pagy_link_proc(pagy, link_extra:
|
57
|
+
link = pagy_link_proc(pagy, link_extra:)
|
49
58
|
p_page = pagy.page
|
50
59
|
p_pages = pagy.pages
|
51
60
|
style = ' style="vertical-align: middle"'
|
52
61
|
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{
|
53
|
-
p_page}" style="text-align: center; width: #{p_pages.to_s.length + 1}rem;">)
|
62
|
+
p_page}" style="text-align: center; width: #{p_pages.to_s.length + 1}rem;" aria-current="page">)
|
54
63
|
|
55
|
-
html = %(<ul#{p_id} class="pagy-materialize-combo-nav-js pagination chip" role="navigation"
|
64
|
+
html = %(<ul#{p_id} class="pagy-materialize-combo-nav-js pagination chip" role="navigation" #{
|
65
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)})
|
56
66
|
%(#{html} style="padding-right: 0" #{
|
57
67
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
58
|
-
|
68
|
+
materialize_prev_html pagy, link, style}<li class="pagy-combo-input">#{
|
59
69
|
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</li>#{
|
60
|
-
|
70
|
+
materialize_next_html pagy, link, style}</ul>)
|
61
71
|
end
|
62
72
|
|
63
73
|
private
|
64
74
|
|
65
|
-
def
|
75
|
+
def materialize_prev_html(pagy, link, style = '')
|
66
76
|
if (p_prev = pagy.prev)
|
67
77
|
%(<li class="waves-effect prev"#{style}>#{
|
68
|
-
link.call
|
78
|
+
link.call(p_prev, '<i class="material-icons">chevron_left</i>', prev_aria_label_attr)}</li>)
|
69
79
|
else
|
70
|
-
%(<li class="prev disabled"#{style}><a href="#"
|
80
|
+
%(<li class="prev disabled"#{style}><a href="#" aria-disabled="true" #{
|
81
|
+
prev_aria_label_attr}><i class="material-icons">chevron_left</i></a></li>)
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
74
|
-
def
|
85
|
+
def materialize_next_html(pagy, link, style = '')
|
75
86
|
if (p_next = pagy.next)
|
76
87
|
%(<li class="waves-effect next"#{style}>#{
|
77
|
-
link.call
|
88
|
+
link.call(p_next, '<i class="material-icons">chevron_right</i>', next_aria_label_attr)}</li>)
|
78
89
|
else
|
79
|
-
%(<li class="next disabled"#{style}><a href="#"
|
90
|
+
%(<li class="next disabled"#{style}><a href="#" aria-disabled="true" #{
|
91
|
+
next_aria_label_attr}><i class="material-icons">chevron_right</i></a></li>)
|
80
92
|
end
|
81
93
|
end
|
82
94
|
end
|
@@ -1,3 +1,4 @@
|
|
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:
|
@@ -6,17 +7,18 @@ class Pagy # :nodoc:
|
|
6
7
|
|
7
8
|
# Paginate Meilisearch results
|
8
9
|
module MeilisearchExtra
|
9
|
-
module
|
10
|
+
module ModelExtension # :nodoc:
|
10
11
|
# Return an array used to delay the call of #search
|
11
12
|
# after the pagination variables are merged to the options
|
12
|
-
def pagy_meilisearch(
|
13
|
-
[self,
|
13
|
+
def pagy_meilisearch(query, params = {})
|
14
|
+
[self, query, params]
|
14
15
|
end
|
15
16
|
alias_method DEFAULT[:meilisearch_pagy_search], :pagy_meilisearch
|
16
17
|
end
|
18
|
+
Pagy::Meilisearch = ModelExtension
|
17
19
|
|
18
|
-
#
|
19
|
-
module
|
20
|
+
# Extension for the Pagy class
|
21
|
+
module PagyExtension
|
20
22
|
# Create a Pagy object from a Meilisearch results
|
21
23
|
def new_from_meilisearch(results, vars = {})
|
22
24
|
vars[:items] = results.raw_answer['hitsPerPage']
|
@@ -26,9 +28,10 @@ class Pagy # :nodoc:
|
|
26
28
|
new(vars)
|
27
29
|
end
|
28
30
|
end
|
31
|
+
Pagy.extend PagyExtension
|
29
32
|
|
30
33
|
# Add specialized backend methods to paginate Meilisearch results
|
31
|
-
module
|
34
|
+
module BackendAddOn
|
32
35
|
private
|
33
36
|
|
34
37
|
# Return Pagy object and results
|
@@ -37,7 +40,7 @@ class Pagy # :nodoc:
|
|
37
40
|
vars = pagy_meilisearch_get_vars(nil, vars)
|
38
41
|
options[:hits_per_page] = vars[:items]
|
39
42
|
options[:page] = vars[:page]
|
40
|
-
results = model.send(:ms_search, term,
|
43
|
+
results = model.send(:ms_search, term, options)
|
41
44
|
vars[:count] = results.raw_answer['totalHits']
|
42
45
|
|
43
46
|
pagy = ::Pagy.new(vars)
|
@@ -53,12 +56,10 @@ class Pagy # :nodoc:
|
|
53
56
|
def pagy_meilisearch_get_vars(_collection, vars)
|
54
57
|
pagy_set_items_from_params(vars) if defined?(ItemsExtra)
|
55
58
|
vars[:items] ||= DEFAULT[:items]
|
56
|
-
vars[:page] ||= (
|
59
|
+
vars[:page] ||= pagy_get_page(vars)
|
57
60
|
vars
|
58
61
|
end
|
59
62
|
end
|
63
|
+
Backend.prepend BackendAddOn
|
60
64
|
end
|
61
|
-
Meilisearch = MeilisearchExtra::Meilisearch
|
62
|
-
extend MeilisearchExtra::Pagy
|
63
|
-
Backend.prepend MeilisearchExtra::Backend
|
64
65
|
end
|
data/lib/pagy/extras/metadata.rb
CHANGED
@@ -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'
|
@@ -15,7 +15,7 @@ class Pagy # :nodoc:
|
|
15
15
|
|
16
16
|
# Return the metadata hash
|
17
17
|
def pagy_metadata(pagy, absolute: nil)
|
18
|
-
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute:
|
18
|
+
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute:)
|
19
19
|
{}.tap do |metadata|
|
20
20
|
keys = defined?(Calendar) && pagy.is_a?(Calendar) ? pagy.vars[:metadata] - %i[count items] : pagy.vars[:metadata]
|
21
21
|
keys.each do |key|
|
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'
|
@@ -8,56 +8,44 @@ class Pagy # :nodoc:
|
|
8
8
|
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
9
|
module NavsExtra
|
10
10
|
# Javascript pagination: it returns a nav and a JSON tag used by the pagy.js file
|
11
|
-
def pagy_nav_js(pagy, pagy_id: nil, link_extra: '',
|
11
|
+
def pagy_nav_js(pagy, pagy_id: nil, link_extra: '',
|
12
|
+
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
12
13
|
sequels = pagy.sequels(**vars)
|
13
14
|
p_id = %( id="#{pagy_id}") if pagy_id
|
14
|
-
link = pagy_link_proc(pagy, link_extra:
|
15
|
-
tags = { 'before' =>
|
15
|
+
link = pagy_link_proc(pagy, link_extra:)
|
16
|
+
tags = { 'before' => prev_html(pagy, link),
|
16
17
|
'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</span> ),
|
17
|
-
'active' => %(<span class="page active"
|
18
|
-
|
19
|
-
'
|
18
|
+
'active' => %(<span class="page active">) +
|
19
|
+
%(<a role="link" aria-current="page" aria-disabled="true">#{LABEL_PLACEHOLDER}</a></span> ),
|
20
|
+
'gap' => %(<span class="page gap">#{pagy_t 'pagy.gap'}</span> ),
|
21
|
+
'after' => next_html(pagy, link) }
|
20
22
|
|
21
23
|
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-nav-js pagination" #{
|
22
|
-
|
24
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
|
25
|
+
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))
|
26
|
+
}></nav>)
|
23
27
|
end
|
24
28
|
|
25
29
|
# Javascript combo pagination: it returns a nav and a JSON tag used by the pagy.js file
|
26
|
-
def pagy_combo_nav_js(pagy, pagy_id: nil, link_extra: ''
|
30
|
+
def pagy_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
|
31
|
+
nav_aria_label: nil, nav_i18n_key: nil)
|
27
32
|
p_id = %( id="#{pagy_id}") if pagy_id
|
28
|
-
link = pagy_link_proc(pagy, link_extra:
|
33
|
+
link = pagy_link_proc(pagy, link_extra:)
|
29
34
|
p_page = pagy.page
|
30
35
|
p_pages = pagy.pages
|
31
|
-
input = %(<input type="number" min="1" max="#{p_pages}" value="#{
|
32
|
-
|
36
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" ) +
|
37
|
+
%(style="padding: 0; text-align: center; width: #{p_pages.to_s.length + 1}rem;" aria-current="page">)
|
33
38
|
|
34
39
|
%(<nav#{p_id} class="pagy-combo-nav-js pagination" #{
|
40
|
+
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
|
35
41
|
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
|
36
|
-
|
37
|
-
|
38
|
-
pagy_t
|
42
|
+
prev_html(pagy, link)
|
43
|
+
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
|
44
|
+
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
|
39
45
|
}</span> #{
|
40
|
-
|
46
|
+
next_html(pagy, link)
|
41
47
|
}</nav>)
|
42
48
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def pagy_nav_prev_html(pagy, link)
|
47
|
-
if (p_prev = pagy.prev)
|
48
|
-
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
49
|
-
else
|
50
|
-
%(<span class="page prev disabled">#{pagy_t 'pagy.nav.prev'}</span> )
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def pagy_nav_next_html(pagy, link)
|
55
|
-
if (p_next = pagy.next)
|
56
|
-
%(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
57
|
-
else
|
58
|
-
%(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
|
59
|
-
end
|
60
|
-
end
|
61
49
|
end
|
62
50
|
Frontend.prepend NavsExtra
|
63
51
|
end
|
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:
|
@@ -7,7 +7,7 @@ class Pagy # :nodoc:
|
|
7
7
|
# Handles OverflowError exceptions for different classes with different options
|
8
8
|
module OverflowExtra
|
9
9
|
# Support for Pagy class
|
10
|
-
module
|
10
|
+
module PagyOverride
|
11
11
|
# Is the requested page overflowing?
|
12
12
|
def overflow?
|
13
13
|
@overflow
|
@@ -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)
|
@@ -50,9 +50,11 @@ class Pagy # :nodoc:
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
+
Pagy.prepend PagyOverride
|
54
|
+
Pagy::Calendar.prepend PagyOverride if defined?(Calendar)
|
53
55
|
|
54
56
|
# Support for Pagy::Countless class
|
55
|
-
module
|
57
|
+
module CountlessOverride
|
56
58
|
# Add rescue clause for different behaviors
|
57
59
|
def finalize(items)
|
58
60
|
@overflow = false
|
@@ -71,8 +73,8 @@ class Pagy # :nodoc:
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
76
|
+
# :nocov:
|
77
|
+
Pagy::Countless.prepend CountlessOverride if defined?(Countless)
|
78
|
+
# :nocov:
|
74
79
|
end
|
75
|
-
prepend OverflowExtra::Pagy
|
76
|
-
Calendar.prepend OverflowExtra::Pagy if defined?(Calendar)
|
77
|
-
Countless.prepend OverflowExtra::Countless if defined?(Countless)
|
78
80
|
end
|
@@ -1,4 +1,4 @@
|
|
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:
|
@@ -7,7 +7,7 @@ class Pagy # :nodoc:
|
|
7
7
|
|
8
8
|
# Paginate Searchkick::Results objects
|
9
9
|
module SearchkickExtra
|
10
|
-
module
|
10
|
+
module ModelExtension # :nodoc:
|
11
11
|
# Return an array used to delay the call of #search
|
12
12
|
# after the pagination variables are merged to the options.
|
13
13
|
# It also pushes to the same array an optional method call.
|
@@ -18,9 +18,10 @@ class Pagy # :nodoc:
|
|
18
18
|
end
|
19
19
|
alias_method Pagy::DEFAULT[:searchkick_pagy_search], :pagy_searchkick
|
20
20
|
end
|
21
|
+
Pagy::Searchkick = ModelExtension
|
21
22
|
|
22
23
|
# Additions for the Pagy class
|
23
|
-
module
|
24
|
+
module PagyExtension
|
24
25
|
# Create a Pagy object from a Searchkick::Results object
|
25
26
|
def new_from_searchkick(results, vars = {})
|
26
27
|
vars[:items] = results.options[:per_page]
|
@@ -29,9 +30,10 @@ class Pagy # :nodoc:
|
|
29
30
|
new(vars)
|
30
31
|
end
|
31
32
|
end
|
33
|
+
Pagy.extend PagyExtension
|
32
34
|
|
33
35
|
# Add specialized backend methods to paginate Searchkick::Results
|
34
|
-
module
|
36
|
+
module BackendAddOn
|
35
37
|
private
|
36
38
|
|
37
39
|
# Return Pagy object and results
|
@@ -56,12 +58,10 @@ class Pagy # :nodoc:
|
|
56
58
|
def pagy_searchkick_get_vars(_collection, vars)
|
57
59
|
pagy_set_items_from_params(vars) if defined?(ItemsExtra)
|
58
60
|
vars[:items] ||= DEFAULT[:items]
|
59
|
-
vars[:page] ||= (
|
61
|
+
vars[:page] ||= pagy_get_page(vars)
|
60
62
|
vars
|
61
63
|
end
|
62
64
|
end
|
65
|
+
Backend.prepend BackendAddOn
|
63
66
|
end
|
64
|
-
Searchkick = SearchkickExtra::Searchkick
|
65
|
-
extend SearchkickExtra::Pagy
|
66
|
-
Backend.prepend SearchkickExtra::Backend
|
67
67
|
end
|