effective_bootstrap 1.23.0 → 1.24.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8525fb430647548ed163f61aacb3d1a5a582cbb6e5bf7182d2c69374cd4e5082
4
- data.tar.gz: b5ba63ca4c4162696b289599106c8476ac3d1eceb557eff451b707ac4b9aa608
3
+ metadata.gz: f683af3488f235baae5f7eee5f403ade629da5b32763d0ab4c9c80f02cdf6112
4
+ data.tar.gz: 9750a978f0fac5b8f4992fd7cf8393092f3eee6dbf36c8e12d24157ca955696f
5
5
  SHA512:
6
- metadata.gz: 9763f0b4a0e4a728d9601dcd9872fcd4ff921b7e6f55f31387a6a5be1c5fa2a0b6aac561c9b0d6203d83667455232804acb49342576cb1068e767d6c026ea598
7
- data.tar.gz: 3dbec9987fc1bfaba4130ad9b4668cd5e1f462d0fd12ee5307d2a7dd4c2d45bf4ea4ee6faa9c21089fffb800428b52b526f6511b780ee3dff8ec4acb8050c9fc
6
+ metadata.gz: 52baeedf313df51b034f5f250ea1fbe637cd81525808473ec4cb515dff29f5545a28a44da823b2f6f1f0555fa9180bcee0064fc5bbd31d10981a5519eefa4bdf
7
+ data.tar.gz: bc935d0336edc537416f74e2d9361d1373c1d346fd69b4f2ba00e1ade6504605a66d41b5a1a9eae91fa8c3867af50b00fd11519efd972dcc536b51381293ec0d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Effective Bootstrap
2
2
 
3
- Everything your Ruby on Rails 5.1+ application needs to get working with [Twitter Bootstrap 4](https://getbootstrap.com/).
3
+ Everything your Ruby on Rails 7.0+ application needs to get working with [Twitter Bootstrap 4](https://getbootstrap.com/).
4
4
 
5
5
  - Bootstrap4 component view helpers.
6
6
  - SVG icons based on [Inline SVG](https://github.com/jamesmartin/inline_svg), with [Feather Icons](https://feathericons.com) and [FontAwesome](https://fontawesome.com) svg icons to replace the old glyphicons.
@@ -124,6 +124,8 @@ Builds a pagination based on the given collection, current url and params[:page]
124
124
 
125
125
  The collection must be an ActiveRecord relation.
126
126
 
127
+ Requests for an invalid page or a page beyond the collection raise `ActiveRecord::RecordNotFound` and return HTTP 404.
128
+
127
129
  ```haml
128
130
  = paginate(@posts, per_page: 10)
129
131
  ```
@@ -132,8 +134,8 @@ Add this to your model:
132
134
 
133
135
  ```ruby
134
136
  scope :paginate, -> (page: nil, per_page:) {
135
- page = (page || 1).to_i
136
- offset = [(page - 1), 0].max * per_page
137
+ page = EffectiveResources.normalize_page(page) || 1
138
+ offset = (page - 1) * per_page
137
139
 
138
140
  limit(per_page).offset(offset)
139
141
  }
@@ -623,7 +625,7 @@ class Select2AjaxController < ApplicationController
623
625
 
624
626
  # Paginate
625
627
  per_page = 20
626
- page = (params[:page] || 1).to_i
628
+ page = EffectiveResources.normalize_page(params[:page]) || 1
627
629
  last = (collection.reselect(:id).count.to_f / per_page).ceil
628
630
  more = page < last
629
631
 
@@ -492,13 +492,14 @@ module EffectiveBootstrapHelper
492
492
  #
493
493
  # https://getbootstrap.com/docs/4.0/components/pagination/
494
494
  # Builds a pagination based on the given collection, current url and params[:page]
495
+ # Raises ActiveRecord::RecordNotFound when the requested page is invalid or exceeds the collection.
495
496
  #
496
497
  # = paginate(@posts, per_page: 10)
497
498
  #
498
499
  # Add this to your model
499
500
  # scope :paginate, -> (page: nil, per_page: 10) {
500
- # page = (page || 1).to_i
501
- # offset = [(page - 1), 0].max * per_page
501
+ # page = EffectiveResources.normalize_page(page) || 1
502
+ # offset = (page - 1) * per_page
502
503
 
503
504
  # limit(per_page).offset(offset)
504
505
  # }
@@ -514,7 +515,11 @@ module EffectiveBootstrapHelper
514
515
 
515
516
  collection_count ||= collection.limit(nil).offset(nil).count # You can pass the total count, or not.
516
517
 
517
- page = (params[:page] || 1).to_i
518
+ page = EffectiveResources.validate_page!(
519
+ params[:page],
520
+ collection_count: collection_count,
521
+ per_page: per_page
522
+ )
518
523
  last = (collection_count.to_f / per_page).ceil
519
524
 
520
525
  return unless (last > 1 || render_single_page) # If there's only 1 page, don't render a pagination at all.
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.23.0'.freeze
2
+ VERSION = '1.24.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.0
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 4.0.0
18
+ version: 7.0.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 4.0.0
25
+ version: 7.0.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bootstrap
28
28
  requirement: !ruby/object:Gem::Requirement