pagy 7.0.11 → 8.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/lib/apps/calendar.ru +2196 -0
- data/lib/apps/demo.ru +452 -0
- data/lib/apps/rails.ru +205 -0
- data/lib/apps/repro.ru +168 -0
- data/lib/bin/pagy +83 -0
- data/lib/config/pagy.rb +6 -17
- data/lib/javascripts/pagy-dev.js +10 -10
- data/lib/javascripts/pagy-module.js +9 -9
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/ar.yml +2 -2
- data/lib/locales/be.yml +4 -4
- data/lib/locales/bg.yml +4 -4
- data/lib/locales/bs.yml +4 -4
- data/lib/locales/ca.yml +4 -4
- data/lib/locales/ckb.yml +4 -4
- data/lib/locales/cs.yml +4 -4
- data/lib/locales/da.yml +4 -4
- data/lib/locales/de.yml +4 -4
- data/lib/locales/en.yml +4 -4
- data/lib/locales/es.yml +2 -2
- data/lib/locales/fr.yml +4 -4
- data/lib/locales/hr.yml +4 -4
- data/lib/locales/id.yml +4 -4
- data/lib/locales/it.yml +4 -4
- data/lib/locales/ja.yml +4 -4
- data/lib/locales/km.yml +4 -4
- data/lib/locales/ko.yml +4 -4
- data/lib/locales/nb.yml +4 -4
- data/lib/locales/nl.yml +4 -4
- data/lib/locales/nn.yml +4 -4
- data/lib/locales/pl.yml +4 -4
- data/lib/locales/pt-BR.yml +2 -2
- data/lib/locales/pt.yml +2 -2
- data/lib/locales/ru.yml +4 -4
- data/lib/locales/sr.yml +4 -4
- data/lib/locales/sv-SE.yml +4 -4
- data/lib/locales/sv.yml +4 -4
- data/lib/locales/sw.yml +4 -4
- data/lib/locales/ta.yml +4 -4
- data/lib/locales/tr.yml +4 -4
- data/lib/locales/uk.yml +4 -4
- data/lib/locales/vi.yml +4 -4
- data/lib/locales/zh-CN.yml +4 -4
- data/lib/locales/zh-HK.yml +4 -4
- data/lib/locales/zh-TW.yml +4 -4
- data/lib/optimist.rb +1022 -0
- data/lib/pagy/extras/bootstrap.rb +52 -63
- data/lib/pagy/extras/bulma.rb +48 -64
- data/lib/pagy/extras/foundation.rb +49 -61
- data/lib/pagy/extras/items.rb +21 -18
- data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +1 -1
- data/lib/pagy/extras/materialize.rb +52 -51
- data/lib/pagy/extras/pagy.rb +82 -0
- data/lib/pagy/extras/semantic.rb +46 -50
- data/lib/pagy/extras/trim.rb +12 -12
- data/lib/pagy/extras/uikit.rb +48 -49
- data/lib/pagy/frontend.rb +31 -48
- data/lib/pagy/url_helpers.rb +1 -2
- data/lib/pagy.rb +10 -9
- data/lib/stylesheets/pagy.css +19 -34
- data/lib/stylesheets/pagy.scss +17 -19
- data/lib/stylesheets/pagy.tailwind.css +21 -0
- metadata +25 -9
- data/lib/pagy/extras/navs.rb +0 -51
- data/lib/pagy/extras/support.rb +0 -40
- data/lib/stylesheets/pagy.tailwind.scss +0 -24
data/lib/pagy/frontend.rb
CHANGED
@@ -15,60 +15,53 @@ class Pagy
|
|
15
15
|
include UrlHelpers
|
16
16
|
|
17
17
|
# Generic pagination: it returns the html with the series of links to the pages
|
18
|
-
def pagy_nav(pagy,
|
19
|
-
|
20
|
-
|
21
|
-
link = pagy_link_proc(pagy, link_extra:)
|
18
|
+
def pagy_nav(pagy, id: nil, aria_label: nil, **vars)
|
19
|
+
id = %( id="#{id}") if id
|
20
|
+
a = pagy_anchor(pagy)
|
22
21
|
|
23
|
-
html =
|
24
|
-
|
22
|
+
html = %(<nav#{id} class="pagy nav" #{nav_aria_label(pagy, aria_label:)}>#{
|
23
|
+
prev_a(pagy, a)})
|
25
24
|
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
26
25
|
html << case item
|
27
26
|
when Integer
|
28
|
-
|
27
|
+
a.(item)
|
29
28
|
when String
|
30
|
-
%(<
|
31
|
-
%(<a role="link" aria-disabled="true" aria-current="page">#{pagy.label_for(item)}</a></span>)
|
29
|
+
%(<a role="link" aria-disabled="true" aria-current="page" class="current">#{pagy.label_for(item)}</a>)
|
32
30
|
when :gap
|
33
|
-
%(<
|
31
|
+
%(<a role="link" aria-disabled="true" class="gap">#{pagy_t('pagy.gap')}</a>)
|
34
32
|
else
|
35
33
|
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
36
34
|
end
|
37
35
|
end
|
38
|
-
html << %(#{
|
36
|
+
html << %(#{next_a(pagy, a)}</nav>)
|
39
37
|
end
|
40
38
|
|
41
39
|
# Return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
|
42
|
-
def pagy_info(pagy,
|
43
|
-
|
40
|
+
def pagy_info(pagy, id: nil, item_name: nil)
|
41
|
+
id = %( id="#{id}") if id
|
44
42
|
p_count = pagy.count
|
45
43
|
key = if p_count.zero? then 'pagy.info.no_items'
|
46
44
|
elsif pagy.pages == 1 then 'pagy.info.single_page'
|
47
45
|
else 'pagy.info.multiple_pages' # rubocop:disable Lint/ElseLayout
|
48
46
|
end
|
49
47
|
|
50
|
-
%(<span#{
|
51
|
-
pagy_t key, item_name: item_name || pagy_t(
|
48
|
+
%(<span#{id} class="pagy info">#{
|
49
|
+
pagy_t key, item_name: item_name || pagy_t('pagy.item_name', count: p_count),
|
52
50
|
count: p_count, from: pagy.from, to: pagy.to
|
53
51
|
}</span>)
|
54
52
|
end
|
55
53
|
|
56
|
-
# Return a performance optimized lambda to generate the
|
54
|
+
# Return a performance optimized lambda to generate the HtML anchor element (a tag)
|
57
55
|
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
left, right = %(<a href="#{pagy_url_for(pagy, PAGE_TOKEN)}" #{
|
63
|
-
pagy.vars[:link_extra]} #{link_extra}).split(PAGE_TOKEN, 2)
|
56
|
+
def pagy_anchor(pagy)
|
57
|
+
a_string = pagy.vars[:anchor_string]
|
58
|
+
a_string = %( #{a_string}) if a_string
|
59
|
+
left, right = %(<a#{a_string} href="#{pagy_url_for(pagy, PAGE_TOKEN)}").split(PAGE_TOKEN, 2)
|
64
60
|
# lambda used by all the helpers
|
65
|
-
lambda do |page, text = pagy.label_for(page),
|
66
|
-
%(#{
|
67
|
-
|
68
|
-
|
69
|
-
when p_page then ' aria-disabled="true" aria-current="page"'
|
70
|
-
else ''
|
71
|
-
end } #{extra_attrs}>#{text}</a>)
|
61
|
+
lambda do |page, text = pagy.label_for(page), classes: nil, aria_label: nil|
|
62
|
+
classes = %( class="#{classes}") if classes
|
63
|
+
aria_label = %( aria-label="#{aria_label}") if aria_label
|
64
|
+
%(#{left}#{page}#{right}#{classes}#{aria_label}>#{text}</a>)
|
72
65
|
end
|
73
66
|
end
|
74
67
|
|
@@ -80,34 +73,24 @@ class Pagy
|
|
80
73
|
|
81
74
|
private
|
82
75
|
|
83
|
-
def
|
84
|
-
|
85
|
-
%(aria-label="#{
|
76
|
+
def nav_aria_label(pagy, aria_label: nil)
|
77
|
+
aria_label ||= pagy_t('pagy.aria_label.nav', count: pagy.pages)
|
78
|
+
%(aria-label="#{aria_label}")
|
86
79
|
end
|
87
80
|
|
88
|
-
def
|
89
|
-
%(aria-label="#{pagy_t('pagy.aria_label.prev')}")
|
90
|
-
end
|
91
|
-
|
92
|
-
def next_aria_label_attr
|
93
|
-
%(aria-label="#{pagy_t('pagy.aria_label.next')}")
|
94
|
-
end
|
95
|
-
|
96
|
-
def prev_html(pagy, link, text: pagy_t('pagy.prev'))
|
81
|
+
def prev_a(pagy, a, text: pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))
|
97
82
|
if (p_prev = pagy.prev)
|
98
|
-
|
83
|
+
a.(p_prev, text, aria_label:)
|
99
84
|
else
|
100
|
-
%(<
|
101
|
-
prev_aria_label_attr}>#{text}</a></span>)
|
85
|
+
%(<a role="link" aria-disabled="true" aria-label="#{aria_label}">#{text}</a>)
|
102
86
|
end
|
103
87
|
end
|
104
88
|
|
105
|
-
def
|
89
|
+
def next_a(pagy, a, text: pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.next'))
|
106
90
|
if (p_next = pagy.next)
|
107
|
-
|
91
|
+
a.(p_next, text, aria_label:)
|
108
92
|
else
|
109
|
-
%(<
|
110
|
-
next_aria_label_attr}>#{text}</a></span>)
|
93
|
+
%(<a role="link" aria-disabled="true" aria-label=#{aria_label}>#{text}</a>)
|
111
94
|
end
|
112
95
|
end
|
113
96
|
end
|
data/lib/pagy/url_helpers.rb
CHANGED
@@ -8,13 +8,12 @@ class Pagy
|
|
8
8
|
# For non-rack environments you can use the standalone extra
|
9
9
|
def pagy_url_for(pagy, page, absolute: false, **_)
|
10
10
|
vars = pagy.vars
|
11
|
-
request_path = vars[:request_path].to_s.empty? ? request.path : vars[:request_path]
|
12
11
|
pagy_params = pagy.params.is_a?(Hash) ? pagy.params.transform_keys(&:to_s) : {}
|
13
12
|
params = request.GET.merge(pagy_params)
|
14
13
|
pagy_set_query_params(page, vars, params)
|
15
14
|
params = pagy.params.call(params) if pagy.params.is_a?(Proc)
|
16
15
|
query_string = "?#{Rack::Utils.build_nested_query(params)}"
|
17
|
-
"#{request.base_url if absolute}#{request_path}#{query_string}#{vars[:fragment]}"
|
16
|
+
"#{request.base_url if absolute}#{vars[:request_path] || request.path}#{query_string}#{vars[:fragment]}"
|
18
17
|
end
|
19
18
|
|
20
19
|
# Add the page and items params
|
data/lib/pagy.rb
CHANGED
@@ -5,27 +5,28 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# Core class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '
|
8
|
+
VERSION = '8.0.0'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
12
12
|
@root ||= Pathname.new(__dir__).freeze
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Core defult: constant for easy access, but mutable for customizable defaults
|
16
16
|
DEFAULT = { page: 1, # rubocop:disable Style/MutableConstant
|
17
17
|
items: 20,
|
18
18
|
outset: 0,
|
19
19
|
size: 7,
|
20
|
-
|
20
|
+
cycle: false,
|
21
|
+
# backend/collection
|
22
|
+
count_args: [:all], # AR friendly
|
23
|
+
# backend/url
|
21
24
|
params: {},
|
25
|
+
page_param: :page,
|
22
26
|
fragment: '',
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
cycle: false,
|
27
|
-
request_path: '',
|
28
|
-
count_args: [:all] } # AR friendly
|
27
|
+
request_path: nil,
|
28
|
+
# frontend/helpers
|
29
|
+
anchor_string: nil }
|
29
30
|
|
30
31
|
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :in, :from, :to, :prev, :next, :params, :request_path
|
31
32
|
|
data/lib/stylesheets/pagy.css
CHANGED
@@ -1,61 +1,46 @@
|
|
1
1
|
.pagy {
|
2
2
|
display: flex;
|
3
|
-
}
|
4
|
-
|
5
|
-
.pagy > :not([hidden]) ~ :not([hidden]) {
|
6
|
-
--space-reverse: 0;
|
7
|
-
margin-right: calc(0.25rem * var(--space-reverse));
|
8
|
-
margin-left: calc(0.25rem * calc(1 - var(--space-reverse)));
|
9
|
-
}
|
10
|
-
|
11
|
-
.pagy {
|
12
3
|
font-family: sans-serif;
|
13
4
|
font-size: 0.875rem;
|
14
5
|
line-height: 1.25rem;
|
15
6
|
font-weight: 600;
|
16
|
-
color:
|
7
|
+
color: #6b7280;
|
17
8
|
}
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
.pagy > :not([hidden]) ~ :not([hidden]) {
|
10
|
+
--space-reverse: 0;
|
11
|
+
margin-right: calc(0.25rem * var(--space-reverse));
|
12
|
+
margin-left: calc(0.25rem * calc(1 - var(--space-reverse)));
|
21
13
|
}
|
22
|
-
|
23
|
-
.pagy .page a {
|
14
|
+
.pagy a:not(.gap) {
|
24
15
|
display: block;
|
25
16
|
text-decoration: none;
|
26
17
|
border-radius: 0.5rem;
|
27
|
-
background-color:
|
18
|
+
background-color: #e5e7eb;
|
28
19
|
padding: 0.25rem 0.75rem;
|
29
20
|
color: inherit;
|
30
21
|
}
|
31
|
-
|
32
|
-
|
33
|
-
background-color: rgb(209 213 219);
|
22
|
+
.pagy a:not(.gap):hover {
|
23
|
+
background-color: #d1d5db;
|
34
24
|
}
|
35
|
-
|
36
|
-
.pagy .page.active a {
|
25
|
+
.pagy a:not(.gap):not([href]) { /* disabled links */
|
37
26
|
cursor: default;
|
38
|
-
background-color:
|
39
|
-
color:
|
27
|
+
background-color: #f3f4f6;
|
28
|
+
color: #d1d5db;
|
40
29
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
background-color: rgb(243 244 246);
|
45
|
-
color: rgb(209 213 219);
|
30
|
+
.pagy a:not(.gap).current {
|
31
|
+
background-color: #9ca3af;
|
32
|
+
color: white;
|
46
33
|
}
|
47
|
-
|
48
|
-
.pagy .pagy-combo-input, .pagy.pagy-items-selector-js {
|
34
|
+
.pagy label {
|
49
35
|
white-space: nowrap;
|
50
36
|
display: inline-block;
|
51
37
|
border-radius: 0.5rem;
|
52
|
-
background-color:
|
38
|
+
background-color: #e5e7eb;
|
53
39
|
padding: 0.125rem 0.75rem;
|
54
40
|
}
|
55
|
-
|
56
|
-
.pagy .pagy-combo-input input, .pagy.pagy-items-selector-js input {
|
41
|
+
.pagy label input {
|
57
42
|
line-height: 1.5rem;
|
58
43
|
border-radius: 0.375rem;
|
59
44
|
border-style: none;
|
60
|
-
background-color:
|
45
|
+
background-color: #f3f4f6;
|
61
46
|
}
|
data/lib/stylesheets/pagy.scss
CHANGED
@@ -10,31 +10,29 @@
|
|
10
10
|
margin-right: calc(0.25rem * var(--space-reverse));
|
11
11
|
margin-left: calc(0.25rem * calc(1 - var(--space-reverse)));
|
12
12
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
}
|
25
|
-
&.active a {
|
26
|
-
cursor: default;
|
27
|
-
background-color: rgb(156 163 175);
|
28
|
-
color: rgb(255 255 255);
|
13
|
+
|
14
|
+
a:not(.gap) {
|
15
|
+
display: block;
|
16
|
+
text-decoration: none;
|
17
|
+
border-radius: 0.5rem;
|
18
|
+
background-color: rgb(229 231 235);
|
19
|
+
padding: 0.25rem 0.75rem;
|
20
|
+
color: inherit;
|
21
|
+
&:hover {
|
22
|
+
background-color: rgb(209 213 219);
|
29
23
|
}
|
30
|
-
|
24
|
+
&:not([href]) { /* disabled links */
|
31
25
|
cursor: default;
|
32
26
|
background-color: rgb(243 244 246);
|
33
27
|
color: rgb(209 213 219);
|
34
28
|
}
|
35
|
-
&.
|
29
|
+
&.current {
|
30
|
+
background-color: rgb(156 163 175);
|
31
|
+
color: rgb(255 255 255);
|
32
|
+
}
|
36
33
|
}
|
37
|
-
|
34
|
+
|
35
|
+
label {
|
38
36
|
white-space: nowrap;
|
39
37
|
display: inline-block;
|
40
38
|
border-radius: 0.5rem;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
.pagy {
|
2
|
+
@apply flex space-x-1 font-semibold text-sm text-gray-500;
|
3
|
+
a:not(.gap) {
|
4
|
+
@apply block rounded-lg px-3 py-1 bg-gray-200;
|
5
|
+
&:hover {
|
6
|
+
@apply bg-gray-300;
|
7
|
+
}
|
8
|
+
&:not([href]) { /* disabled links */
|
9
|
+
@apply text-gray-300 bg-gray-100 cursor-default;
|
10
|
+
}
|
11
|
+
&.current {
|
12
|
+
@apply text-white bg-gray-400;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
label {
|
16
|
+
@apply inline-block whitespace-nowrap bg-gray-200 rounded-lg px-3 py-0.5;
|
17
|
+
input {
|
18
|
+
@apply bg-gray-100 border-none rounded-md;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
metadata
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
|
-
bindir: bin
|
9
|
+
bindir: lib/bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|
15
15
|
- dd.nexus@gmail.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- pagy
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- LICENSE.txt
|
22
|
+
- lib/apps/calendar.ru
|
23
|
+
- lib/apps/demo.ru
|
24
|
+
- lib/apps/rails.ru
|
25
|
+
- lib/apps/repro.ru
|
26
|
+
- lib/bin/pagy
|
21
27
|
- lib/config/pagy.rb
|
22
28
|
- lib/javascripts/pagy-dev.js
|
23
29
|
- lib/javascripts/pagy-module.d.ts
|
@@ -59,6 +65,7 @@ files:
|
|
59
65
|
- lib/locales/zh-CN.yml
|
60
66
|
- lib/locales/zh-HK.yml
|
61
67
|
- lib/locales/zh-TW.yml
|
68
|
+
- lib/optimist.rb
|
62
69
|
- lib/pagy.rb
|
63
70
|
- lib/pagy/backend.rb
|
64
71
|
- lib/pagy/calendar.rb
|
@@ -79,21 +86,20 @@ files:
|
|
79
86
|
- lib/pagy/extras/countless.rb
|
80
87
|
- lib/pagy/extras/elasticsearch_rails.rb
|
81
88
|
- lib/pagy/extras/foundation.rb
|
82
|
-
- lib/pagy/extras/frontend_helpers.rb
|
83
89
|
- lib/pagy/extras/gearbox.rb
|
84
90
|
- lib/pagy/extras/headers.rb
|
85
91
|
- lib/pagy/extras/i18n.rb
|
86
92
|
- lib/pagy/extras/items.rb
|
93
|
+
- lib/pagy/extras/js_tools.rb
|
87
94
|
- lib/pagy/extras/jsonapi.rb
|
88
95
|
- lib/pagy/extras/materialize.rb
|
89
96
|
- lib/pagy/extras/meilisearch.rb
|
90
97
|
- lib/pagy/extras/metadata.rb
|
91
|
-
- lib/pagy/extras/navs.rb
|
92
98
|
- lib/pagy/extras/overflow.rb
|
99
|
+
- lib/pagy/extras/pagy.rb
|
93
100
|
- lib/pagy/extras/searchkick.rb
|
94
101
|
- lib/pagy/extras/semantic.rb
|
95
102
|
- lib/pagy/extras/standalone.rb
|
96
|
-
- lib/pagy/extras/support.rb
|
97
103
|
- lib/pagy/extras/trim.rb
|
98
104
|
- lib/pagy/extras/uikit.rb
|
99
105
|
- lib/pagy/frontend.rb
|
@@ -101,7 +107,7 @@ files:
|
|
101
107
|
- lib/pagy/url_helpers.rb
|
102
108
|
- lib/stylesheets/pagy.css
|
103
109
|
- lib/stylesheets/pagy.scss
|
104
|
-
- lib/stylesheets/pagy.tailwind.
|
110
|
+
- lib/stylesheets/pagy.tailwind.css
|
105
111
|
homepage: https://github.com/ddnexus/pagy
|
106
112
|
licenses:
|
107
113
|
- MIT
|
@@ -112,7 +118,16 @@ metadata:
|
|
112
118
|
bug_tracker_uri: https://github.com/ddnexus/pagy/issues
|
113
119
|
changelog_uri: https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md
|
114
120
|
support: https://github.com/ddnexus/pagy/discussions/categories/q-a
|
115
|
-
post_install_message:
|
121
|
+
post_install_message: |2+
|
122
|
+
|
123
|
+
*********************** PAGY WARNING! ***********************
|
124
|
+
We may drop pagy's less used CSS extras.
|
125
|
+
|
126
|
+
If you wish to keep them alive, please, vote here:
|
127
|
+
|
128
|
+
https://github.com/ddnexus/pagy/discussions/categories/survey
|
129
|
+
*************************************************************
|
130
|
+
|
116
131
|
rdoc_options: []
|
117
132
|
require_paths:
|
118
133
|
- lib
|
@@ -132,3 +147,4 @@ signing_key:
|
|
132
147
|
specification_version: 4
|
133
148
|
summary: The best pagination ruby gem
|
134
149
|
test_files: []
|
150
|
+
...
|
data/lib/pagy/extras/navs.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/navs
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'pagy/extras/frontend_helpers'
|
5
|
-
|
6
|
-
class Pagy # :nodoc:
|
7
|
-
# Frontend modules are specially optimized for performance.
|
8
|
-
# The resulting code may not look very elegant, but produces the best benchmarks
|
9
|
-
module NavsExtra
|
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: '',
|
12
|
-
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
13
|
-
sequels = pagy.sequels(**vars)
|
14
|
-
p_id = %( id="#{pagy_id}") if pagy_id
|
15
|
-
link = pagy_link_proc(pagy, link_extra:)
|
16
|
-
tags = { 'before' => prev_html(pagy, link),
|
17
|
-
'link' => %(<span class="page">#{link.call(PAGE_TOKEN, LABEL_TOKEN)}</span>),
|
18
|
-
'active' => %(<span class="page active">) +
|
19
|
-
%(<a role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a></span>),
|
20
|
-
'gap' => %(<span class="page gap">#{pagy_t 'pagy.gap'}</span>),
|
21
|
-
'after' => next_html(pagy, link) }
|
22
|
-
|
23
|
-
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy pagy-nav-js pagination" #{
|
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>)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Javascript combo pagination: it returns a nav and a JSON tag used by the pagy.js file
|
30
|
-
def pagy_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
|
31
|
-
nav_aria_label: nil, nav_i18n_key: nil)
|
32
|
-
p_id = %( id="#{pagy_id}") if pagy_id
|
33
|
-
link = pagy_link_proc(pagy, link_extra:)
|
34
|
-
p_page = pagy.page
|
35
|
-
p_pages = pagy.pages
|
36
|
-
input = %(<input name="page" 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">)
|
38
|
-
|
39
|
-
%(<nav#{p_id} class="pagy pagy-combo-nav-js pagination" #{
|
40
|
-
nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)} #{
|
41
|
-
pagy_data(pagy, :combo, pagy_url_for(pagy, PAGE_TOKEN))}>#{
|
42
|
-
prev_html(pagy, link)
|
43
|
-
}<span class="pagy-combo-input">#{
|
44
|
-
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
|
45
|
-
}</span>#{
|
46
|
-
next_html(pagy, link)
|
47
|
-
}</nav>)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
Frontend.prepend NavsExtra
|
51
|
-
end
|
data/lib/pagy/extras/support.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/support
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
class Pagy # :nodoc:
|
5
|
-
# Extra support for features like: incremental, auto-incremental and infinite pagination
|
6
|
-
module SupportExtra
|
7
|
-
# Return the previous page URL string or nil
|
8
|
-
def pagy_prev_url(pagy, absolute: false)
|
9
|
-
pagy_url_for(pagy, pagy.prev, absolute:) if pagy.prev
|
10
|
-
end
|
11
|
-
|
12
|
-
# Return the next page URL string or nil
|
13
|
-
def pagy_next_url(pagy, absolute: false)
|
14
|
-
pagy_url_for(pagy, pagy.next, absolute:) if pagy.next
|
15
|
-
end
|
16
|
-
|
17
|
-
# Return the HTML string for the enabled/disabled previous page link
|
18
|
-
def pagy_prev_html(pagy, text: pagy_t('pagy.prev'), link_extra: '')
|
19
|
-
link = pagy_link_proc(pagy, link_extra:)
|
20
|
-
prev_html(pagy, link, text:)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Return the HTML string for the enabled/disabled next page link
|
24
|
-
def pagy_next_html(pagy, text: pagy_t('pagy.next'), link_extra: '')
|
25
|
-
link = pagy_link_proc(pagy, link_extra:)
|
26
|
-
next_html(pagy, link, text:)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Conditionally return the HTML link tag string for the previous page
|
30
|
-
def pagy_prev_link_tag(pagy, absolute: false)
|
31
|
-
%(<link href="#{pagy_url_for(pagy, pagy.prev, absolute:)}" rel="prev"/>) if pagy.prev
|
32
|
-
end
|
33
|
-
|
34
|
-
# Conditionally return the HTML link tag string for the next page
|
35
|
-
def pagy_next_link_tag(pagy, absolute: false)
|
36
|
-
%(<link href="#{pagy_url_for(pagy, pagy.next, absolute:)}" rel="next"/>) if pagy.next
|
37
|
-
end
|
38
|
-
end
|
39
|
-
Frontend.prepend SupportExtra
|
40
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
.pagy {
|
2
|
-
@apply flex space-x-1 font-semibold text-sm text-gray-500;
|
3
|
-
.page {
|
4
|
-
a {
|
5
|
-
@apply block rounded-lg px-3 py-1 bg-gray-200;
|
6
|
-
&:hover {
|
7
|
-
@apply bg-gray-300;
|
8
|
-
}
|
9
|
-
}
|
10
|
-
&.active a {
|
11
|
-
@apply text-white bg-gray-400 cursor-default;
|
12
|
-
}
|
13
|
-
&.disabled a {
|
14
|
-
@apply text-gray-300 bg-gray-100 cursor-default;
|
15
|
-
}
|
16
|
-
&.gap { } /* if you need to customize it */
|
17
|
-
}
|
18
|
-
.pagy-combo-input, &.pagy-items-selector-js {
|
19
|
-
@apply inline-block whitespace-nowrap bg-gray-200 rounded-lg px-3 py-0.5;
|
20
|
-
input {
|
21
|
-
@apply bg-gray-100 border-none rounded-md;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|