pagy 1.3.3 → 2.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/config/pagy.rb +32 -10
- data/lib/javascripts/pagy.js +0 -7
- data/lib/locales/utils/i18n.rb +18 -0
- data/lib/locales/utils/loader.rb +29 -0
- data/lib/locales/{plurals.rb → utils/p11n.rb} +20 -18
- data/lib/pagy.rb +3 -2
- data/lib/pagy/backend.rb +2 -0
- data/lib/pagy/countless.rb +4 -1
- data/lib/pagy/extras/array.rb +2 -0
- data/lib/pagy/extras/bootstrap.rb +12 -14
- data/lib/pagy/extras/bulma.rb +10 -12
- data/lib/pagy/extras/countless.rb +2 -0
- data/lib/pagy/extras/elasticsearch_rails.rb +31 -7
- data/lib/pagy/extras/foundation.rb +11 -13
- data/lib/pagy/extras/i18n.rb +7 -4
- data/lib/pagy/extras/items.rb +16 -17
- data/lib/pagy/extras/materialize.rb +11 -13
- data/lib/pagy/extras/overflow.rb +36 -34
- data/lib/pagy/extras/pagy_search.rb +16 -0
- data/lib/pagy/extras/plain.rb +4 -5
- data/lib/pagy/extras/searchkick.rb +31 -8
- data/lib/pagy/extras/semantic.rb +8 -10
- data/lib/pagy/extras/shared.rb +1 -7
- data/lib/pagy/extras/support.rb +2 -1
- data/lib/pagy/extras/trim.rb +2 -1
- data/lib/pagy/frontend.rb +17 -26
- data/lib/templates/bootstrap_nav.html.erb +1 -1
- data/lib/templates/bootstrap_nav.html.haml +1 -1
- data/lib/templates/bootstrap_nav.html.slim +1 -1
- data/lib/templates/bulma_nav.html.erb +1 -1
- data/lib/templates/bulma_nav.html.haml +1 -1
- data/lib/templates/bulma_nav.html.slim +1 -1
- data/lib/templates/foundation_nav.html.erb +1 -1
- data/lib/templates/foundation_nav.html.haml +1 -1
- data/lib/templates/foundation_nav.html.slim +1 -1
- data/pagy.gemspec +2 -5
- metadata +10 -10
- data/lib/pagy/extras/navs.rb +0 -4
data/lib/pagy/extras/shared.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'json'
|
@@ -39,13 +40,6 @@ class Pagy
|
|
39
40
|
"pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
|
40
41
|
end
|
41
42
|
|
42
|
-
def self.deprecate(old_meth, new_meth)
|
43
|
-
send(:define_method, old_meth) do |pagy, id=pagy_id|
|
44
|
-
Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
|
45
|
-
method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
43
|
end
|
50
44
|
|
51
45
|
end
|
data/lib/pagy/extras/support.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/support
|
2
|
+
# encoding: utf-8
|
2
3
|
# frozen_string_literal: true
|
3
4
|
|
4
5
|
require 'pagy/extras/shared'
|
@@ -6,7 +7,7 @@ require 'pagy/extras/shared'
|
|
6
7
|
class Pagy
|
7
8
|
|
8
9
|
def to_h
|
9
|
-
{ count: @count,
|
10
|
+
{ count: defined?(@count) && @count,
|
10
11
|
page: @page,
|
11
12
|
items: @items,
|
12
13
|
pages: @pages,
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
|
2
|
+
# encoding: utf-8
|
2
3
|
# frozen_string_literal: true
|
3
4
|
|
4
5
|
class Pagy
|
@@ -15,7 +16,7 @@ class Pagy
|
|
15
16
|
page1_url = pagy_trim_url(marker_url, "#{p_vars[:page_param]}=#{MARKER}")
|
16
17
|
page1_link = %(<a href="#{page1_url}" #{p_vars[:link_extra]} #{link_extra})
|
17
18
|
a, b = %(<a href="#{marker_url}" #{p_vars[:link_extra]} #{link_extra}).split(MARKER, 2)
|
18
|
-
|
19
|
+
lambda{|n, text=n, extra=''| start = n.to_i == 1 ? page1_link : "#{a}#{n}#{b}"
|
19
20
|
"#{start}#{ if n == p_prev ; ' rel="prev"'
|
20
21
|
elsif n == p_next ; ' rel="next"'
|
21
22
|
else '' end } #{extra}>#{text}</a>" }
|
data/lib/pagy/frontend.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
1
|
# See Pagy::Frontend API documentation: https://ddnexus.github.io/pagy/api/frontend
|
2
|
+
# encoding: utf-8
|
2
3
|
# frozen_string_literal: true
|
3
4
|
|
4
5
|
require 'yaml'
|
5
6
|
|
6
7
|
class Pagy
|
7
8
|
|
9
|
+
# I18n static hash loaded at startup, used as default alternative to the i18n gem.
|
10
|
+
# see https://ddnexus.github.io/pagy/api/frontend#i18n
|
11
|
+
I18n = eval(Pagy.root.join('locales', 'utils', 'i18n.rb').read) #rubocop:disable Security/Eval
|
12
|
+
|
8
13
|
# All the code here has been optimized for performance: it may not look very pretty
|
9
14
|
# (as most code dealing with many long strings), but its performance makes it very sexy! ;)
|
10
15
|
module Frontend
|
11
16
|
|
17
|
+
# We use EMPTY + 'whatever' that is almost as fast as +'whatever' but is also 1.9 compatible
|
18
|
+
EMPTY = ''
|
19
|
+
|
12
20
|
# Generic pagination: it returns the html with the series of links to the pages
|
13
21
|
def pagy_nav(pagy)
|
14
|
-
|
22
|
+
link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
|
15
23
|
|
16
|
-
html
|
17
|
-
|
24
|
+
html = EMPTY + (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
25
|
+
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
|
18
26
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
19
27
|
html << if item.is_a?(Integer); %(<span class="page">#{link.call item}</span> ) # page link
|
20
28
|
elsif item.is_a?(String) ; %(<span class="page active">#{item}</span> ) # current page
|
@@ -45,34 +53,17 @@ class Pagy
|
|
45
53
|
MARKER = "-pagy-#{'pagy'.hash}-"
|
46
54
|
|
47
55
|
# Returns a performance optimized proc to generate the HTML links
|
48
|
-
# Benchmarked on a 20 link nav: it is ~
|
56
|
+
# Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
|
49
57
|
def pagy_link_proc(pagy, link_extra='')
|
50
58
|
p_prev, p_next = pagy.prev, pagy.next
|
51
59
|
a, b = %(<a href="#{pagy_url_for(MARKER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(MARKER, 2)
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
lambda {|n, text=n, extra=''| "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'
|
61
|
+
elsif n == p_next ; ' rel="next"'
|
62
|
+
else '' end } #{extra}>#{text}</a>" }
|
55
63
|
end
|
56
64
|
|
57
|
-
#
|
58
|
-
def (
|
59
|
-
self[:data] = YAML.load_file(file)[language]
|
60
|
-
self[:plural] = eval(Pagy.root.join('locales', 'plurals.rb').read)[language] #rubocop:disable Security/Eval
|
61
|
-
end; I18N.load
|
62
|
-
|
63
|
-
# Similar to I18n.t for streamlined interpolation and pluralization but without dynamic translation.
|
64
|
-
# It is specialized for Pagy and 5x faster than I18n.t (see https://ddnexus.github.io/pagy/api/frontend#i18n)
|
65
|
-
# See also https://ddnexus.github.io/pagy/extras/i18n if you need to use the standard I18n gem instead
|
66
|
-
def pagy_t(path, vars={})
|
67
|
-
value = I18N[:data].dig(*path.split('.')) or return %(translation missing: "#{path}")
|
68
|
-
if value.is_a?(Hash)
|
69
|
-
vars.key?(:count) or return value
|
70
|
-
plural = I18N[:plural].call(vars[:count])
|
71
|
-
value.key?(plural) or return %(invalid pluralization data: "#{path}" cannot be used with count: #{vars[:count]}; key "#{plural}" is missing.)
|
72
|
-
value = value[plural] or return %(translation missing: "#{path}")
|
73
|
-
end
|
74
|
-
sprintf value, Hash.new{|_,k| "%{#{k}}"}.merge!(vars) # interpolation
|
75
|
-
end
|
65
|
+
# Similar to I18n.t: just ~18x faster using ~10x less memory
|
66
|
+
def pagy_t(path, vars={}) Pagy::I18n.t(@pagy_locale, path, vars) end
|
76
67
|
|
77
68
|
end
|
78
69
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy, 'class="page-link"') -%>
|
9
|
-
<%# -%><nav aria-label="pager" class="pagy-
|
9
|
+
<%# -%><nav aria-label="pager" class="pagy-bootstrap-nav pagination" role="navigation">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
12
|
<% else -%> <li class="page-item prev disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.prev') %></a></li>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy, 'class="page-link"')
|
8
8
|
|
9
|
-
%nav.pagy-
|
9
|
+
%nav.pagy-bootstrap-nav.pagination{"aria-label" => "pager", :role => "navigation"}
|
10
10
|
|
11
11
|
%ul.pagination
|
12
12
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy) -%>
|
9
|
-
<%# -%><nav class="pagy-
|
9
|
+
<%# -%><nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">
|
10
10
|
<% if pagy.prev -%> <%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"') %>
|
11
11
|
<% else -%> <a class="pagination-previous" disabled><%== pagy_t('pagy.nav.prev') %></a>
|
12
12
|
<% end -%>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy)
|
8
8
|
|
9
|
-
%nav.pagy-
|
9
|
+
%nav.pagy-bulma_nav.pagination.is-centered{:role => "navigation", "aria-label" => "pagination"}
|
10
10
|
|
11
11
|
- if pagy.prev
|
12
12
|
!= link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
- link = pagy_link_proc(pagy)
|
8
8
|
|
9
|
-
nav.pagy-
|
9
|
+
nav.pagy-bulma-nav.pagination.is-centered role="navigation" aria-label="pagination"
|
10
10
|
|
11
11
|
- if pagy.prev
|
12
12
|
== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
|
@@ -6,7 +6,7 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy) -%>
|
9
|
-
<%# -%><nav class="pagy-
|
9
|
+
<%# -%><nav class="pagy-foundation-nav" role="navigation" aria-label="Pagination">
|
10
10
|
<%# -%> <ul class="pagination">
|
11
11
|
<% if pagy.prev -%> <li class="prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
12
|
<% else -%> <li class="prev disabled"><%== pagy_t('pagy.nav.prev') %></li>
|
data/pagy.gemspec
CHANGED
@@ -8,12 +8,9 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ['Domizio Demichelis']
|
9
9
|
s.email = ['dd.nexus@gmail.com']
|
10
10
|
s.summary = 'The Ultimate Pagination Ruby Gem'
|
11
|
-
s.description = 'Agnostic pagination in plain ruby: it works with any framework, ORM and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays, JSON data...
|
11
|
+
s.description = 'Agnostic pagination in plain ruby: it works with any framework, ORM and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays, JSON data... Easy, powerful, fast and light.'
|
12
12
|
s.homepage = 'https://github.com/ddnexus/pagy'
|
13
13
|
s.license = 'MIT'
|
14
14
|
s.files = `git ls-files -z`.split("\x0").select{|f| f.start_with?('lib', 'pagy.gemspec', 'LICENSE') }
|
15
|
-
s.required_ruby_version = '>=
|
16
|
-
|
17
|
-
# remove after 1.0
|
18
|
-
s.post_install_message = "Pagy CHANGELOG: https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md"
|
15
|
+
s.required_ruby_version = '>= 1.9' # rubocop:disable Gemspec/RequiredRubyVersion
|
19
16
|
end
|
metadata
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
|
14
14
|
and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
|
15
|
-
JSON data...
|
16
|
-
and very light.'
|
15
|
+
JSON data... Easy, powerful, fast and light.'
|
17
16
|
email:
|
18
17
|
- dd.nexus@gmail.com
|
19
18
|
executables: []
|
@@ -31,10 +30,12 @@ files:
|
|
31
30
|
- lib/locales/ja.yml
|
32
31
|
- lib/locales/nb.yml
|
33
32
|
- lib/locales/nl.yml
|
34
|
-
- lib/locales/plurals.rb
|
35
33
|
- lib/locales/pt-br.yml
|
36
34
|
- lib/locales/ru.yml
|
37
35
|
- lib/locales/tr.yml
|
36
|
+
- lib/locales/utils/i18n.rb
|
37
|
+
- lib/locales/utils/loader.rb
|
38
|
+
- lib/locales/utils/p11n.rb
|
38
39
|
- lib/locales/zh-cn.yml
|
39
40
|
- lib/pagy.rb
|
40
41
|
- lib/pagy/backend.rb
|
@@ -48,8 +49,8 @@ files:
|
|
48
49
|
- lib/pagy/extras/i18n.rb
|
49
50
|
- lib/pagy/extras/items.rb
|
50
51
|
- lib/pagy/extras/materialize.rb
|
51
|
-
- lib/pagy/extras/navs.rb
|
52
52
|
- lib/pagy/extras/overflow.rb
|
53
|
+
- lib/pagy/extras/pagy_search.rb
|
53
54
|
- lib/pagy/extras/plain.rb
|
54
55
|
- lib/pagy/extras/searchkick.rb
|
55
56
|
- lib/pagy/extras/semantic.rb
|
@@ -74,7 +75,7 @@ homepage: https://github.com/ddnexus/pagy
|
|
74
75
|
licenses:
|
75
76
|
- MIT
|
76
77
|
metadata: {}
|
77
|
-
post_install_message:
|
78
|
+
post_install_message:
|
78
79
|
rdoc_options: []
|
79
80
|
require_paths:
|
80
81
|
- lib
|
@@ -82,15 +83,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
83
|
requirements:
|
83
84
|
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
+
version: '1.9'
|
86
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
88
|
requirements:
|
88
89
|
- - ">="
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.7
|
93
|
+
rubygems_version: 3.0.1
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: The Ultimate Pagination Ruby Gem
|
data/lib/pagy/extras/navs.rb
DELETED