smart_pagination 0.1.0 → 0.2.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/smart_pagination/helper.rb +9 -0
- data/lib/smart_pagination/renderer.rb +48 -3
- data/lib/smart_pagination/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f29d971452750acea3f9548fb9db34b667c6f7e9
|
4
|
+
data.tar.gz: 8d3f5f61fed10007efd7e610b9ad39edd6edf711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d2781df39f31e3aaa6545950e5419e955f8ff9d68ce43662edeaddd10482646e68f89ebed13d767d3997232d66d6bb8817e81481aea81ee912cdbb2fb8a8384
|
7
|
+
data.tar.gz: 9011741512d6112cc6dc55f50027edfee3cb00a21d345963fef0b51148bfc88b2f2d5732f972bf5e986d33798949baa176d2c9025963fbd3fcb2f9fbef56f358
|
@@ -16,5 +16,14 @@ module SmartPagination
|
|
16
16
|
|
17
17
|
# Alias helper method
|
18
18
|
alias :pager_for :smart_pager_for
|
19
|
+
|
20
|
+
# Render pagination info text
|
21
|
+
def smart_pagination_info_for(collection, options={})
|
22
|
+
options = options.merge(info_mode: true)
|
23
|
+
SmartPagination::Renderer.new(self, collection, options).render
|
24
|
+
end
|
25
|
+
|
26
|
+
# Alias helper method
|
27
|
+
alias :pagination_info_for :smart_pagination_info_for
|
19
28
|
end
|
20
29
|
end
|
@@ -9,7 +9,13 @@ module SmartPagination
|
|
9
9
|
|
10
10
|
# Render pagination links
|
11
11
|
def render
|
12
|
-
|
12
|
+
if info_mode?
|
13
|
+
pagination_info
|
14
|
+
elsif pager_mode?
|
15
|
+
pager
|
16
|
+
else
|
17
|
+
pagination
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
private
|
@@ -17,6 +23,7 @@ module SmartPagination
|
|
17
23
|
# Default options
|
18
24
|
def default_options
|
19
25
|
{
|
26
|
+
info_mode: false,
|
20
27
|
pager_mode: false,
|
21
28
|
item_class: '',
|
22
29
|
previous_text: '«',
|
@@ -33,6 +40,15 @@ module SmartPagination
|
|
33
40
|
}
|
34
41
|
end
|
35
42
|
|
43
|
+
# Get collection name
|
44
|
+
def collection_name
|
45
|
+
if @collection.is_a? ActiveRecord::Relation
|
46
|
+
@collection.model_name.human(count: total_entries)
|
47
|
+
else
|
48
|
+
total_entries == 1 ? 'Item' : 'Items'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
# Get current_page
|
37
53
|
def current_page
|
38
54
|
@collection.current_page.to_i
|
@@ -40,7 +56,7 @@ module SmartPagination
|
|
40
56
|
|
41
57
|
# Get total pages
|
42
58
|
def total_pages
|
43
|
-
@total_pages ||= @collection.total_pages
|
59
|
+
@total_pages ||= @collection.total_pages.to_i
|
44
60
|
end
|
45
61
|
|
46
62
|
# Check if current page
|
@@ -48,11 +64,32 @@ module SmartPagination
|
|
48
64
|
page.to_i == current_page
|
49
65
|
end
|
50
66
|
|
67
|
+
# Get entries per page
|
68
|
+
def per_page
|
69
|
+
@collection.per_page.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get current entries
|
73
|
+
def current_entries
|
74
|
+
entries = current_page * per_page
|
75
|
+
entries < total_entries ? entries : total_entries
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get total entries
|
79
|
+
def total_entries
|
80
|
+
@total_entries ||= @collection.total_entries.to_i
|
81
|
+
end
|
82
|
+
|
51
83
|
# Check if pager mode enabled
|
52
84
|
def pager_mode?
|
53
85
|
@options[:pager_mode].present?
|
54
86
|
end
|
55
87
|
|
88
|
+
# Check if info mode enabled
|
89
|
+
def info_mode?
|
90
|
+
@options[:info_mode].present?
|
91
|
+
end
|
92
|
+
|
56
93
|
# Get page numbers
|
57
94
|
def page_numbers
|
58
95
|
inner = @options[:inner_window].to_i
|
@@ -149,7 +186,7 @@ module SmartPagination
|
|
149
186
|
|
150
187
|
# Render link tag
|
151
188
|
def link_to(text, params={}, html_options={})
|
152
|
-
url = @context.url_for params.merge(per_page:
|
189
|
+
url = @context.url_for params.merge(per_page: per_page)
|
153
190
|
opt = html_options.to_h
|
154
191
|
|
155
192
|
opt.merge!(href: url) if params[:page].present?
|
@@ -166,6 +203,14 @@ module SmartPagination
|
|
166
203
|
wrap_tag
|
167
204
|
end
|
168
205
|
|
206
|
+
# Render pagination info
|
207
|
+
def pagination_info
|
208
|
+
current = tag :strong, current_entries, class: 'current'
|
209
|
+
total = tag :strong, total_entries, class: 'total'
|
210
|
+
|
211
|
+
"Displaying #{current} of #{total} #{collection_name}".html_safe
|
212
|
+
end
|
213
|
+
|
169
214
|
# Render pager
|
170
215
|
def pager
|
171
216
|
items = [previous_link, next_link]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_paginate
|