effective_bootstrap 0.6.4 → 0.6.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1aa3384fb3e09bfd5b1f7f14d03ca6e60ff3ee366252274f3ecb4f41b4779a6
|
4
|
+
data.tar.gz: 4c59087f46a59835461df12bf436e81a002627765f1242c402861c03f5885d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5cfd9ee7e3e46bb6303c2d387d06758c32e275d51f69fb56f1b6839e41c88911ff661c9d8273482fe1b68fcb2fbaf7de0a1c8ddb6d34ddaeafcfd1ff312b573
|
7
|
+
data.tar.gz: 968230fcf3f09272b941f84707451398741d3654e293d5fbbafac619815106210b08b71eb47cf071c921dd4cd033233194b16dc796e6019b0ae4fedd4b2b73f5
|
@@ -197,35 +197,77 @@ module EffectiveBootstrapHelper
|
|
197
197
|
# Add this to your view
|
198
198
|
# %nav= paginate(@posts, per_page: 10)
|
199
199
|
#
|
200
|
-
def bootstrap_paginate(collection, per_page:, url: nil)
|
200
|
+
def bootstrap_paginate(collection, per_page:, url: nil, count: nil, window: 2)
|
201
201
|
raise 'expected an ActiveRecord::Relation' unless collection.respond_to?(:limit) && collection.respond_to?(:offset)
|
202
202
|
|
203
|
-
count
|
203
|
+
count ||= collection.limit(nil).offset(nil).count # You can pass the total count, or not.
|
204
204
|
|
205
205
|
page = (params[:page] || 1).to_i
|
206
206
|
last = (count.to_f / per_page).ceil
|
207
207
|
|
208
208
|
return unless last > 1 # If there's only 1 page, don't render a pagination at all.
|
209
209
|
|
210
|
+
# Build URL
|
210
211
|
uri = URI(url || request.fullpath)
|
211
212
|
params = Rack::Utils.parse_nested_query(uri.query)
|
212
213
|
url = uri.path + '?'
|
213
214
|
|
215
|
+
# Pagination Tags
|
216
|
+
prev_tag = content_tag(:li, class: ['page-item', ('disabled' if page <= 1)].compact.join(' ')) do
|
217
|
+
link_to(content_tag(:span, 'Previous'.html_safe), (page <= 1 ? '#' : url + params.merge('page' => page - 1).to_query),
|
218
|
+
class: 'page-link', 'aria-label': 'Previous', title: 'Previous', 'aria-disabled': ('true' if page <= 1), 'tabindex': ('-1' if page <= 1)
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
next_tag = content_tag(:li, class: ['page-item', ('disabled' if page >= last)].compact.join(' ')) do
|
223
|
+
link_to(content_tag(:span, 'Next'.html_safe), (page >= last ? '#' : url + params.merge('page' => page + 1).to_query),
|
224
|
+
class: 'page-link', 'aria-label': 'Next', title: 'Next', 'aria-disabled': ('true' if page >= last), 'tabindex': ('-1' if page >= last)
|
225
|
+
)
|
226
|
+
end
|
227
|
+
|
228
|
+
dots_tag = content_tag(:li, class: 'page-item disabled') do
|
229
|
+
link_to('...', '#', class: 'page-link', 'aria-label': '...', 'aria-disabled': true, tabindex: '-1')
|
230
|
+
end
|
231
|
+
|
232
|
+
# Calculate Windows
|
233
|
+
left = 1.upto(last).to_a.first(1 + (window * 2))
|
234
|
+
middle = ([1, 1 + page - window].max).upto([page + window - 1, last].min).to_a
|
235
|
+
right = 1.upto(last).to_a.last(1 + (window * 2))
|
236
|
+
|
237
|
+
if left.include?(page + 1)
|
238
|
+
left = left - right
|
239
|
+
middle = []
|
240
|
+
right = [last]
|
241
|
+
elsif right.include?(page - 1)
|
242
|
+
left = [1]
|
243
|
+
middle = []
|
244
|
+
right = right - left
|
245
|
+
elsif middle.include?(page)
|
246
|
+
left = [1]
|
247
|
+
middle = middle - left - right
|
248
|
+
right = [last]
|
249
|
+
end
|
250
|
+
|
251
|
+
left_dots = (dots_tag if left == [1] && last > (window * 2 + 1))
|
252
|
+
right_dots = (dots_tag if right == [last] && last > (window * 2 + 1))
|
253
|
+
|
254
|
+
# Render the pagination
|
214
255
|
content_tag(:ul, class: 'pagination') do
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
256
|
+
[
|
257
|
+
prev_tag,
|
258
|
+
(left || []).map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
259
|
+
left_dots,
|
260
|
+
(middle || []).compact.map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
261
|
+
right_dots,
|
262
|
+
(right || []).map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
263
|
+
next_tag
|
264
|
+
].flatten.join.html_safe
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def bootstrap_paginate_tag(index, page, url, params)
|
269
|
+
content_tag(:li, class: ['page-item', ('active' if index == page)].compact.join(' '), title: "Page #{index}") do
|
270
|
+
link_to(index, (url + params.merge('page' => index).to_query), class: 'page-link')
|
229
271
|
end
|
230
272
|
end
|
231
273
|
|
@@ -14,9 +14,9 @@ module EffectiveFormBuilderHelper
|
|
14
14
|
end
|
15
15
|
|
16
16
|
options[:class] = [
|
17
|
-
options[:class],
|
18
|
-
'needs-validation',
|
19
|
-
('form-inline' if options[:layout] == :inline),
|
17
|
+
options[:class],
|
18
|
+
'needs-validation',
|
19
|
+
('form-inline' if options[:layout] == :inline),
|
20
20
|
('with-errors' if subject.respond_to?(:errors) && subject.errors.present?)
|
21
21
|
].compact.join(' ')
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|