pagy 7.0.11 → 43.5.1
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/apps/calendar.ru +741 -0
- data/apps/demo.ru +513 -0
- data/apps/enable_rails_page_segment.rb +54 -0
- data/apps/index.rb +9 -0
- data/apps/keynav+root_key.ru +316 -0
- data/apps/keynav.ru +255 -0
- data/apps/keyset.ru +219 -0
- data/apps/keyset_sequel.ru +212 -0
- data/apps/rails.ru +216 -0
- data/apps/repro.ru +185 -0
- data/bin/pagy +5 -0
- data/config/pagy.rb +46 -0
- data/javascripts/ai_widget.js +90 -0
- data/javascripts/pagy.js +168 -0
- data/javascripts/pagy.min.js +2 -0
- data/javascripts/pagy.mjs +161 -0
- data/javascripts/wand.js +1172 -0
- data/lib/pagy/classes/calendar/calendar.rb +101 -0
- data/lib/pagy/{calendar → classes/calendar}/day.rb +9 -12
- data/lib/pagy/{calendar → classes/calendar}/month.rb +7 -11
- data/lib/pagy/{calendar → classes/calendar}/quarter.rb +12 -16
- data/lib/pagy/classes/calendar/unit.rb +93 -0
- data/lib/pagy/{calendar → classes/calendar}/week.rb +7 -11
- data/lib/pagy/{calendar → classes/calendar}/year.rb +9 -9
- data/lib/pagy/classes/exceptions.rb +26 -0
- data/lib/pagy/classes/keyset/adapters/active_record.rb +50 -0
- data/lib/pagy/classes/keyset/adapters/sequel.rb +62 -0
- data/lib/pagy/classes/keyset/keynav.rb +85 -0
- data/lib/pagy/classes/keyset/keyset.rb +150 -0
- data/lib/pagy/classes/offset/countish.rb +17 -0
- data/lib/pagy/classes/offset/countless.rb +63 -0
- data/lib/pagy/classes/offset/offset.rb +63 -0
- data/lib/pagy/classes/offset/search.rb +34 -0
- data/lib/pagy/classes/request.rb +48 -0
- data/lib/pagy/cli.rb +122 -0
- data/lib/pagy/console.rb +5 -20
- data/lib/pagy/deprecated.rb +84 -0
- data/lib/pagy/modules/abilities/configurable.rb +37 -0
- data/lib/pagy/modules/abilities/countable.rb +23 -0
- data/lib/pagy/modules/abilities/linkable.rb +72 -0
- data/lib/pagy/modules/abilities/rangeable.rb +14 -0
- data/lib/pagy/modules/abilities/shiftable.rb +12 -0
- data/lib/pagy/modules/b64.rb +35 -0
- data/lib/pagy/modules/console.rb +33 -0
- data/lib/pagy/modules/i18n/i18n.rb +72 -0
- data/lib/pagy/modules/i18n/p11n/arabic.rb +30 -0
- data/lib/pagy/modules/i18n/p11n/east_slavic.rb +27 -0
- data/lib/pagy/modules/i18n/p11n/one_other.rb +15 -0
- data/lib/pagy/modules/i18n/p11n/one_upto_two_other.rb +15 -0
- data/lib/pagy/modules/i18n/p11n/other.rb +13 -0
- data/lib/pagy/modules/i18n/p11n/polish.rb +27 -0
- data/lib/pagy/modules/i18n/p11n/west_slavic.rb +22 -0
- data/lib/pagy/modules/i18n/p11n.rb +16 -0
- data/lib/pagy/modules/searcher.rb +20 -0
- data/lib/pagy/next.rb +25 -0
- data/lib/pagy/tasks/sync.rb +20 -0
- data/lib/pagy/toolbox/helpers/anchor_tags.rb +21 -0
- data/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb +28 -0
- data/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb +19 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb +32 -0
- data/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb +24 -0
- data/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb +25 -0
- data/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb +20 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav.rb +31 -0
- data/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb +23 -0
- data/lib/pagy/toolbox/helpers/data_hash.rb +29 -0
- data/lib/pagy/toolbox/helpers/headers_hash.rb +30 -0
- data/lib/pagy/toolbox/helpers/info_tag.rb +30 -0
- data/lib/pagy/toolbox/helpers/input_nav_js.rb +22 -0
- data/lib/pagy/toolbox/helpers/limit_tag_js.rb +25 -0
- data/lib/pagy/toolbox/helpers/loaders.rb +55 -0
- data/lib/pagy/toolbox/helpers/page_url.rb +16 -0
- data/lib/pagy/toolbox/helpers/series_nav.rb +30 -0
- data/lib/pagy/toolbox/helpers/series_nav_js.rb +20 -0
- data/lib/pagy/toolbox/helpers/support/a_lambda.rb +36 -0
- data/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb +19 -0
- data/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb +10 -0
- data/lib/pagy/toolbox/helpers/support/series.rb +37 -0
- data/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb +19 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb +17 -0
- data/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb +42 -0
- data/lib/pagy/toolbox/helpers/urls_hash.rb +12 -0
- data/lib/pagy/toolbox/paginators/calendar.rb +34 -0
- data/lib/pagy/toolbox/paginators/countish.rb +38 -0
- data/lib/pagy/toolbox/paginators/countless.rb +22 -0
- data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +56 -0
- data/lib/pagy/toolbox/paginators/keynav_js.rb +26 -0
- data/lib/pagy/toolbox/paginators/keyset.rb +15 -0
- data/lib/pagy/toolbox/paginators/meilisearch.rb +34 -0
- data/lib/pagy/toolbox/paginators/method.rb +38 -0
- data/lib/pagy/toolbox/paginators/offset.rb +24 -0
- data/lib/pagy/toolbox/paginators/searchkick.rb +34 -0
- data/lib/pagy/toolbox/paginators/typesense_rails.rb +34 -0
- data/lib/pagy.rb +67 -131
- data/locales/ar.yml +32 -0
- data/locales/be.yml +28 -0
- data/locales/bg.yml +24 -0
- data/locales/bs.yml +28 -0
- data/locales/ca.yml +24 -0
- data/locales/ckb.yml +20 -0
- data/locales/cs.yml +26 -0
- data/locales/da.yml +24 -0
- data/locales/de.yml +24 -0
- data/locales/dz.yml +20 -0
- data/locales/en.yml +24 -0
- data/{lib/locales → locales}/es.yml +9 -6
- data/locales/fr.yml +24 -0
- data/locales/hr.yml +28 -0
- data/locales/id.yml +20 -0
- data/locales/it.yml +24 -0
- data/locales/ja.yml +20 -0
- data/locales/km.yml +20 -0
- data/locales/ko.yml +20 -0
- data/locales/nb.yml +24 -0
- data/locales/nl.yml +24 -0
- data/locales/nn.yml +24 -0
- data/locales/pl.yml +28 -0
- data/{lib/locales → locales}/pt-BR.yml +10 -7
- data/{lib/locales → locales}/pt.yml +10 -7
- data/locales/ru.yml +28 -0
- data/locales/sk.yml +26 -0
- data/locales/sr.yml +28 -0
- data/locales/sv-SE.yml +24 -0
- data/locales/sv.yml +24 -0
- data/locales/sw.yml +28 -0
- data/locales/ta.yml +24 -0
- data/locales/tr.yml +24 -0
- data/locales/uk.yml +28 -0
- data/locales/vi.yml +20 -0
- data/locales/zh-CN.yml +20 -0
- data/locales/zh-HK.yml +20 -0
- data/locales/zh-TW.yml +20 -0
- data/stylesheets/pagy-tailwind.css +68 -0
- data/stylesheets/pagy.css +83 -0
- metadata +185 -94
- data/lib/config/pagy.rb +0 -258
- data/lib/javascripts/pagy-dev.js +0 -112
- data/lib/javascripts/pagy-module.js +0 -111
- data/lib/javascripts/pagy.js +0 -1
- data/lib/locales/ar.yml +0 -30
- data/lib/locales/be.yml +0 -25
- data/lib/locales/bg.yml +0 -21
- data/lib/locales/bs.yml +0 -25
- data/lib/locales/ca.yml +0 -23
- data/lib/locales/ckb.yml +0 -18
- data/lib/locales/cs.yml +0 -23
- data/lib/locales/da.yml +0 -23
- data/lib/locales/de.yml +0 -21
- data/lib/locales/en.yml +0 -21
- data/lib/locales/fr.yml +0 -21
- data/lib/locales/hr.yml +0 -25
- data/lib/locales/id.yml +0 -19
- data/lib/locales/it.yml +0 -21
- data/lib/locales/ja.yml +0 -19
- data/lib/locales/km.yml +0 -19
- data/lib/locales/ko.yml +0 -19
- data/lib/locales/nb.yml +0 -21
- data/lib/locales/nl.yml +0 -21
- data/lib/locales/nn.yml +0 -21
- data/lib/locales/pl.yml +0 -25
- data/lib/locales/ru.yml +0 -27
- data/lib/locales/sr.yml +0 -25
- data/lib/locales/sv-SE.yml +0 -21
- data/lib/locales/sv.yml +0 -21
- data/lib/locales/sw.yml +0 -23
- data/lib/locales/ta.yml +0 -23
- data/lib/locales/tr.yml +0 -19
- data/lib/locales/uk.yml +0 -25
- data/lib/locales/vi.yml +0 -17
- data/lib/locales/zh-CN.yml +0 -19
- data/lib/locales/zh-HK.yml +0 -19
- data/lib/locales/zh-TW.yml +0 -19
- data/lib/pagy/backend.rb +0 -39
- data/lib/pagy/calendar/helper.rb +0 -65
- data/lib/pagy/calendar.rb +0 -126
- data/lib/pagy/countless.rb +0 -37
- data/lib/pagy/exceptions.rb +0 -25
- data/lib/pagy/extras/arel.rb +0 -36
- data/lib/pagy/extras/array.rb +0 -24
- data/lib/pagy/extras/bootstrap.rb +0 -108
- data/lib/pagy/extras/bulma.rb +0 -105
- data/lib/pagy/extras/calendar.rb +0 -53
- data/lib/pagy/extras/countless.rb +0 -37
- data/lib/pagy/extras/elasticsearch_rails.rb +0 -80
- data/lib/pagy/extras/foundation.rb +0 -105
- data/lib/pagy/extras/frontend_helpers.rb +0 -67
- data/lib/pagy/extras/gearbox.rb +0 -54
- data/lib/pagy/extras/headers.rb +0 -53
- data/lib/pagy/extras/i18n.rb +0 -26
- data/lib/pagy/extras/items.rb +0 -61
- data/lib/pagy/extras/jsonapi.rb +0 -79
- data/lib/pagy/extras/materialize.rb +0 -96
- data/lib/pagy/extras/meilisearch.rb +0 -65
- data/lib/pagy/extras/metadata.rb +0 -38
- data/lib/pagy/extras/navs.rb +0 -51
- data/lib/pagy/extras/overflow.rb +0 -80
- data/lib/pagy/extras/searchkick.rb +0 -67
- data/lib/pagy/extras/semantic.rb +0 -95
- data/lib/pagy/extras/standalone.rb +0 -60
- data/lib/pagy/extras/support.rb +0 -40
- data/lib/pagy/extras/trim.rb +0 -29
- data/lib/pagy/extras/uikit.rb +0 -97
- data/lib/pagy/frontend.rb +0 -114
- data/lib/pagy/i18n.rb +0 -165
- data/lib/pagy/url_helpers.rb +0 -27
- data/lib/stylesheets/pagy.css +0 -61
- data/lib/stylesheets/pagy.scss +0 -50
- data/lib/stylesheets/pagy.tailwind.scss +0 -24
- /data/{lib/javascripts/pagy-module.d.ts → javascripts/pagy.d.ts} +0 -0
data/lib/pagy/frontend.rb
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# See Pagy::Frontend API documentation: https://ddnexus.github.io/pagy/docs/api/frontend
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'pagy/url_helpers'
|
|
5
|
-
require 'pagy/i18n'
|
|
6
|
-
|
|
7
|
-
class Pagy
|
|
8
|
-
# Used for search and replace, hardcoded also in the pagy.js file
|
|
9
|
-
PAGE_TOKEN = '__pagy_page__'
|
|
10
|
-
LABEL_TOKEN = '__pagy_label__'
|
|
11
|
-
|
|
12
|
-
# Frontend modules are specially optimized for performance.
|
|
13
|
-
# The resulting code may not look very elegant, but produces the best benchmarks
|
|
14
|
-
module Frontend
|
|
15
|
-
include UrlHelpers
|
|
16
|
-
|
|
17
|
-
# Generic pagination: it returns the html with the series of links to the pages
|
|
18
|
-
def pagy_nav(pagy, pagy_id: nil, link_extra: '',
|
|
19
|
-
nav_aria_label: nil, nav_i18n_key: nil, **vars)
|
|
20
|
-
p_id = %( id="#{pagy_id}") if pagy_id
|
|
21
|
-
link = pagy_link_proc(pagy, link_extra:)
|
|
22
|
-
|
|
23
|
-
html = +%(<nav#{p_id} class="pagy pagy-nav pagination" #{nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key)}>)
|
|
24
|
-
html << prev_html(pagy, link)
|
|
25
|
-
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
|
26
|
-
html << case item
|
|
27
|
-
when Integer
|
|
28
|
-
%(<span class="page">#{link.call(item)}</span>)
|
|
29
|
-
when String
|
|
30
|
-
%(<span class="page active">) +
|
|
31
|
-
%(<a role="link" aria-disabled="true" aria-current="page">#{pagy.label_for(item)}</a></span>)
|
|
32
|
-
when :gap
|
|
33
|
-
%(<span class="page gap">#{pagy_t('pagy.gap')}</span>)
|
|
34
|
-
else
|
|
35
|
-
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
html << %(#{next_html(pagy, link)}</nav>)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
|
|
42
|
-
def pagy_info(pagy, pagy_id: nil, item_name: nil, item_i18n_key: nil)
|
|
43
|
-
p_id = %( id="#{pagy_id}") if pagy_id
|
|
44
|
-
p_count = pagy.count
|
|
45
|
-
key = if p_count.zero? then 'pagy.info.no_items'
|
|
46
|
-
elsif pagy.pages == 1 then 'pagy.info.single_page'
|
|
47
|
-
else 'pagy.info.multiple_pages' # rubocop:disable Lint/ElseLayout
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
%(<span#{p_id} class="pagy-info">#{
|
|
51
|
-
pagy_t key, item_name: item_name || pagy_t(item_i18n_key || pagy.vars[:item_i18n_key], count: p_count),
|
|
52
|
-
count: p_count, from: pagy.from, to: pagy.to
|
|
53
|
-
}</span>)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Return a performance optimized lambda to generate the HTML links
|
|
57
|
-
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
|
|
58
|
-
def pagy_link_proc(pagy, link_extra: '')
|
|
59
|
-
p_prev = pagy.prev
|
|
60
|
-
p_next = pagy.next
|
|
61
|
-
p_page = pagy.page.to_s
|
|
62
|
-
left, right = %(<a href="#{pagy_url_for(pagy, PAGE_TOKEN)}" #{
|
|
63
|
-
pagy.vars[:link_extra]} #{link_extra}).split(PAGE_TOKEN, 2)
|
|
64
|
-
# lambda used by all the helpers
|
|
65
|
-
lambda do |page, text = pagy.label_for(page), extra_attrs = ''|
|
|
66
|
-
%(#{left}#{page}#{right}#{ case page
|
|
67
|
-
when p_prev then ' rel="prev"'
|
|
68
|
-
when p_next then ' rel="next"'
|
|
69
|
-
when p_page then ' aria-disabled="true" aria-current="page"'
|
|
70
|
-
else ''
|
|
71
|
-
end } #{extra_attrs}>#{text}</a>)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Similar to I18n.t: just ~18x faster using ~10x less memory
|
|
76
|
-
# (@pagy_locale explicitly initialized in order to avoid warning)
|
|
77
|
-
def pagy_t(key, opts = {})
|
|
78
|
-
Pagy::I18n.translate(@pagy_locale ||= nil, key, opts)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
|
|
83
|
-
def nav_aria_label_attr(pagy, nav_aria_label, nav_i18n_key, count: pagy.pages)
|
|
84
|
-
nav_aria_label ||= pagy_t(nav_i18n_key || pagy.vars[:nav_i18n_key], count:)
|
|
85
|
-
%(aria-label="#{nav_aria_label}")
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def prev_aria_label_attr
|
|
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'))
|
|
97
|
-
if (p_prev = pagy.prev)
|
|
98
|
-
%(<span class="page prev">#{link.call(p_prev, text, prev_aria_label_attr)}</span>)
|
|
99
|
-
else
|
|
100
|
-
%(<span class="page prev disabled"><a role="link" aria-disabled="true" #{
|
|
101
|
-
prev_aria_label_attr}>#{text}</a></span>)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def next_html(pagy, link, text: pagy_t('pagy.next'))
|
|
106
|
-
if (p_next = pagy.next)
|
|
107
|
-
%(<span class="page next">#{link.call(p_next, text, next_aria_label_attr)}</span>)
|
|
108
|
-
else
|
|
109
|
-
%(<span class="page next disabled"><a role="link" aria-disabled="true" #{
|
|
110
|
-
next_aria_label_attr}>#{text}</a></span>)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
data/lib/pagy/i18n.rb
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# See Pagy::I18n API documentation https://ddnexus.github.io/pagy/docs/api/i18n
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'yaml'
|
|
5
|
-
|
|
6
|
-
class Pagy
|
|
7
|
-
# Pagy i18n implementation, compatible with the I18n gem, just a lot faster and lighter
|
|
8
|
-
module I18n
|
|
9
|
-
extend self
|
|
10
|
-
|
|
11
|
-
# Pluralization rules
|
|
12
|
-
module P11n
|
|
13
|
-
# Pluralization variables
|
|
14
|
-
from0to1 = (0..1).to_a.freeze
|
|
15
|
-
from2to4 = (2..4).to_a.freeze
|
|
16
|
-
from3to10 = (3..10).to_a.freeze
|
|
17
|
-
from5to9 = (5..9).to_a.freeze
|
|
18
|
-
from11to14 = (11..14).to_a.freeze
|
|
19
|
-
from11to99 = (11..99).to_a.freeze
|
|
20
|
-
from12to14 = (12..14).to_a.freeze
|
|
21
|
-
|
|
22
|
-
from0to1_from5to9 = from0to1 + from5to9
|
|
23
|
-
|
|
24
|
-
# Store the proc defining each pluralization RULE
|
|
25
|
-
# Logic adapted from https://github.com/svenfuchs/rails-i18n
|
|
26
|
-
RULE = {
|
|
27
|
-
arabic:
|
|
28
|
-
lambda do |n = 0|
|
|
29
|
-
mod100 = n % 100
|
|
30
|
-
case
|
|
31
|
-
when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
|
|
32
|
-
when n == 1 then 'one'
|
|
33
|
-
when n == 2 then 'two'
|
|
34
|
-
when from3to10.include?(mod100) then 'few'
|
|
35
|
-
when from11to99.include?(mod100) then 'many'
|
|
36
|
-
else 'other'
|
|
37
|
-
end
|
|
38
|
-
end,
|
|
39
|
-
|
|
40
|
-
east_slavic:
|
|
41
|
-
lambda do |n = 0|
|
|
42
|
-
mod10 = n % 10
|
|
43
|
-
mod100 = n % 100
|
|
44
|
-
case
|
|
45
|
-
when mod10 == 1 && mod100 != 11 then 'one'
|
|
46
|
-
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
|
47
|
-
when mod10 == 0 || from5to9.include?(mod10) || from11to14.include?(mod100) then 'many' # rubocop:disable Style/NumericPredicate
|
|
48
|
-
else 'other'
|
|
49
|
-
end
|
|
50
|
-
end,
|
|
51
|
-
|
|
52
|
-
one_other:
|
|
53
|
-
->(n) { n == 1 ? 'one' : 'other' }, # default RULE
|
|
54
|
-
|
|
55
|
-
one_two_other:
|
|
56
|
-
lambda do |n|
|
|
57
|
-
case n
|
|
58
|
-
when 1 then 'one'
|
|
59
|
-
when 2 then 'two'
|
|
60
|
-
else 'other'
|
|
61
|
-
end
|
|
62
|
-
end,
|
|
63
|
-
|
|
64
|
-
one_upto_two_other:
|
|
65
|
-
->(n) { n && n >= 0 && n < 2 ? 'one' : 'other' },
|
|
66
|
-
|
|
67
|
-
other:
|
|
68
|
-
->(*) { 'other' },
|
|
69
|
-
|
|
70
|
-
polish:
|
|
71
|
-
lambda do |n = 0|
|
|
72
|
-
mod10 = n % 10
|
|
73
|
-
mod100 = n % 100
|
|
74
|
-
case
|
|
75
|
-
when n == 1 then 'one'
|
|
76
|
-
when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
|
|
77
|
-
when from0to1_from5to9.include?(mod10) || from12to14.include?(mod100) then 'many'
|
|
78
|
-
else 'other'
|
|
79
|
-
end
|
|
80
|
-
end,
|
|
81
|
-
|
|
82
|
-
west_slavic:
|
|
83
|
-
lambda do |n|
|
|
84
|
-
case n
|
|
85
|
-
when 1 then 'one'
|
|
86
|
-
when *from2to4 then 'few'
|
|
87
|
-
else 'other'
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
}.freeze
|
|
92
|
-
|
|
93
|
-
# Store the RULE to apply to each LOCALE
|
|
94
|
-
# the :one_other RULE is the default for locales missing from this list
|
|
95
|
-
LOCALE = Hash.new(RULE[:one_other]).tap do |hash|
|
|
96
|
-
hash['ar'] = RULE[:arabic]
|
|
97
|
-
hash['be'] = RULE[:east_slavic]
|
|
98
|
-
hash['bs'] = RULE[:east_slavic]
|
|
99
|
-
hash['ckb'] = RULE[:other]
|
|
100
|
-
hash['cs'] = RULE[:west_slavic]
|
|
101
|
-
hash['id'] = RULE[:other]
|
|
102
|
-
hash['fr'] = RULE[:one_upto_two_other]
|
|
103
|
-
hash['hr'] = RULE[:east_slavic]
|
|
104
|
-
hash['ja'] = RULE[:other]
|
|
105
|
-
hash['km'] = RULE[:other]
|
|
106
|
-
hash['ko'] = RULE[:other]
|
|
107
|
-
hash['pl'] = RULE[:polish]
|
|
108
|
-
hash['ru'] = RULE[:east_slavic]
|
|
109
|
-
hash['sr'] = RULE[:east_slavic]
|
|
110
|
-
hash['tr'] = RULE[:other]
|
|
111
|
-
hash['uk'] = RULE[:east_slavic]
|
|
112
|
-
hash['vi'] = RULE[:other]
|
|
113
|
-
hash['zh-CN'] = RULE[:other]
|
|
114
|
-
hash['zh-HK'] = RULE[:other]
|
|
115
|
-
hash['zh-TW'] = RULE[:other]
|
|
116
|
-
end.freeze
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# Stores the i18n DATA structure for each loaded locale
|
|
120
|
-
# default on the first locale DATA
|
|
121
|
-
DATA = Hash.new { |hash, _| hash.first[1] }
|
|
122
|
-
|
|
123
|
-
private
|
|
124
|
-
|
|
125
|
-
# Create a flat hash with dotted notation keys
|
|
126
|
-
def flatten(initial, prefix = '')
|
|
127
|
-
initial.each.reduce({}) do |hash, (key, value)|
|
|
128
|
-
hash.merge!(value.is_a?(Hash) ? flatten(value, "#{prefix}#{key}.") : { "#{prefix}#{key}" => value })
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Build the DATA hash out of the passed locales
|
|
133
|
-
def build(*locales)
|
|
134
|
-
locales.each do |locale|
|
|
135
|
-
locale[:filepath] ||= Pagy.root.join('locales', "#{locale[:locale]}.yml")
|
|
136
|
-
locale[:pluralize] ||= P11n::LOCALE[locale[:locale]]
|
|
137
|
-
dictionary = YAML.safe_load(File.read(locale[:filepath], encoding: 'UTF-8'))
|
|
138
|
-
raise I18nError, %(expected :locale "#{locale[:locale]}" not found in :filepath "#{locale[:filepath].inspect}") \
|
|
139
|
-
unless dictionary.key?(locale[:locale])
|
|
140
|
-
|
|
141
|
-
DATA[locale[:locale]] = [flatten(dictionary[locale[:locale]]), locale[:pluralize]]
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
# Build the default at require time
|
|
145
|
-
build(locale: 'en')
|
|
146
|
-
|
|
147
|
-
public
|
|
148
|
-
|
|
149
|
-
# Public method to configure the locales: overrides the default, build the DATA and freezes it
|
|
150
|
-
def load(*locales)
|
|
151
|
-
DATA.clear
|
|
152
|
-
build(*locales)
|
|
153
|
-
DATA.freeze
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# Translate and pluralize the key with the locale DATA
|
|
157
|
-
def translate(locale, key, opts = {})
|
|
158
|
-
data, pluralize = DATA[locale]
|
|
159
|
-
translation = data[key] || (opts[:count] && data[key += ".#{pluralize.call(opts[:count])}"]) \
|
|
160
|
-
or return %([translation missing: "#{key}"])
|
|
161
|
-
translation.gsub(/%{[^}]+?}/) { |match| opts[:"#{match[2..-2]}"] || match }
|
|
162
|
-
end
|
|
163
|
-
alias t translate
|
|
164
|
-
end
|
|
165
|
-
end
|
data/lib/pagy/url_helpers.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class Pagy
|
|
4
|
-
# Provide the helpers to handle the url in frontend and backend
|
|
5
|
-
module UrlHelpers
|
|
6
|
-
# Return the URL for the page, relying on the params method and Rack by default.
|
|
7
|
-
# It supports all Rack-based frameworks (Sinatra, Padrino, Rails, ...).
|
|
8
|
-
# For non-rack environments you can use the standalone extra
|
|
9
|
-
def pagy_url_for(pagy, page, absolute: false, **_)
|
|
10
|
-
vars = pagy.vars
|
|
11
|
-
request_path = vars[:request_path].to_s.empty? ? request.path : vars[:request_path]
|
|
12
|
-
pagy_params = pagy.params.is_a?(Hash) ? pagy.params.transform_keys(&:to_s) : {}
|
|
13
|
-
params = request.GET.merge(pagy_params)
|
|
14
|
-
pagy_set_query_params(page, vars, params)
|
|
15
|
-
params = pagy.params.call(params) if pagy.params.is_a?(Proc)
|
|
16
|
-
query_string = "?#{Rack::Utils.build_nested_query(params)}"
|
|
17
|
-
"#{request.base_url if absolute}#{request_path}#{query_string}#{vars[:fragment]}"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Add the page and items params
|
|
21
|
-
# Overridable by the jsonapi extra
|
|
22
|
-
def pagy_set_query_params(page, vars, params)
|
|
23
|
-
params[vars[:page_param].to_s] = page
|
|
24
|
-
params[vars[:items_param].to_s] = vars[:items] if vars[:items_extra]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/lib/stylesheets/pagy.css
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
.pagy {
|
|
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
|
-
font-family: sans-serif;
|
|
13
|
-
font-size: 0.875rem;
|
|
14
|
-
line-height: 1.25rem;
|
|
15
|
-
font-weight: 600;
|
|
16
|
-
color: rgb(107 114 128);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.pagy .page.gap {
|
|
20
|
-
/* if you need to customize it */
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.pagy .page a {
|
|
24
|
-
display: block;
|
|
25
|
-
text-decoration: none;
|
|
26
|
-
border-radius: 0.5rem;
|
|
27
|
-
background-color: rgb(229 231 235);
|
|
28
|
-
padding: 0.25rem 0.75rem;
|
|
29
|
-
color: inherit;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.pagy .page a:hover {
|
|
33
|
-
background-color: rgb(209 213 219);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.pagy .page.active a {
|
|
37
|
-
cursor: default;
|
|
38
|
-
background-color: rgb(156 163 175);
|
|
39
|
-
color: rgb(255 255 255);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.pagy .page.disabled a {
|
|
43
|
-
cursor: default;
|
|
44
|
-
background-color: rgb(243 244 246);
|
|
45
|
-
color: rgb(209 213 219);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.pagy .pagy-combo-input, .pagy.pagy-items-selector-js {
|
|
49
|
-
white-space: nowrap;
|
|
50
|
-
display: inline-block;
|
|
51
|
-
border-radius: 0.5rem;
|
|
52
|
-
background-color: rgb(229 231 235);
|
|
53
|
-
padding: 0.125rem 0.75rem;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.pagy .pagy-combo-input input, .pagy.pagy-items-selector-js input {
|
|
57
|
-
line-height: 1.5rem;
|
|
58
|
-
border-radius: 0.375rem;
|
|
59
|
-
border-style: none;
|
|
60
|
-
background-color: rgb(243 244 246);
|
|
61
|
-
}
|
data/lib/stylesheets/pagy.scss
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
.pagy {
|
|
2
|
-
display: flex;
|
|
3
|
-
font-family: sans-serif;
|
|
4
|
-
font-size: 0.875rem;
|
|
5
|
-
line-height: 1.25rem;
|
|
6
|
-
font-weight: 600;
|
|
7
|
-
color: rgb(107 114 128);
|
|
8
|
-
& > :not([hidden]) ~ :not([hidden]) {
|
|
9
|
-
--space-reverse: 0;
|
|
10
|
-
margin-right: calc(0.25rem * var(--space-reverse));
|
|
11
|
-
margin-left: calc(0.25rem * calc(1 - var(--space-reverse)));
|
|
12
|
-
}
|
|
13
|
-
.page {
|
|
14
|
-
a {
|
|
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);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
&.active a {
|
|
26
|
-
cursor: default;
|
|
27
|
-
background-color: rgb(156 163 175);
|
|
28
|
-
color: rgb(255 255 255);
|
|
29
|
-
}
|
|
30
|
-
&.disabled a {
|
|
31
|
-
cursor: default;
|
|
32
|
-
background-color: rgb(243 244 246);
|
|
33
|
-
color: rgb(209 213 219);
|
|
34
|
-
}
|
|
35
|
-
&.gap { } /* if you need to customize it */
|
|
36
|
-
}
|
|
37
|
-
.pagy-combo-input, &.pagy-items-selector-js {
|
|
38
|
-
white-space: nowrap;
|
|
39
|
-
display: inline-block;
|
|
40
|
-
border-radius: 0.5rem;
|
|
41
|
-
background-color: rgb(229 231 235);
|
|
42
|
-
padding: 0.125rem 0.75rem;
|
|
43
|
-
input {
|
|
44
|
-
line-height: 1.5rem;
|
|
45
|
-
border-radius: 0.375rem;
|
|
46
|
-
border-style: none;
|
|
47
|
-
background-color: rgb(243 244 246);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -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
|
-
}
|
|
File without changes
|