effective_bootstrap 0.6.5 → 0.6.6
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/app/helpers/effective_bootstrap_helper.rb +19 -20
- data/lib/effective_bootstrap/version.rb +1 -1
- 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: b4522b40a141a3ea3b72005b21e9f2dfc69c4ac0098fb9fcae41582f0f273278
|
4
|
+
data.tar.gz: eaa49061b18dadb536b6bc1a738a4605b7271320e27e78d109901cd98dfdfe3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a502e5e55ec541dd7376735fe9dc32f0bee314e3f9e7a7b0f60f66aa1287eb4fc5ea874ff750dc8f6738a44ef204394bb123bdcd39fca450edc0f220cb61384
|
7
|
+
data.tar.gz: 4ca777f00efe441d239f4c1cef3679a6b9052593ca5622d032ffe764d9130679f5f7725f400aeef8356e96ded6781e3c600ac892c6e5ac81c47bf4b94cc09a63
|
@@ -197,15 +197,15 @@ 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, window: 2, collection_count: nil, render_single_page: false)
|
201
201
|
raise 'expected an ActiveRecord::Relation' unless collection.respond_to?(:limit) && collection.respond_to?(:offset)
|
202
202
|
|
203
|
-
|
203
|
+
collection_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
|
-
last = (
|
206
|
+
last = (collection_count.to_f / per_page).ceil
|
207
207
|
|
208
|
-
return unless last > 1 # If there's only 1 page, don't render a pagination at all.
|
208
|
+
return unless (last > 1 || render_single_page) # If there's only 1 page, don't render a pagination at all.
|
209
209
|
|
210
210
|
# Build URL
|
211
211
|
uri = URI(url || request.fullpath)
|
@@ -230,36 +230,35 @@ module EffectiveBootstrapHelper
|
|
230
230
|
end
|
231
231
|
|
232
232
|
# Calculate Windows
|
233
|
-
|
234
|
-
|
235
|
-
right = 1.upto(last).to_a.last(
|
233
|
+
length = 1 + (window * 2)
|
234
|
+
left = 1.upto(last).to_a.first(length)
|
235
|
+
right = 1.upto(last).to_a.last(length)
|
236
|
+
center = []
|
236
237
|
|
237
|
-
if
|
238
|
+
if last <= (length + 2)
|
238
239
|
left = left - right
|
239
|
-
|
240
|
+
right = right - left
|
241
|
+
elsif left.include?(page + 1)
|
240
242
|
right = [last]
|
243
|
+
left = left - right
|
241
244
|
elsif right.include?(page - 1)
|
242
245
|
left = [1]
|
243
|
-
middle = []
|
244
246
|
right = right - left
|
245
|
-
|
247
|
+
else
|
246
248
|
left = [1]
|
247
|
-
middle = middle - left - right
|
248
249
|
right = [last]
|
250
|
+
center = (page - window + 1).upto(page + window - 1).to_a
|
249
251
|
end
|
250
252
|
|
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
253
|
# Render the pagination
|
255
254
|
content_tag(:ul, class: 'pagination') do
|
256
255
|
[
|
257
256
|
prev_tag,
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
257
|
+
left.map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
258
|
+
(dots_tag if last > length && left == [1]),
|
259
|
+
center.map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
260
|
+
(dots_tag if last > length && right == [last]),
|
261
|
+
right.map { |index| bootstrap_paginate_tag(index, page, url, params) },
|
263
262
|
next_tag
|
264
263
|
].flatten.join.html_safe
|
265
264
|
end
|
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.6
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|