pagy 0.4.1 → 0.4.2
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/pagy.rb +6 -6
- data/lib/pagy/backend.rb +2 -1
- data/lib/pagy/frontend.rb +7 -4
- data/lib/templates/bootstrap.html.erb +20 -24
- data/lib/templates/bootstrap.html.slim +3 -3
- data/lib/templates/default.html.erb +19 -23
- data/lib/templates/default.html.haml +3 -3
- data/lib/templates/default.html.slim +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60384daf0fd49d4815f49d4ab0bf65840835bb42f7c9c38979fae883f9e0c4c5
|
4
|
+
data.tar.gz: 4aaa58eba02a590254ecf82d80f750aa4cd0b3bf7da1d745f92d8a7125c19fc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3006bd929cce65f58b5d0fd4c512e791fc939de6661055359c918f035f981645ce705d3d5e02f55aa7c43816d309000ee10991c54b89144768f986f6e6f18c0d
|
7
|
+
data.tar.gz: 4ad8a43b6138a671e84e074155e60f80713cd68a41f71fab6ac69d5a88bc5a48fbac0b49cb0a9b50e6c15b416c72373ceafe01e9bc841f9fe2b72965deb9dfaa
|
data/lib/pagy.rb
CHANGED
@@ -7,7 +7,7 @@ require 'ostruct'
|
|
7
7
|
# Notice that it doesn't actually do any pagination, nor navigation... that is
|
8
8
|
# done with a few helpers in the Pagy::Backend and Pagy::Frontend modules.
|
9
9
|
|
10
|
-
class Pagy ; VERSION = '0.4.
|
10
|
+
class Pagy ; VERSION = '0.4.2'
|
11
11
|
|
12
12
|
autoload :Backend, 'pagy/backend'
|
13
13
|
autoload :Frontend, 'pagy/frontend'
|
@@ -39,8 +39,8 @@ class Pagy ; VERSION = '0.4.1'
|
|
39
39
|
@pages = @last = [(@count.to_f / @limit).ceil, 1].max # cardinal and ordinal meanings
|
40
40
|
(1..@last).cover?(@page) || raise(OutOfRangeError, "expected :page in 1..#{@last}; got #{@page.inspect}")
|
41
41
|
@offset += @limit * (@page - 1) # initial offset + offset for pagination
|
42
|
-
@limit = @count % @limit if @page == @last # adjust limit for last page (for pre-limit(ed)
|
43
|
-
@from = @count
|
42
|
+
@limit = @count % @limit if @page == @last # adjust limit for last page (for pre-limit(ed) collections)
|
43
|
+
@from = @count == 0 ? 0 : @offset+1 # page begins from item
|
44
44
|
@to = @offset + @limit # page ends to item
|
45
45
|
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
46
46
|
@next = (@page+1 unless @page == @last) # nil if no next page
|
@@ -49,9 +49,9 @@ class Pagy ; VERSION = '0.4.1'
|
|
49
49
|
around = ([@page-@before, 1].max .. [@page+@after, @last].min).to_a # before..after pages
|
50
50
|
row = (all.first(@initial+1) | around | all.last(@final+1)).sort # row of pages with boundaries
|
51
51
|
row.each_cons(2) do |a, b| # loop in consecutive pairs
|
52
|
-
if a+1 == b; @series.push(a)
|
53
|
-
elsif a+2 == b; @series.push(a, a+1)
|
54
|
-
else
|
52
|
+
if a+1 == b ; @series.push(a) # no gap -> no additions
|
53
|
+
elsif a+2 == b ; @series.push(a, a+1) # 1 page gap -> fill with missing page
|
54
|
+
else @series.push(a, :gap) # n page gap -> add :gap
|
55
55
|
end # skip the end-boundary (last+1)
|
56
56
|
end
|
57
57
|
@series.shift # remove the start-boundary (0)
|
data/lib/pagy/backend.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Pagy
|
2
|
+
|
2
3
|
# Including this module (usually in your controller) is handy but totally optional.
|
3
4
|
# It basically just encapsulates a couple of verbose statements in one single slick
|
4
5
|
# #pagy method, but it does not add any functionality on its own.
|
@@ -15,7 +16,7 @@ class Pagy
|
|
15
16
|
# return pagy, scope.offset(pagy.offset).limit(pagy.limit)
|
16
17
|
# end
|
17
18
|
|
18
|
-
module Backend ; private # the whole module is private so no problem including it in a controller
|
19
|
+
module Backend ; private # the whole module is private so no problem with including it in a controller
|
19
20
|
|
20
21
|
def pagy(obj, opts={})
|
21
22
|
pagy = Pagy.new(count: pagy_get_count(obj), page: pagy_get_page, i18n_key: pagy_get_i18n_key(obj), **opts)
|
data/lib/pagy/frontend.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
class Pagy
|
3
|
+
|
3
4
|
# This module supplies a few methods to deal with the navigation aspect of the pagination.
|
4
5
|
# You will usually include it in some helper module, eventually overriding the #pagy_url_for
|
5
6
|
# in order to fit its behavior with your app needs (e.g.: removing and adding some param or
|
@@ -67,6 +68,7 @@ class Pagy
|
|
67
68
|
url << '?' << Rack::Utils.build_nested_query(params)
|
68
69
|
end
|
69
70
|
|
71
|
+
|
70
72
|
# The :pagy_t method is the internal implementation of I18n.t, used when I18n is missing or
|
71
73
|
# not needed (for example when your application is a single-locale app, e.g. only 'en', or only 'fr'...).
|
72
74
|
#
|
@@ -100,8 +102,9 @@ class Pagy
|
|
100
102
|
sprintf value, Hash.new{|h,k| "%{#{k}}"}.merge!(vars) # interpolation
|
101
103
|
end
|
102
104
|
|
105
|
+
|
103
106
|
# NOTICE: This method is used internally, so you need to know about it only if you
|
104
|
-
# are going to override a *_nav helper or a template AND
|
107
|
+
# are going to override a *_nav helper or a template AND change the link tags.
|
105
108
|
#
|
106
109
|
# You call this method in order to get a proc that you will call to produce the page links.
|
107
110
|
# The reasaon it is a 2 step process instead of a single method call is performance.
|
@@ -153,9 +156,9 @@ class Pagy
|
|
153
156
|
def pagy_link_proc(pagy, lx=''.freeze) # link extra
|
154
157
|
p_prev, p_next, p_lx = pagy.prev, pagy.next, pagy.opts[:link_extra]
|
155
158
|
a, b = %(<a href="#{pagy_url_for(MARKER)}"#{p_lx ? %( #{p_lx}) : ''.freeze}#{lx.empty? ? lx : %( #{lx})}).split(MARKER)
|
156
|
-
-> (n, text=n, x=''.freeze) { "#{a}#{n}#{b}#{ if n == p_prev; ' rel="prev"'.freeze
|
157
|
-
elsif n == p_next; ' rel="next"'.freeze
|
158
|
-
else
|
159
|
+
-> (n, text=n, x=''.freeze) { "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'.freeze
|
160
|
+
elsif n == p_next ; ' rel="next"'.freeze
|
161
|
+
else ''.freeze
|
159
162
|
end }#{x.empty? ? x : %( #{x})}>#{text}</a>" }
|
160
163
|
end
|
161
164
|
|
@@ -6,27 +6,23 @@
|
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
7
|
-%>
|
8
8
|
<% link = pagy_link_proc(pagy, 'class="page-link"') -%>
|
9
|
-
|
10
|
-
<ul class="pagination">
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
<li class="page-item next disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.next') %></a></li>
|
30
|
-
<% end -%>
|
31
|
-
</ul>
|
32
|
-
</nav>
|
9
|
+
<%# -%><nav aria-label="pager" class="pagination" role="navigation">
|
10
|
+
<%# -%> <ul class="pagination">
|
11
|
+
<% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
|
12
|
+
<% else -%> <li class="page-item prev disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.prev') %></a></li>
|
13
|
+
<% end -%>
|
14
|
+
<% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%>
|
15
|
+
<% case item
|
16
|
+
when Integer -%>
|
17
|
+
<%# -%> <li class="page-item"><%== link.call(item) %></li>
|
18
|
+
<% when String -%>
|
19
|
+
<%# -%> <li class="page-item active"><%== link.call(item) %></li>
|
20
|
+
<% when :gap -%>
|
21
|
+
<%# -%> <li class="page-item disabled gap"><a href="#" class="page-link"><%== pagy_t('pagy.nav.gap') %></a></li>
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
<% if pagy.next -%> <li class="page-item next"><%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') %></li>
|
25
|
+
<% else -%> <li class="page-item next disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.next') %></a></li>
|
26
|
+
<% end -%>
|
27
|
+
<%# -%> </ul>
|
28
|
+
<%# -%></nav>
|
@@ -19,13 +19,13 @@ nav.pagination role="navigation" aria-label="pager"
|
|
19
19
|
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
20
20
|
- case item
|
21
21
|
|
22
|
-
- when Integer
|
22
|
+
- when Integer # page link
|
23
23
|
li.page-item == link.call(item)
|
24
24
|
|
25
|
-
- when String
|
25
|
+
- when String # current page
|
26
26
|
li.page-item.active == link.call(item)
|
27
27
|
|
28
|
-
- when :gap
|
28
|
+
- when :gap # page gap
|
29
29
|
li.page-item.disabled.gap
|
30
30
|
a.page-link href="#" == pagy_t('pagy.nav.gap')
|
31
31
|
|
@@ -4,27 +4,23 @@
|
|
4
4
|
|
5
5
|
The link variable is set to a proc that returns the link tag.
|
6
6
|
Usage: link.call( page_number [, text [, extra_attributes_string ]])
|
7
|
-
|
7
|
+
-%>
|
8
8
|
<% link = pagy_link_proc(pagy) -%>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
<% else -%>
|
28
|
-
<span class="page next disabled"><%== pagy_t('pagy.nav.next') %></span>
|
29
|
-
<% end -%>
|
30
|
-
</nav>
|
9
|
+
<%# -%><nav aria-label="pager" class="pagination" role="navigation">
|
10
|
+
<% if pagy.prev -%> <span class="page prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></span>
|
11
|
+
<% else -%> <span class="page prev disabled"><%== pagy_t('pagy.nav.prev') %></span>
|
12
|
+
<% end -%>
|
13
|
+
<% pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] -%>
|
14
|
+
<% case item
|
15
|
+
when Integer -%>
|
16
|
+
<%# -%> <span class="page"><%== link.call(item) %></span>
|
17
|
+
<% when String -%>
|
18
|
+
<%# -%> <span class="page current"><%= item %></span>
|
19
|
+
<% when :gap -%>
|
20
|
+
<%# -%> <span class="page gap"><%== pagy_t('pagy.nav.gap') %></span>
|
21
|
+
<% end -%>
|
22
|
+
<% end -%>
|
23
|
+
<% if pagy.next -%> <span class="page next"><%== link.call(pagy.next, pagy_t('pagy.nav.next'), 'aria-label="next"') %></span>
|
24
|
+
<% else -%> <span class="page next disabled"><%== pagy_t('pagy.nav.next') %></span>
|
25
|
+
<% end -%>
|
26
|
+
<%# -%></nav>
|
@@ -16,14 +16,14 @@
|
|
16
16
|
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
17
|
- case item
|
18
18
|
|
19
|
-
- when Integer
|
19
|
+
- when Integer # page link
|
20
20
|
%span.page
|
21
21
|
!= link.call(item)
|
22
22
|
|
23
|
-
- when String
|
23
|
+
- when String # current page
|
24
24
|
%span.page.current= item
|
25
25
|
|
26
|
-
- when :gap
|
26
|
+
- when :gap # page gap
|
27
27
|
%span.page.gap!= pagy_t('pagy.nav.gap')
|
28
28
|
|
29
29
|
- if pagy.next
|
@@ -15,13 +15,13 @@ nav.pagination role="navigation" aria-label="pager"
|
|
15
15
|
|
16
16
|
- pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
17
|
- case item
|
18
|
-
- when Integer
|
18
|
+
- when Integer # page link
|
19
19
|
span.page ==> link.call(item)
|
20
20
|
|
21
|
-
- when String
|
21
|
+
- when String # current page
|
22
22
|
span.page.current ==> item
|
23
23
|
|
24
|
-
- when :gap
|
24
|
+
- when :gap # page gap
|
25
25
|
span.page.gap ==> pagy_t('pagy.nav.gap')
|
26
26
|
|
27
27
|
- if pagy.next
|
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: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|