effective_bootstrap 1.22.2 → 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: 72dd156fce6da5b624d7ef6e666198def54c289676f1aaf024aea4c11eae7f8f
4
- data.tar.gz: 3f6518cd35b2a1dd28159dcaad798631572b6fd4607e252d79990c468d693e7c
3
+ metadata.gz: f683af3488f235baae5f7eee5f403ade629da5b32763d0ab4c9c80f02cdf6112
4
+ data.tar.gz: 9750a978f0fac5b8f4992fd7cf8393092f3eee6dbf36c8e12d24157ca955696f
5
5
  SHA512:
6
- metadata.gz: ba618d917a6a0a312b40bd93d86ebd28e9022adf7d1cd530a75e6956de1e2cd72010e2f1631654963f1b8675d7f144c574efbe062ad0ad1d239d8d7839262665
7
- data.tar.gz: 32e42a810c099983bfc764bc3d25d94a9c6dfba62c4966d5eeef84140cb84c3a02bb8a2d4a1f1429d7f6faa585300ccba158437b2d6fa2be1f0fb122c935209d
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.
@@ -226,6 +226,7 @@ module Effective
226
226
 
227
227
  obj = (object.class == Class) ? object : object.class
228
228
  return false unless obj.respond_to?(:validators_on)
229
+ return true if required_belongs_to?(obj, name)
229
230
 
230
231
  if name.to_s.ends_with?('_id')
231
232
  return required_presence?(obj, name) || required_presence?(obj, name[0...-3])
@@ -234,6 +235,20 @@ module Effective
234
235
  required_presence?(obj, name)
235
236
  end
236
237
 
238
+ def required_belongs_to?(obj, name)
239
+ return false unless obj.respond_to?(:reflect_on_all_associations)
240
+
241
+ reflection = obj.reflect_on_association(name.to_s.delete_suffix('_id'))
242
+ reflection ||= obj.reflect_on_all_associations(:belongs_to).find do |belongs_to|
243
+ Array(belongs_to.foreign_key).map(&:to_s).include?(name.to_s)
244
+ end
245
+
246
+ return false unless reflection&.macro == :belongs_to
247
+
248
+ optional = reflection.options[:optional]
249
+ optional.nil? ? obj.belongs_to_required_by_default : !optional
250
+ end
251
+
237
252
  def required_presence?(obj, name)
238
253
  obj.validators_on(name).any? do |v|
239
254
  (
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.22.2'.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.22.2
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