effective_bootstrap 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1aa3384fb3e09bfd5b1f7f14d03ca6e60ff3ee366252274f3ecb4f41b4779a6
4
- data.tar.gz: 4c59087f46a59835461df12bf436e81a002627765f1242c402861c03f5885d90
3
+ metadata.gz: b4522b40a141a3ea3b72005b21e9f2dfc69c4ac0098fb9fcae41582f0f273278
4
+ data.tar.gz: eaa49061b18dadb536b6bc1a738a4605b7271320e27e78d109901cd98dfdfe3b
5
5
  SHA512:
6
- metadata.gz: f5cfd9ee7e3e46bb6303c2d387d06758c32e275d51f69fb56f1b6839e41c88911ff661c9d8273482fe1b68fcb2fbaf7de0a1c8ddb6d34ddaeafcfd1ff312b573
7
- data.tar.gz: 968230fcf3f09272b941f84707451398741d3654e293d5fbbafac619815106210b08b71eb47cf071c921dd4cd033233194b16dc796e6019b0ae4fedd4b2b73f5
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, count: nil, window: 2)
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
- count ||= collection.limit(nil).offset(nil).count # You can pass the total count, or not.
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 = (count.to_f / per_page).ceil
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
- 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))
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 left.include?(page + 1)
238
+ if last <= (length + 2)
238
239
  left = left - right
239
- middle = []
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
- elsif middle.include?(page)
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
- (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) },
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.6.5'.freeze
2
+ VERSION = '0.6.6'.freeze
3
3
  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.5
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-29 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails