rails_bootstrap_form 0.5.3 → 0.6.1
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/CHANGELOG.md +111 -2
- data/Gemfile.lock +9 -3
- data/README.md +68 -0
- data/Rakefile +2 -0
- data/app/assets/stylesheets/rails_bootstrap_form.css +3 -0
- data/demo/app/views/users/_form.html.erb +2 -0
- data/demo/app/views/users/_horizontal_form.html.erb +32 -0
- data/demo/app/views/users/_vertical_form.html.erb +8 -8
- data/demo/config/database.yml +7 -15
- data/demo/db/schema.rb +8 -5
- data/gemfiles/common.gemfile +10 -2
- data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +1 -1
- data/lib/rails_bootstrap_form/bootstrap_form_options.rb +21 -3
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +31 -17
- data/lib/rails_bootstrap_form/{components → helpers}/check_box.rb +10 -3
- data/lib/rails_bootstrap_form/{components → helpers}/errors.rb +1 -1
- data/lib/rails_bootstrap_form/{components → helpers}/help_text.rb +1 -1
- data/lib/rails_bootstrap_form/{components → helpers}/labels.rb +8 -2
- data/lib/rails_bootstrap_form/{components → helpers}/radio_button.rb +10 -3
- data/lib/rails_bootstrap_form/{components → helpers}/required_field.rb +1 -1
- data/lib/rails_bootstrap_form/helpers.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/base.rb +16 -11
- data/lib/rails_bootstrap_form/inputs/check_box.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +41 -0
- data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +39 -0
- data/lib/rails_bootstrap_form/inputs/collection_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/color_field.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/date_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/date_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_local_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/datetime_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/email_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/file_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/hidden_field.rb +19 -0
- data/lib/rails_bootstrap_form/inputs/month_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/number_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/password_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/phone_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/radio_button.rb +45 -0
- data/lib/rails_bootstrap_form/inputs/range_field.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/search_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/static_field.rb +30 -0
- data/lib/rails_bootstrap_form/inputs/telephone_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/text_area.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/text_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_select.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +21 -0
- data/lib/rails_bootstrap_form/inputs/url_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs/week_field.rb +15 -0
- data/lib/rails_bootstrap_form/inputs.rb +62 -209
- data/lib/rails_bootstrap_form/version.rb +1 -1
- data/lib/rails_bootstrap_form.rb +3 -2
- metadata +70 -10
- data/lib/rails_bootstrap_form/components.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34303679b08cf0617516305e5b4e1f21d8c201ffcd9f4cc8eb90f26a587a7f7a
|
4
|
+
data.tar.gz: 4e01e2321eb0318e222e802ce84e8c63648296c50e78de5de9f3c8e14be9570e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f4349d0933eeea1f1965df83eb80ec0fd83392a3a47e2299214a797ec36e5c198e647d727969443779d60910741f91b49f88973a6ebcf6d93a29302f308b46
|
7
|
+
data.tar.gz: adab966d0ca4b8064094e7e941296d95e75e594452384e9cb6e7370ca19fd288a4e9d9cea1e56dbf7981804ef58f9cafc1398d1e0203bb1eefb80004f27ab18d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,114 @@
|
|
1
|
-
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
You can find recent releases with docs in GitHub:
|
4
|
+
|
5
|
+
https://github.com/shivam091/rails_bootstrap_form/releases
|
6
|
+
|
7
|
+
## [0.6.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.0...v0.6.1) - 2023-05-24
|
8
|
+
|
9
|
+
### What's changed
|
10
|
+
- Changes in directory structure
|
11
|
+
- Added test cases
|
12
|
+
- Added README and CHANGELOG
|
13
|
+
|
14
|
+
## [0.6.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.3...v0.6.0) - 2023-05-22
|
15
|
+
|
16
|
+
### What's new
|
17
|
+
- Added support for **`horizontal`** form layout
|
18
|
+
|
19
|
+
## [0.5.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.2...v0.5.3) - 2023-05-21
|
20
|
+
|
21
|
+
### What's changed
|
22
|
+
- Added new option inline to render checkboxes and radio buttons inline
|
23
|
+
|
24
|
+
## [0.5.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.1...v0.5.2) - 2023-05-21
|
25
|
+
|
26
|
+
### What's new
|
27
|
+
- Added option to add custom options to the field's wrapper
|
28
|
+
- Added option to apply user defined CSS class to the field
|
29
|
+
- Added option to control size of input group and field
|
30
|
+
- Added provision to change id of the field and corresponding label
|
31
|
+
|
32
|
+
### What's changed
|
33
|
+
- Added `mb-3` css class to field wrapper if radio buttons or check boxes are not inline
|
34
|
+
|
35
|
+
## [0.5.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.0...v0.5.1) - 2023-05-20
|
36
|
+
|
37
|
+
### What's new
|
38
|
+
- Wrapped `collection_check_boxes` and `collection_radio_buttons` inside field wrapper.
|
39
|
+
|
40
|
+
## [0.5.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.2...v0.5.0) - 2023-05-20
|
41
|
+
|
42
|
+
### What's new
|
43
|
+
- Added wrapper methods for `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` to support Bootstrap 5 form styles
|
44
|
+
|
45
|
+
### What's changed
|
46
|
+
- Replaced HTML tag of help_text component from `<span>` to `<div>`
|
47
|
+
|
48
|
+
## [0.4.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.1...v0.4.2) - 2023-05-16
|
49
|
+
|
50
|
+
### What's new
|
51
|
+
- Added wrapper method for `grouped_collection_select`
|
52
|
+
|
53
|
+
## [0.4.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.0...v0.4.1) - 2023-05-16
|
2
54
|
|
3
|
-
|
55
|
+
### What's fixed
|
56
|
+
- Replaced `reverse_merge` by `deep_merge!` in adding new option values to fix bug causing not to merge options.
|
57
|
+
|
58
|
+
## [0.4.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.1...v0.4.0) - 2023-05-15
|
59
|
+
|
60
|
+
### What's new
|
61
|
+
- Added wrapper methods for `range_field` and `color_field`
|
62
|
+
- Added wrapper methods for `time_zone_select` and `hidden_field`
|
63
|
+
- Added wrapper methods for `date_select`, `time_select`, and `datetime_select`
|
64
|
+
- Added wrapper method to render static control
|
65
|
+
- Added wrapper method for `collection_select`
|
66
|
+
|
67
|
+
## [0.3.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.0...v0.3.1) - 2023-05-15
|
68
|
+
|
69
|
+
### What's fixed
|
70
|
+
- Bug causing fields to wrap in input group even when content to append and prepend is not available.
|
71
|
+
|
72
|
+
## [0.3.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.3...v0.3.0) - 2023-05-15
|
73
|
+
|
74
|
+
### What's new
|
75
|
+
- Added support to wrap field in input group
|
76
|
+
- Added support to display error messages below the field
|
77
|
+
- Added support for floating labels for inputs.
|
78
|
+
|
79
|
+
## [0.2.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.2...v0.2.3) - 2023-05-15
|
80
|
+
|
81
|
+
### What's new
|
82
|
+
- Added component to mark labels as required
|
83
|
+
|
84
|
+
## [0.2.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.1...v0.2.2) - 2023-05-15
|
85
|
+
|
86
|
+
### What's new
|
87
|
+
- Added support to display labels along with the field.
|
88
|
+
|
89
|
+
## [0.2.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.0...v0.2.1) - 2023-05-15
|
90
|
+
|
91
|
+
### What's new
|
92
|
+
- Added FieldWrapperBuilder to create wrapper for placing fields and other related components
|
93
|
+
- Added support to display help text along with the field
|
94
|
+
- Added wrapper methods for simple form fields
|
95
|
+
|
96
|
+
## [0.2.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.1...v0.2.0) - 2023-05-15
|
97
|
+
|
98
|
+
### What's new
|
99
|
+
- Added PORO class `BootstrapFormOptions` to maintain gem specific configuration.
|
100
|
+
- Added BoostrapFormBuilder and extension methods for Rails form builder.
|
101
|
+
- Added required models, controllers, and views in demo application.
|
102
|
+
|
103
|
+
## [0.1.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.0...v0.1.1) - 2023-05-15
|
104
|
+
|
105
|
+
### What's new
|
106
|
+
- Initialized demo application for demonstrating the working.
|
107
|
+
- Added generater to copy initializer file required for maintaining global configuration.
|
108
|
+
- Added Configuration class to maintain configurable options.
|
109
|
+
|
110
|
+
## 0.1.0 - 2023-05-15
|
4
111
|
|
5
112
|
- Initial release
|
113
|
+
|
114
|
+
## [Unreleased]
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_bootstrap_form (0.
|
4
|
+
rails_bootstrap_form (0.6.1)
|
5
|
+
actionpack (~> 7.0)
|
6
|
+
activemodel (~> 7.0)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: http://rubygems.org/
|
@@ -79,6 +81,8 @@ GEM
|
|
79
81
|
sassc-rails (>= 2.0.0)
|
80
82
|
builder (3.2.4)
|
81
83
|
byebug (11.1.3)
|
84
|
+
compare-xml (0.66)
|
85
|
+
nokogiri (~> 1.8)
|
82
86
|
concurrent-ruby (1.2.2)
|
83
87
|
crass (1.0.6)
|
84
88
|
date (3.3.3)
|
@@ -118,6 +122,7 @@ GEM
|
|
118
122
|
nio4r (2.5.9)
|
119
123
|
nokogiri (1.14.4-x86_64-linux)
|
120
124
|
racc (~> 1.4)
|
125
|
+
pg (1.5.3)
|
121
126
|
popper_js (2.11.7)
|
122
127
|
puma (6.2.2)
|
123
128
|
nio4r (~> 2.0)
|
@@ -190,7 +195,6 @@ GEM
|
|
190
195
|
actionpack (>= 5.2)
|
191
196
|
activesupport (>= 5.2)
|
192
197
|
sprockets (>= 3.0.0)
|
193
|
-
sqlite3 (1.6.2-x86_64-linux)
|
194
198
|
thor (1.2.2)
|
195
199
|
tilt (2.1.0)
|
196
200
|
timeout (0.3.2)
|
@@ -207,7 +211,10 @@ PLATFORMS
|
|
207
211
|
DEPENDENCIES
|
208
212
|
bootstrap (~> 5.3.0.alpha3)
|
209
213
|
byebug
|
214
|
+
compare-xml
|
210
215
|
generator_spec
|
216
|
+
nokogiri
|
217
|
+
pg (~> 1.1)
|
211
218
|
puma
|
212
219
|
rails (~> 7.0)
|
213
220
|
rails_bootstrap_form!
|
@@ -216,7 +223,6 @@ DEPENDENCIES
|
|
216
223
|
sassc-rails
|
217
224
|
simplecov
|
218
225
|
sprockets-rails
|
219
|
-
sqlite3 (~> 1.4)
|
220
226
|
|
221
227
|
BUNDLED WITH
|
222
228
|
2.4.10
|
data/README.md
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
# RailsBootstrapForm
|
2
|
+
|
3
|
+
**rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate
|
4
|
+
[Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
|
5
|
+
|
6
|
+
## Minimum Requirements
|
7
|
+
|
8
|
+
* Ruby 3.2.2+ (https://www.ruby-lang.org/en/downloads/branches/)
|
9
|
+
* Rails 7.0+ (https://guides.rubyonrails.org/maintenance_policy.html)
|
10
|
+
* Bootstrap 5.0+ (https://getbootstrap.com/docs/versions/)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application. One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0 application created _without_ the `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "bootstrap", "~> 5.0"
|
18
|
+
```
|
19
|
+
|
20
|
+
And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.
|
21
|
+
|
22
|
+
Add the `rails_bootstrap_form` gem to your `Gemfile`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem "rails_bootstrap_form", "~> 0.6.1"
|
26
|
+
```
|
27
|
+
|
28
|
+
Then:
|
29
|
+
|
30
|
+
`bundle install`
|
31
|
+
|
32
|
+
Depending on which CSS pre-processor you are using, adding the bootstrap form styles differs slightly.
|
33
|
+
If you use Rails in the default mode without any pre-processor, you'll have to add the following line to your `application.css` file:
|
34
|
+
|
35
|
+
```css
|
36
|
+
*= require rails_bootstrap_form
|
37
|
+
```
|
38
|
+
|
39
|
+
If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails), you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:
|
40
|
+
|
41
|
+
```scss
|
42
|
+
@import "rails_bootstrap_form";
|
43
|
+
```
|
44
|
+
|
45
|
+
## Configuration
|
46
|
+
|
47
|
+
`rails_bootstrap_form` can be used without any configuration. However, `rails_bootstrap_form` does have an optional configuration file at `config/initializers/rails_bootstrap_form.rb` for setting options that affect all generated forms in an application. This configuration file is created using the generator
|
48
|
+
by running the command on the terminal.
|
49
|
+
|
50
|
+
```
|
51
|
+
$ rails generate rails_bootstrap_form:install
|
52
|
+
```
|
53
|
+
|
54
|
+
Example:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# config/initializers/rails_bootstrap_form.rb
|
58
|
+
RailsBootstrapForm.configure do |config|
|
59
|
+
# to make forms non-compliant with W3C.
|
60
|
+
config.default_form_attributes = {role: "form", novalidate: true}
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
The current configuration options are:
|
65
|
+
|
66
|
+
| Option | Default value | Description |
|
67
|
+
|---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
68
|
+
| `default_form_attributes` | | Set this option to `{role: "form"}` to make forms non-compliant with W3C, but generate the `role="form"` attribute. |
|
data/Rakefile
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
<div class="card card-primary my-3">
|
2
|
+
<div class="card-header fw-bold">
|
3
|
+
Profile Form (Horizontal layout)
|
4
|
+
</div>
|
5
|
+
<div class="card-body">
|
6
|
+
<%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
|
7
|
+
<%= form.text_field :name, autocomplete: "new-name" %>
|
8
|
+
<%= form.email_field :email, autocomplete: "new-email" %>
|
9
|
+
<%= form.password_field :password, autocomplete: "new-password" %>
|
10
|
+
<%= form.phone_field :mobile_number %>
|
11
|
+
<%= form.date_field :birth_date %>
|
12
|
+
<%= form.range_field :excellence %>
|
13
|
+
<%= form.url_field :blog_url %>
|
14
|
+
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
|
15
|
+
<%= form.color_field :favorite_color %>
|
16
|
+
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
|
17
|
+
<%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %>
|
18
|
+
<%= address_form.text_area :street %>
|
19
|
+
<%= address_form.text_field :state %>
|
20
|
+
<%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
|
21
|
+
<%= address_form.text_field :postal_code %>
|
22
|
+
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
|
23
|
+
{include_blank: "Select Country"} %>
|
24
|
+
<% end %>
|
25
|
+
<%= form.check_box :terms, required: true %>
|
26
|
+
<div class="mt-3">
|
27
|
+
<%= form.submit "Register", class: "btn btn-primary" %>
|
28
|
+
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
</div>
|
@@ -3,26 +3,26 @@
|
|
3
3
|
Profile Form (Vertical layout)
|
4
4
|
</div>
|
5
5
|
<div class="card-body">
|
6
|
-
<%= bootstrap_form_for @user
|
7
|
-
<%= form.text_field :name, autocomplete: "new-name"
|
8
|
-
<%= form.
|
9
|
-
<%= form.
|
6
|
+
<%= bootstrap_form_for @user do |form| %>
|
7
|
+
<%= form.text_field :name, autocomplete: "new-name" %>
|
8
|
+
<%= form.email_field :email, autocomplete: "new-email" %>
|
9
|
+
<%= form.password_field :password, autocomplete: "new-password" %>
|
10
10
|
<%= form.phone_field :mobile_number %>
|
11
11
|
<%= form.date_field :birth_date %>
|
12
|
-
<%= form.check_box :terms, bootstrap_form: {switch: false}, required: true %>
|
13
12
|
<%= form.range_field :excellence %>
|
14
13
|
<%= form.url_field :blog_url %>
|
15
|
-
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {
|
14
|
+
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
|
16
15
|
<%= form.color_field :favorite_color %>
|
17
|
-
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name
|
16
|
+
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
|
18
17
|
<%= form.fields_for :address, include_id: false do |address_form| %>
|
19
18
|
<%= address_form.text_area :street %>
|
20
19
|
<%= address_form.text_field :state %>
|
21
20
|
<%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
|
22
21
|
<%= address_form.text_field :postal_code %>
|
23
22
|
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
|
24
|
-
{include_blank: "Select Country"
|
23
|
+
{include_blank: "Select Country"} %>
|
25
24
|
<% end %>
|
25
|
+
<%= form.check_box :terms, required: true %>
|
26
26
|
<div class="mt-3">
|
27
27
|
<%= form.submit "Register", class: "btn btn-primary" %>
|
28
28
|
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
|
data/demo/config/database.yml
CHANGED
@@ -1,25 +1,17 @@
|
|
1
|
-
# SQLite. Versions 3.8.0 and up are supported.
|
2
|
-
# gem install sqlite3
|
3
|
-
#
|
4
|
-
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
-
# gem "sqlite3"
|
6
|
-
#
|
7
1
|
default: &default
|
8
|
-
adapter:
|
9
|
-
|
10
|
-
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: unicode
|
4
|
+
reconnect: false
|
5
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 20 } %>
|
11
6
|
|
12
7
|
development:
|
13
8
|
<<: *default
|
14
|
-
|
9
|
+
url: <%= ENV["DATABASE_URL"] %>
|
15
10
|
|
16
|
-
# Warning: The database defined as "test" will be erased and
|
17
|
-
# re-generated from your development database when you run "rake".
|
18
|
-
# Do not set this db to the same as development or production.
|
19
11
|
test:
|
20
12
|
<<: *default
|
21
|
-
|
13
|
+
url: <%= ENV["DATABASE_URL"] %>
|
22
14
|
|
23
15
|
production:
|
24
16
|
<<: *default
|
25
|
-
|
17
|
+
url: <%= ENV["DATABASE_URL"] %>
|
data/demo/db/schema.rb
CHANGED
@@ -11,8 +11,11 @@
|
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
13
|
ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
|
14
|
+
# These are extensions that must be enabled in order to support this database
|
15
|
+
enable_extension "plpgsql"
|
16
|
+
|
14
17
|
create_table "addresses", primary_key: "user_id", force: :cascade do |t|
|
15
|
-
t.
|
18
|
+
t.bigint "country_id"
|
16
19
|
t.string "street"
|
17
20
|
t.string "city"
|
18
21
|
t.string "state"
|
@@ -25,7 +28,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
|
|
25
28
|
|
26
29
|
create_table "cities", force: :cascade do |t|
|
27
30
|
t.string "name"
|
28
|
-
t.
|
31
|
+
t.bigint "country_id"
|
29
32
|
t.datetime "created_at", null: false
|
30
33
|
t.datetime "updated_at", null: false
|
31
34
|
t.index ["country_id"], name: "index_cities_on_country_id"
|
@@ -50,8 +53,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
|
|
50
53
|
end
|
51
54
|
|
52
55
|
create_table "user_skills", force: :cascade do |t|
|
53
|
-
t.
|
54
|
-
t.
|
56
|
+
t.bigint "user_id"
|
57
|
+
t.bigint "skill_id"
|
55
58
|
t.datetime "created_at", null: false
|
56
59
|
t.datetime "updated_at", null: false
|
57
60
|
t.index ["skill_id"], name: "index_user_skills_on_skill_id"
|
@@ -65,7 +68,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
|
|
65
68
|
t.string "mobile_number"
|
66
69
|
t.string "blog_url"
|
67
70
|
t.date "birth_date"
|
68
|
-
t.
|
71
|
+
t.bigint "fruit_id"
|
69
72
|
t.boolean "terms"
|
70
73
|
t.string "excellence"
|
71
74
|
t.string "favorite_color"
|
data/gemfiles/common.gemfile
CHANGED
@@ -15,8 +15,8 @@ gem "sassc-rails"
|
|
15
15
|
# Add bootstrap support
|
16
16
|
gem "bootstrap", "~> 5.3.0.alpha3"
|
17
17
|
|
18
|
-
# Use
|
19
|
-
gem "
|
18
|
+
# Use postgresql as the database for Active Record
|
19
|
+
gem "pg", "~> 1.1"
|
20
20
|
|
21
21
|
# Library to show coverage of the code.
|
22
22
|
gem "simplecov"
|
@@ -25,6 +25,14 @@ group :development do
|
|
25
25
|
gem "puma"
|
26
26
|
end
|
27
27
|
|
28
|
+
group :test do
|
29
|
+
# make it easy and painless to work with XML and HTML from Ruby.
|
30
|
+
gem "nokogiri"
|
31
|
+
|
32
|
+
# Solve your XML/HTML comparison or diffing needs.
|
33
|
+
gem "compare-xml"
|
34
|
+
end
|
35
|
+
|
28
36
|
group :development, :test do
|
29
37
|
gem "byebug"
|
30
38
|
end
|
@@ -6,7 +6,7 @@ module RailsBootstrapForm
|
|
6
6
|
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
|
7
7
|
|
8
8
|
include RailsBootstrapForm::FieldWrapperBuilder
|
9
|
-
include RailsBootstrapForm::
|
9
|
+
include RailsBootstrapForm::Helpers
|
10
10
|
include RailsBootstrapForm::InputGroupBuilder
|
11
11
|
include RailsBootstrapForm::Inputs
|
12
12
|
|
@@ -50,8 +50,9 @@ module RailsBootstrapForm
|
|
50
50
|
# readers. Default is `visually-hidden`
|
51
51
|
attr_accessor :hide_class
|
52
52
|
|
53
|
-
# Default CSS class that will be applied to all label tags
|
54
|
-
#
|
53
|
+
# Default CSS class that will be applied to all label tags when layout is
|
54
|
+
# vertical.
|
55
|
+
# The default value is `form-label`.
|
55
56
|
attr_accessor :label_class
|
56
57
|
|
57
58
|
# An additional CSS class that will be added along with the existing
|
@@ -105,6 +106,19 @@ module RailsBootstrapForm
|
|
105
106
|
# form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap_form: {inline: true}
|
106
107
|
attr_accessor :inline
|
107
108
|
|
109
|
+
# Default CSS class that will be applied to all label tags when layout is
|
110
|
+
# horizontal.
|
111
|
+
# The default value is `col-form-label`.
|
112
|
+
attr_accessor :label_col_class
|
113
|
+
|
114
|
+
# Default CSS class for label column when using horizontal form.
|
115
|
+
# The default value is `col-sm-2`.
|
116
|
+
attr_accessor :label_col_wrapper_class
|
117
|
+
|
118
|
+
# Default CSS class for control column when using horizontal form.
|
119
|
+
# The default value is `col-sm-10`.
|
120
|
+
attr_accessor :field_col_wrapper_class
|
121
|
+
|
108
122
|
def initialize(options = {})
|
109
123
|
set_defaults
|
110
124
|
set_bootstrap_form_options(options)
|
@@ -131,7 +145,7 @@ module RailsBootstrapForm
|
|
131
145
|
# to a given form field. For example, we can change grid just for one field:
|
132
146
|
#
|
133
147
|
# bootstrap_form_with model: @user do |f|
|
134
|
-
# f.text_field :email, bootstrap_form: {
|
148
|
+
# f.text_field :email, bootstrap_form: {label_col_wrapper_class: "col-md-6", field_col_wrapper_class: "col-md-6"}
|
135
149
|
# f.password_field :password
|
136
150
|
# end
|
137
151
|
#
|
@@ -173,6 +187,10 @@ module RailsBootstrapForm
|
|
173
187
|
@size = nil
|
174
188
|
|
175
189
|
@inline = false
|
190
|
+
|
191
|
+
@label_col_class = "col-form-label"
|
192
|
+
@label_col_wrapper_class = "col-sm-2"
|
193
|
+
@field_col_wrapper_class = "col-sm-10"
|
176
194
|
end
|
177
195
|
|
178
196
|
private :set_defaults
|
@@ -16,35 +16,49 @@ module RailsBootstrapForm
|
|
16
16
|
label = draw_label(attribute, options, bootstrap_options)
|
17
17
|
help_text = help_text(attribute, bootstrap_options)
|
18
18
|
|
19
|
-
if bootstrap_options.
|
19
|
+
if bootstrap_options.layout_horizontal?
|
20
20
|
tag.div(**field_wrapper_options(bootstrap_options)) do
|
21
|
-
concat(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
21
|
+
concat(label)
|
22
|
+
concat(tag.div(class: bootstrap_options.field_col_wrapper_class) do
|
23
|
+
concat(input_group_wrapper(attribute, bootstrap_options) do
|
24
|
+
capture(&block)
|
25
|
+
end)
|
26
|
+
concat(help_text)
|
26
27
|
end)
|
27
|
-
concat(help_text)
|
28
28
|
end
|
29
29
|
else
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
if bootstrap_options.floating
|
31
|
+
tag.div(**field_wrapper_options(bootstrap_options)) do
|
32
|
+
concat(input_group_wrapper(attribute, bootstrap_options) do
|
33
|
+
tag.div(class: floating_label_classes(attribute)) do
|
34
|
+
concat(capture(&block))
|
35
|
+
concat(label)
|
36
|
+
end
|
37
|
+
end)
|
38
|
+
concat(help_text)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
tag.div(**field_wrapper_options(bootstrap_options)) do
|
42
|
+
concat(label)
|
43
|
+
concat(input_group_wrapper(attribute, bootstrap_options) do
|
44
|
+
capture(&block)
|
45
|
+
end)
|
46
|
+
concat(help_text)
|
47
|
+
end
|
36
48
|
end
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
40
52
|
def field_wrapper_options(bootstrap_options)
|
41
53
|
{}.tap do |option|
|
42
|
-
option[:class] = field_wrapper_classes
|
54
|
+
option[:class] = field_wrapper_classes(bootstrap_options)
|
43
55
|
end.merge(bootstrap_options.wrapper_options)
|
44
56
|
end
|
45
57
|
|
46
|
-
def field_wrapper_classes
|
47
|
-
classes = [
|
58
|
+
def field_wrapper_classes(bootstrap_options)
|
59
|
+
classes = []
|
60
|
+
classes << "row" if bootstrap_options.layout_horizontal?
|
61
|
+
classes << form_wrapper_default_class
|
48
62
|
classes.flatten.compact
|
49
63
|
end
|
50
64
|
|
@@ -68,7 +82,7 @@ module RailsBootstrapForm
|
|
68
82
|
css_options[:class] = field_classes.flatten.compact
|
69
83
|
css_options.merge!(required_field_options(attribute, options))
|
70
84
|
|
71
|
-
if bootstrap_options.floating
|
85
|
+
if (bootstrap_options.floating && !bootstrap_options.layout_horizontal?)
|
72
86
|
css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
|
73
87
|
end
|
74
88
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
module RailsBootstrapForm
|
6
|
-
module
|
6
|
+
module Helpers
|
7
7
|
module CheckBox
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
@@ -62,11 +62,18 @@ module RailsBootstrapForm
|
|
62
62
|
classes = Array("form-check")
|
63
63
|
classes << "form-switch" if bootstrap_options.switch
|
64
64
|
classes << "form-check-inline" if bootstrap_options.inline?
|
65
|
-
classes << "mb-3"
|
65
|
+
classes << "mb-3" unless (bootstrap_options.layout_horizontal? || bootstrap_options.inline?)
|
66
66
|
classes.flatten.compact
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
def check_box_container_classes(bootstrap_options)
|
70
|
+
classes = Array(bootstrap_options.field_col_wrapper_class)
|
71
|
+
classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
|
72
|
+
classes.flatten.compact
|
73
|
+
end
|
74
|
+
|
75
|
+
private :check_box_label, :check_box_classes, :check_box_label_class,
|
76
|
+
:check_box_wrapper_class, :check_box_container_classes
|
70
77
|
end
|
71
78
|
end
|
72
79
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
module RailsBootstrapForm
|
6
|
-
module
|
6
|
+
module Helpers
|
7
7
|
module Labels
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
@@ -21,7 +21,13 @@ module RailsBootstrapForm
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def label_classes(attribute, bootstrap_options)
|
24
|
-
classes = [
|
24
|
+
classes = []
|
25
|
+
classes << if bootstrap_options.layout_horizontal?
|
26
|
+
[bootstrap_options.label_col_class, bootstrap_options.label_col_wrapper_class]
|
27
|
+
else
|
28
|
+
bootstrap_options.label_class
|
29
|
+
end
|
30
|
+
classes << bootstrap_options.additional_label_class
|
25
31
|
classes << bootstrap_options.hide_class if bootstrap_options.hide_label
|
26
32
|
classes << "required" if is_attribute_required?(attribute)
|
27
33
|
classes << "is-invalid" if is_invalid?(attribute)
|