pagy 2.0.1 → 2.1.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 +10 -3
- data/lib/locales/zh-hk.yml +20 -0
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +6 -1
- data/lib/pagy/extras/headers.rb +38 -0
- data/lib/pagy/extras/overflow.rb +2 -0
- data/lib/pagy/extras/searchkick.rb +6 -1
- data/lib/pagy/frontend.rb +13 -9
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231b1787febd199766fff19ee9e1f8a25b9ba94e92491f9899ea91b98cad82c3
|
4
|
+
data.tar.gz: 94c21814452385052d0a1ed3085074e1cc69c60534a9525d66946e3f556d32a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206e2c4afb1398260ab713f2d85b6628c1594af65a857455b491c27788367b2a90f1f9eb9b943a2f4fcf6355f928d4228f36e76229e77cd75b9611c80a93c81a
|
7
|
+
data.tar.gz: d2690104a7de7e789600837504bed1f7f8d227d395d8a57c39cd51b3fc0ad3ed44522d0ee4211c29da1bc04603f36ce2116312e87afefe327b49dd75eec16d63
|
data/lib/config/pagy.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
# Pagy initializer file
|
5
5
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
6
|
+
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
7
|
|
7
8
|
|
8
9
|
# Extras
|
@@ -64,6 +65,11 @@
|
|
64
65
|
|
65
66
|
# Feature Extras
|
66
67
|
|
68
|
+
# Headers extra: http response headers (and other helpers) useful for API pagination
|
69
|
+
# See http://ddnexus.github.io/pagy/extras/headers
|
70
|
+
# require 'pagy/extras/headers'
|
71
|
+
# Pagy::VARS[:headers] = { items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' } # default
|
72
|
+
|
67
73
|
# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination
|
68
74
|
# See https://ddnexus.github.io/pagy/extras/support
|
69
75
|
# require 'pagy/extras/support'
|
@@ -77,7 +83,7 @@
|
|
77
83
|
# Overflow extra: Allow for easy handling of overflowing pages
|
78
84
|
# See https://ddnexus.github.io/pagy/extras/overflow
|
79
85
|
# require 'pagy/extras/overflow'
|
80
|
-
# Pagy::VARS[:overflow] = :
|
86
|
+
# Pagy::VARS[:overflow] = :empty_page # default (other options: :last_page and :exception)
|
81
87
|
|
82
88
|
# Trim extra: Remove the page=1 param from links
|
83
89
|
# See https://ddnexus.github.io/pagy/extras/trim
|
@@ -117,7 +123,8 @@
|
|
117
123
|
|
118
124
|
# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
|
119
125
|
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
120
|
-
# Notice: No need to
|
126
|
+
# Notice: No need to configure anything in this section if your app uses only "en"
|
127
|
+
# or if you use the i18n extra below
|
121
128
|
#
|
122
129
|
# Examples:
|
123
130
|
# load the "de" built-in locale:
|
@@ -133,7 +140,7 @@
|
|
133
140
|
# {locale: 'es'})
|
134
141
|
#
|
135
142
|
# load the "en" built-in locale, a custom "es" locale,
|
136
|
-
# and a totally custom locale complete with
|
143
|
+
# and a totally custom locale complete with a custom :pluralize proc:
|
137
144
|
# (the first passed :locale will be used also as the default_locale)
|
138
145
|
# Pagy::I18n.load({locale: 'en'},
|
139
146
|
# {locale: 'es', filepath: 'path/to/pagy-es.yml'},
|
@@ -0,0 +1,20 @@
|
|
1
|
+
zh-hk:
|
2
|
+
pagy:
|
3
|
+
nav:
|
4
|
+
prev: "‹ 上一頁"
|
5
|
+
next: "下一頁 ›"
|
6
|
+
gap: "…"
|
7
|
+
info:
|
8
|
+
single_page:
|
9
|
+
zero: "%{item_name}未搵到"
|
10
|
+
one: "顯示 <b>1</b> %{item_name}"
|
11
|
+
other: "顯示<b>所有 %{count}</b> %{item_name}"
|
12
|
+
multiple_pages: "共 <b>%{count}</b> %{item_name},顯示 <b>%{from}-%{to}</b>"
|
13
|
+
item_name:
|
14
|
+
zero: "記錄"
|
15
|
+
one: ""
|
16
|
+
other: ""
|
17
|
+
compact: "第 %{page_input} / %{pages} 頁"
|
18
|
+
items:
|
19
|
+
one: "每頁顯示 %{items_input} 記錄"
|
20
|
+
other: "每頁顯示 %{items_input} 記錄"
|
data/lib/pagy.rb
CHANGED
@@ -28,7 +28,12 @@ class Pagy
|
|
28
28
|
options[:from] = vars[:items] * (vars[:page] - 1)
|
29
29
|
response = model.search(query_or_payload, options)
|
30
30
|
vars[:count] = response.raw_response['hits']['total']
|
31
|
-
|
31
|
+
pagy = Pagy.new(vars)
|
32
|
+
# with :last_page overflow we need to re-run the method in order to get the hits
|
33
|
+
if defined?(OVERFLOW) && pagy.overflow? && pagy.vars[:overflow] == :last_page
|
34
|
+
return pagy_elasticsearch_rails(search_args, vars.merge(page: pagy.page))
|
35
|
+
end
|
36
|
+
return pagy, called.empty? ? response : response.send(*called)
|
32
37
|
end
|
33
38
|
|
34
39
|
# Sub-method called only by #pagy_elasticsearch_rails: here for easy customization of variables by overriding
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/headers
|
2
|
+
# encoding: utf-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
class Pagy
|
6
|
+
# Add specialized backend methods to add pagination response headers
|
7
|
+
module Backend ; private
|
8
|
+
|
9
|
+
VARS[:headers] = { items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' }
|
10
|
+
|
11
|
+
include Helpers
|
12
|
+
|
13
|
+
def pagy_headers_merge(pagy)
|
14
|
+
response.headers.merge!(pagy_headers(pagy))
|
15
|
+
end
|
16
|
+
|
17
|
+
def pagy_headers(pagy)
|
18
|
+
hash = pagy_headers_hash(pagy)
|
19
|
+
hash['Link'] = hash['Link'].map{|rel, link| %(<#{link}>; rel="#{rel}")}.join(', ')
|
20
|
+
hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def pagy_headers_hash(pagy)
|
24
|
+
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
|
25
|
+
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }; rels['last'] = pagy.last unless countless
|
26
|
+
url_str = pagy_url_for(Frontend::MARKER, pagy, :url)
|
27
|
+
hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(Frontend::MARKER, n.to_s)] if n}.compact] }
|
28
|
+
headers = pagy.vars[:headers]
|
29
|
+
hash[headers[:items]] = pagy.vars[:items] if headers[:items]
|
30
|
+
unless countless
|
31
|
+
hash[headers[:pages]] = pagy.pages if headers[:pages]
|
32
|
+
hash[headers[:count]] = pagy.count if headers[:count]
|
33
|
+
end
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -28,7 +28,12 @@ class Pagy
|
|
28
28
|
options[:page] = vars[:page]
|
29
29
|
results = model.search(term, options, &block)
|
30
30
|
vars[:count] = results.total_count
|
31
|
-
|
31
|
+
pagy = Pagy.new(vars)
|
32
|
+
# with :last_page overflow we need to re-run the method in order to get the hits
|
33
|
+
if defined?(OVERFLOW) && pagy.overflow? && pagy.vars[:overflow] == :last_page
|
34
|
+
return pagy_searchkick(search_args, vars.merge(page: pagy.page))
|
35
|
+
end
|
36
|
+
return pagy, called.empty? ? results : results.send(*called)
|
32
37
|
end
|
33
38
|
|
34
39
|
# Sub-method called only by #pagy_searchkick: here for easy customization of variables by overriding
|
data/lib/pagy/frontend.rb
CHANGED
@@ -10,10 +10,23 @@ class Pagy
|
|
10
10
|
# see https://ddnexus.github.io/pagy/api/frontend#i18n
|
11
11
|
I18n = eval(Pagy.root.join('locales', 'utils', 'i18n.rb').read) #rubocop:disable Security/Eval
|
12
12
|
|
13
|
+
module Helpers
|
14
|
+
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
15
|
+
def pagy_url_for(page, pagy, path_or_url=:path)
|
16
|
+
p_vars = pagy.vars; params = request.GET; params[p_vars[:page_param].to_s] = page; params.merge!(p_vars[:params])
|
17
|
+
"#{request.send(path_or_url)}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
|
21
|
+
def pagy_get_params(params) params end
|
22
|
+
end
|
23
|
+
|
13
24
|
# All the code here has been optimized for performance: it may not look very pretty
|
14
25
|
# (as most code dealing with many long strings), but its performance makes it very sexy! ;)
|
15
26
|
module Frontend
|
16
27
|
|
28
|
+
include Helpers
|
29
|
+
|
17
30
|
# We use EMPTY + 'whatever' that is almost as fast as +'whatever' but is also 1.9 compatible
|
18
31
|
EMPTY = ''
|
19
32
|
|
@@ -41,15 +54,6 @@ class Pagy
|
|
41
54
|
pagy_t(path, item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
|
42
55
|
end
|
43
56
|
|
44
|
-
# This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
|
45
|
-
def pagy_url_for(page, pagy)
|
46
|
-
p_vars = pagy.vars; params = request.GET.merge(p_vars[:page_param].to_s => page).merge!(p_vars[:params])
|
47
|
-
"#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
|
51
|
-
def pagy_get_params(params) params end
|
52
|
-
|
53
57
|
MARKER = "-pagy-#{'pagy'.hash}-"
|
54
58
|
|
55
59
|
# Returns a performance optimized proc to generate the HTML links
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.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-03-
|
11
|
+
date: 2019-03-12 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,
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/locales/utils/loader.rb
|
38
38
|
- lib/locales/utils/p11n.rb
|
39
39
|
- lib/locales/zh-cn.yml
|
40
|
+
- lib/locales/zh-hk.yml
|
40
41
|
- lib/pagy.rb
|
41
42
|
- lib/pagy/backend.rb
|
42
43
|
- lib/pagy/countless.rb
|
@@ -46,6 +47,7 @@ files:
|
|
46
47
|
- lib/pagy/extras/countless.rb
|
47
48
|
- lib/pagy/extras/elasticsearch_rails.rb
|
48
49
|
- lib/pagy/extras/foundation.rb
|
50
|
+
- lib/pagy/extras/headers.rb
|
49
51
|
- lib/pagy/extras/i18n.rb
|
50
52
|
- lib/pagy/extras/items.rb
|
51
53
|
- lib/pagy/extras/materialize.rb
|