rails_bootstrap_form 0.9.4 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile.lock +5 -1
  4. data/README.md +67 -7
  5. data/demo/app/assets/config/manifest.js +1 -0
  6. data/demo/app/assets/stylesheets/actiontext.scss +36 -0
  7. data/demo/app/assets/stylesheets/application.scss +2 -1
  8. data/demo/app/controllers/users_controller.rb +1 -0
  9. data/demo/app/javascript/application.js +2 -0
  10. data/demo/app/models/address.rb +1 -1
  11. data/demo/app/models/user.rb +4 -0
  12. data/demo/app/views/active_storage/blobs/_blob.html.erb +14 -0
  13. data/demo/app/views/layouts/action_text/contents/_content.html.erb +3 -0
  14. data/demo/app/views/layouts/application.html.erb +1 -0
  15. data/demo/app/views/users/_horizontal_form.html.erb +2 -0
  16. data/demo/app/views/users/_vertical_form.html.erb +2 -0
  17. data/demo/bin/importmap +7 -0
  18. data/demo/config/environment.rb +2 -0
  19. data/demo/config/importmap.rb +7 -0
  20. data/demo/config/locales/en.rb +2 -0
  21. data/demo/db/migrate/20230621041641_create_active_storage_tables.active_storage.rb +61 -0
  22. data/demo/db/migrate/20230621041642_create_action_text_tables.action_text.rb +30 -0
  23. data/demo/db/schema.rb +41 -1
  24. data/gemfiles/common.gemfile +3 -0
  25. data/lib/rails_bootstrap_form/bootstrap_form_options.rb +10 -2
  26. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +1 -1
  27. data/lib/rails_bootstrap_form/helpers/errors.rb +7 -8
  28. data/lib/rails_bootstrap_form/inputs/base.rb +6 -3
  29. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +4 -1
  30. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +2 -1
  31. data/lib/rails_bootstrap_form/inputs/collection_select.rb +2 -2
  32. data/lib/rails_bootstrap_form/inputs/color_field.rb +3 -7
  33. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +2 -2
  34. data/lib/rails_bootstrap_form/inputs/range_field.rb +3 -2
  35. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +2 -2
  36. data/lib/rails_bootstrap_form/inputs/select.rb +2 -2
  37. data/lib/rails_bootstrap_form/inputs/static_field.rb +10 -12
  38. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +2 -2
  39. data/lib/rails_bootstrap_form/inputs/weekday_select.rb +2 -2
  40. data/lib/rails_bootstrap_form/version.rb +1 -1
  41. data/lib/rails_bootstrap_form.rb +1 -0
  42. metadata +10 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c769ec63a2b3c1a8abaeaa8f8a8d11f7b473e71c69d7eb4fda3a4d200b9106e7
4
- data.tar.gz: a477abf8d26482d15d9eb6a1a4dae62be453823def408d9958961945d81cfe97
3
+ metadata.gz: c71affc7b54a85ee1b7d1515c5124e1c337470bb1ccb16bb22b82b9f56342d84
4
+ data.tar.gz: dc88fb2396c94e92cb9516f1b65ba8e03c1e768f1c337241a74177227d7c497a
5
5
  SHA512:
6
- metadata.gz: 6394304b9d69627c1032d8392a6cb586964f9dce3e0d948aeaf0854303ae222f26f9a357e4df40f41c4f42e4d381140d27cf3cb65b2d1582c2a0f8400895be72
7
- data.tar.gz: fb8f1d8a37574de977551917b2e0b1577c2240d6443f48e7ac9d65fff3ca97939eaea6c97f54e88eb5d1322aed18c4336b4d6f440594b8089372d5185013ef6d
6
+ metadata.gz: 20e03576472e57b9d643eaa6b433a0cddb7e219271d14978de48b1175ce9b06422442240c9027719061b4e499b48a080010a9bca9deeb4bba34b013675bf7e91
7
+ data.tar.gz: b0038b7c98be63e6b97a2b256aa2a733d30241349f534312ec2222e40923824bf5c4e765d8946965ca03198640e4b41dc9ed02c05738522aca6f78b651cedf59
data/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ You can find recent releases with docs in GitHub:
4
4
 
5
5
  https://github.com/shivam091/rails_bootstrap_form/releases
6
6
 
7
+ ## [0.9.6](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.5...v0.9.6) - 2023-06-25
8
+
9
+ ### What's new
10
+
11
+ - Integrated `importmap` and `actiontext` in demo application for demonstrating implementation of `rich_text_area`.
12
+ - Added spec examples for `date_field`, `datetime_field`, `datetime_local_field`, `datetime_select`, `email_field`,
13
+ `file_field`, `hidden_field`, `month_field`, `number_field`, `password_field`, `phone_field`, `search_field`,
14
+ `telephone_field`, `text_area`, `time_field`, `time_select`, `url_field`, and `week_field` helpers.
15
+
16
+ ## [0.9.5](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.4...v0.9.5) - 2023-06-21
17
+
18
+ ### What's changed
19
+
20
+ - Changed default value of `field_class` option to `nil`.
21
+
22
+ ### What's fixed
23
+
24
+ - Fixed static field options to accept bootstrap options ([#45](https://github.com/shivam091/rails_bootstrap_form/issues/45))
25
+ - Changes to allow overriding of field_class at form and field level ([#44](https://github.com/shivam091/rails_bootstrap_form/issues/44))
26
+ - Fixed bug causing class attribute in select list to not get added to field ([#46](https://github.com/shivam091/rails_bootstrap_form/issues/46))
27
+
7
28
  ## [0.9.4](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.3...v0.9.4) - 2023-06-17
8
29
 
9
30
  ### What's new
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.9.4)
4
+ rails_bootstrap_form (0.9.6)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
@@ -98,6 +98,9 @@ GEM
98
98
  activesupport (>= 5.0)
99
99
  i18n (1.13.0)
100
100
  concurrent-ruby (~> 1.0)
101
+ importmap-rails (1.2.1)
102
+ actionpack (>= 6.0.0)
103
+ railties (>= 6.0.0)
101
104
  loofah (2.21.2)
102
105
  crass (~> 1.0.2)
103
106
  nokogiri (>= 1.12.0)
@@ -213,6 +216,7 @@ DEPENDENCIES
213
216
  byebug
214
217
  compare-xml
215
218
  generator_spec
219
+ importmap-rails (~> 1.2)
216
220
  nokogiri
217
221
  pg (~> 1.1)
218
222
  puma
data/README.md CHANGED
@@ -28,7 +28,7 @@ for setting up `application.scss` and `application.js`.
28
28
  Add the `rails_bootstrap_form` gem to your `Gemfile`:
29
29
 
30
30
  ```ruby
31
- gem "rails_bootstrap_form", "~> 0.9.4"
31
+ gem "rails_bootstrap_form", "~> 0.9.6"
32
32
  ```
33
33
 
34
34
  Then:
@@ -154,13 +154,13 @@ This generates the following HTML:
154
154
 
155
155
  ## Bootstrap Configuration Options
156
156
 
157
- Here's a list of all possible options you can pass via `bootstrap` option that can be attached to the `bootstrap_form_for` or `bootstrap_form_with` or any field helpers inside of it:
157
+ Here's a list of all possible options you can pass via `bootstrap` option that can be attached to the `bootstrap_form_for`, `bootstrap_form_with`, `fields_for`, or any field helpers inside of it:
158
158
 
159
159
  | Option | Description | Default value |
160
160
  | ------ | ------------- | ----------- |
161
161
  | `disabled` | An option to disable **rails_bootstrap_form** helpers. Default rails form builder element is rendered when set to `true` | `false` |
162
162
  | `layout` | Controls layout of form and field helpers. It can be `vertical` `horizontal`, or `inline`. | `vertical` |
163
- | `field_class` | A CSS class that will be applied to all form fields. | `form-control` |
163
+ | `field_class` | A CSS class that will be applied to all form fields. | `nil` |
164
164
  | `help_text` | Describes help text for the HTML field. Help text is automatically read from translation file. If you want to customize it, you can pass a string. You can also set it `false` if you do not want help text displayed. | `nil` |
165
165
  | `label_text` | An option to customize automatically generated label text. | `nil` |
166
166
  | `skip_label` | An option to control whether the label is to be displayed or not. | `false` |
@@ -176,7 +176,7 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
176
176
  | `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
177
177
  | `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. You can set it false if you don't the field to be rendered in a wrapper. | `{}` |
178
178
  | `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
179
- | `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
179
+ | `inline` | An option to group checkboxes and radio buttons on the same horizontal row. If form layout is `inline`, this option doesn't get considered. | `false` |
180
180
  | `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
181
181
  | `label_col_wrapper_class` | A CSS class for label column when layout is `horizontal`. | `col-sm-2` |
182
182
  | `field_col_wrapper_class` | A CSS class for field column when layout is `horizontal`. | `col-sm-10` |
@@ -322,7 +322,7 @@ time_field time_select time_zone_select
322
322
  url_field week_field weekday_select
323
323
  ```
324
324
 
325
- ## Supported form layouts
325
+ ## Supported Form Layouts
326
326
 
327
327
  ### Vertical Layout
328
328
 
@@ -1030,6 +1030,8 @@ This generates the following HTML:
1030
1030
  </form>
1031
1031
  ```
1032
1032
 
1033
+ Options specified at the field level take precedence over those specified at the fields_for level, which take precedence over those specified at the form level.
1034
+
1033
1035
  ### file_field
1034
1036
 
1035
1037
  Our `file_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-file_field).
@@ -1190,6 +1192,64 @@ This generates the following HTML:
1190
1192
  </div>
1191
1193
  ```
1192
1194
 
1195
+ ### rich_text_area
1196
+
1197
+ Our `rich_text_area` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-rich_text_area). This editor is also known as `Trix Editor`.
1198
+
1199
+ ![rich_text_area](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e845ee05-79f2-4352-899e-f93decc9b16b)
1200
+
1201
+ ```erb
1202
+ <%= form.rich_text_area :life_story %>
1203
+ ```
1204
+
1205
+ This generates the following HTML:
1206
+
1207
+ ```html
1208
+ <div class="mb-3">
1209
+ <label class="form-label" for="user_life_story">Life story</label>
1210
+ <input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user" autocomplete="off">
1211
+ <trix-toolbar id="trix-toolbar-1">
1212
+ <div class="trix-button-row">
1213
+ <span class="trix-button-group trix-button-group--text-tools" data-trix-button-group="text-tools">
1214
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-bold" data-trix-attribute="bold" data-trix-key="b" title="Bold" tabindex="-1">Bold</button>
1215
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-italic" data-trix-attribute="italic" data-trix-key="i" title="Italic" tabindex="-1">Italic</button>
1216
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-strike" data-trix-attribute="strike" title="Strikethrough" tabindex="-1">Strikethrough</button>
1217
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-link" data-trix-attribute="href" data-trix-action="link" data-trix-key="k" title="Link" tabindex="-1">Link</button>
1218
+ </span>
1219
+ <span class="trix-button-group trix-button-group--block-tools" data-trix-button-group="block-tools">
1220
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-heading-1" data-trix-attribute="heading1" title="Heading" tabindex="-1">Heading</button>
1221
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-quote" data-trix-attribute="quote" title="Quote" tabindex="-1">Quote</button>
1222
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-code" data-trix-attribute="code" title="Code" tabindex="-1">Code</button>
1223
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-bullet-list" data-trix-attribute="bullet" title="Bullets" tabindex="-1">Bullets</button>
1224
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-number-list" data-trix-attribute="number" title="Numbers" tabindex="-1">Numbers</button>
1225
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-decrease-nesting-level" data-trix-action="decreaseNestingLevel" title="Decrease Level" tabindex="-1">Decrease Level</button>
1226
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-increase-nesting-level" data-trix-action="increaseNestingLevel" title="Increase Level" tabindex="-1">Increase Level</button>
1227
+ </span>
1228
+ <span class="trix-button-group trix-button-group--file-tools" data-trix-button-group="file-tools">
1229
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-attach" data-trix-action="attachFiles" title="Attach Files" tabindex="-1">Attach Files</button>
1230
+ </span>
1231
+ <span class="trix-button-group-spacer"></span>
1232
+ <span class="trix-button-group trix-button-group--history-tools" data-trix-button-group="history-tools">
1233
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-undo" data-trix-action="undo" data-trix-key="z" title="Undo" tabindex="-1">Undo</button>
1234
+ <button type="button" class="trix-button trix-button--icon trix-button--icon-redo" data-trix-action="redo" data-trix-key="shift+z" title="Redo" tabindex="-1">Redo</button>
1235
+ </span>
1236
+ </div>
1237
+ <div class="trix-dialogs" data-trix-dialogs="">
1238
+ <div class="trix-dialog trix-dialog--link" data-trix-dialog="href" data-trix-dialog-attribute="href">
1239
+ <div class="trix-dialog__link-fields">
1240
+ <input type="url" name="href" class="trix-input trix-input--dialog" placeholder="Enter a URL…" aria-label="URL" required="" data-trix-input="" disabled="disabled">
1241
+ <div class="trix-button-group">
1242
+ <input type="button" class="trix-button trix-button--dialog" value="Link" data-trix-method="setAttribute">
1243
+ <input type="button" class="trix-button trix-button--dialog" value="Unlink" data-trix-method="removeAttribute">
1244
+ </div>
1245
+ </div>
1246
+ </div>
1247
+ </div>
1248
+ </trix-toolbar>
1249
+ <trix-editor class="trix-content form-control" id="user_life_story" input="user_life_story_trix_input_user" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" data-blob-url-template="http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename" contenteditable="" role="textbox" aria-label="Life story Life story" trix-id="1" toolbar="trix-toolbar-1"></trix-editor>
1250
+ </div>
1251
+ ```
1252
+
1193
1253
  ### search_field
1194
1254
 
1195
1255
  Our `search_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-search_field).
@@ -1488,12 +1548,12 @@ This generates the following HTML:
1488
1548
  ### collection_check_boxes
1489
1549
 
1490
1550
  This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a `block` as
1491
- an argument and takes care of rendering labels, check boxes, and wrapper for you.
1551
+ an argument and takes care of rendering labels, check boxes, and wrapper for you. `collection_check_boxes` are rendered by default for multiple option selections, but you can turn them into single selections by passing `options[:multiple] = false`.
1492
1552
 
1493
1553
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1494
1554
 
1495
1555
  ```erb
1496
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {multiple: true, bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
1556
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
1497
1557
  ```
1498
1558
 
1499
1559
  This generates the following HTML:
@@ -1 +1,2 @@
1
1
  //= link_directory ../stylesheets .css
2
+ //= link_tree ../../javascript .js
@@ -0,0 +1,36 @@
1
+ //
2
+ // Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
3
+ // the trix-editor content (whether displayed or under editing). Feel free to incorporate this
4
+ // inclusion directly in any other asset bundle and remove this file.
5
+ //
6
+ @import "trix";
7
+
8
+ // We need to override trix.css’s image gallery styles to accommodate the
9
+ // <action-text-attachment> element we wrap around attachments. Otherwise,
10
+ // images in galleries will be squished by the max-width: 33%; rule.
11
+ .trix-content {
12
+ .attachment-gallery {
13
+ > action-text-attachment,
14
+ > .attachment {
15
+ flex: 1 0 33%;
16
+ padding: 0 0.5em;
17
+ max-width: 33%;
18
+ }
19
+
20
+ &.attachment-gallery--2,
21
+ &.attachment-gallery--4 {
22
+ > action-text-attachment,
23
+ > .attachment {
24
+ flex-basis: 50%;
25
+ max-width: 50%;
26
+ }
27
+ }
28
+ }
29
+
30
+ action-text-attachment {
31
+ .attachment {
32
+ padding: 0 !important;
33
+ max-width: 100% !important;
34
+ }
35
+ }
36
+ }
@@ -1,3 +1,4 @@
1
1
  @charset "utf-8";
2
2
  @import "bootstrap";
3
- @import "rails_bootstrap_form"
3
+ @import "actiontext";
4
+ @import "rails_bootstrap_form";
@@ -60,6 +60,7 @@ class UsersController < ApplicationController
60
60
  :interview_datetime,
61
61
  :weekly_off,
62
62
  :gender,
63
+ :life_story,
63
64
  skill_ids: [],
64
65
  address_attributes: [
65
66
  :street,
@@ -0,0 +1,2 @@
1
+ import "trix";
2
+ import "@rails/actiontext";
@@ -3,7 +3,7 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  class Address < ApplicationRecord
6
- validates :street, :city, :country_id, presence: true
6
+ validates :street, :city, presence: true
7
7
 
8
8
  belongs_to :user
9
9
  belongs_to :country
@@ -6,6 +6,10 @@ class User < ApplicationRecord
6
6
 
7
7
  attr_accessor :remember_me
8
8
 
9
+ has_rich_text :life_story
10
+
11
+ has_one_attached :avatar, dependent: :purge_later
12
+
9
13
  validates :name, presence: true, length: {in: 2..50}
10
14
  validates :terms, acceptance: true
11
15
  validates :email,
@@ -0,0 +1,14 @@
1
+ <figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
2
+ <% if blob.representable? %>
3
+ <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
4
+ <% end %>
5
+
6
+ <figcaption class="attachment__caption">
7
+ <% if caption = blob.try(:caption) %>
8
+ <%= caption %>
9
+ <% else %>
10
+ <span class="attachment__name"><%= blob.filename %></span>
11
+ <span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
12
+ <% end %>
13
+ </figcaption>
14
+ </figure>
@@ -0,0 +1,3 @@
1
+ <div class="trix-content">
2
+ <%= yield -%>
3
+ </div>
@@ -6,6 +6,7 @@
6
6
  <%= csrf_meta_tags %>
7
7
  <%= csp_meta_tag %>
8
8
  <%= stylesheet_link_tag "application" %>
9
+ <%= javascript_importmap_tags %>
9
10
  </head>
10
11
  <body>
11
12
  <div class="container-fluid p-3">
@@ -9,6 +9,7 @@
9
9
  <%= form.email_field :email, autocomplete: "new-email" %>
10
10
  <%= form.password_field :password, autocomplete: "new-password" %>
11
11
  <%= form.phone_field :mobile_number %>
12
+ <%= form.file_field :avatar %>
12
13
  <%= form.date_field :birth_date %>
13
14
  <%= form.range_field :excellence %>
14
15
  <%= form.url_field :blog_url %>
@@ -20,6 +21,7 @@
20
21
  <%= form.time_select :interview_time %>
21
22
  <%= form.datetime_select :interview_datetime %>
22
23
  <%= form.weekday_select :weekly_off %>
24
+ <%= form.rich_text_area :life_story %>
23
25
  <%= form.fields_for :address, include_id: false do |address_form| %>
24
26
  <%= address_form.text_area :street %>
25
27
  <%= address_form.text_field :state %>
@@ -9,6 +9,7 @@
9
9
  <%= form.email_field :email, autocomplete: "new-email" %>
10
10
  <%= form.password_field :password, autocomplete: "new-password" %>
11
11
  <%= form.phone_field :mobile_number %>
12
+ <%= form.file_field :avatar %>
12
13
  <%= form.date_field :birth_date %>
13
14
  <%= form.range_field :excellence %>
14
15
  <%= form.url_field :blog_url %>
@@ -20,6 +21,7 @@
20
21
  <%= form.time_select :interview_time %>
21
22
  <%= form.datetime_select :interview_datetime %>
22
23
  <%= form.weekday_select :weekly_off %>
24
+ <%= form.rich_text_area :life_story %>
23
25
  <%= form.fields_for :address, include_id: false do |address_form| %>
24
26
  <%= address_form.text_area :street %>
25
27
  <%= address_form.text_field :state %>
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ # -*- frozen_string_literal: true -*-
4
+ # -*- warn_indent: true -*-
5
+
6
+ require_relative "../config/application"
7
+ require "importmap/commands"
@@ -7,3 +7,5 @@ require_relative "application"
7
7
 
8
8
  # Initialize the Rails application.
9
9
  Rails.application.initialize!
10
+
11
+ Rails.application.routes.default_url_options[:host] = "localhost"
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ pin "trix", to: "https://ga.jspm.io/npm:trix@2.0.5/dist/trix.esm.min.js"
6
+ pin "@rails/actiontext", to: "https://ga.jspm.io/npm:@rails/actiontext@7.0.5/app/assets/javascripts/actiontext.js"
7
+ pin "application", preload: true
@@ -35,6 +35,8 @@
35
35
  interview_datetime: "Interview date & time",
36
36
  weekly_off: "Week off",
37
37
  gender: "Gender",
38
+ bio: "Life story",
39
+ avatar: "Avatar",
38
40
  },
39
41
  user_skill: {
40
42
  user_id: "User",
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ # This migration comes from active_storage (originally 20170806125915)
6
+ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
7
+ def change
8
+ # Use Active Record's configured type for primary and foreign keys
9
+ primary_key_type, foreign_key_type = primary_and_foreign_key_types
10
+
11
+ create_table :active_storage_blobs, id: primary_key_type do |t|
12
+ t.string :key, null: false
13
+ t.string :filename, null: false
14
+ t.string :content_type
15
+ t.text :metadata
16
+ t.string :service_name, null: false
17
+ t.bigint :byte_size, null: false
18
+ t.string :checksum
19
+
20
+ if connection.supports_datetime_with_precision?
21
+ t.datetime :created_at, precision: 6, null: false
22
+ else
23
+ t.datetime :created_at, null: false
24
+ end
25
+
26
+ t.index [ :key ], unique: true
27
+ end
28
+
29
+ create_table :active_storage_attachments, id: primary_key_type do |t|
30
+ t.string :name, null: false
31
+ t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
32
+ t.references :blob, null: false, type: foreign_key_type
33
+
34
+ if connection.supports_datetime_with_precision?
35
+ t.datetime :created_at, precision: 6, null: false
36
+ else
37
+ t.datetime :created_at, null: false
38
+ end
39
+
40
+ t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
41
+ t.foreign_key :active_storage_blobs, column: :blob_id
42
+ end
43
+
44
+ create_table :active_storage_variant_records, id: primary_key_type do |t|
45
+ t.belongs_to :blob, null: false, index: false, type: foreign_key_type
46
+ t.string :variation_digest, null: false
47
+
48
+ t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
49
+ t.foreign_key :active_storage_blobs, column: :blob_id
50
+ end
51
+ end
52
+
53
+ private
54
+ def primary_and_foreign_key_types
55
+ config = Rails.configuration.generators
56
+ setting = config.options[config.orm][:primary_key_type]
57
+ primary_key_type = setting || :primary_key
58
+ foreign_key_type = setting || :bigint
59
+ [primary_key_type, foreign_key_type]
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ # This migration comes from action_text (originally 20180528164100)
6
+ class CreateActionTextTables < ActiveRecord::Migration[6.0]
7
+ def change
8
+ # Use Active Record's configured type for primary and foreign keys
9
+ primary_key_type, foreign_key_type = primary_and_foreign_key_types
10
+
11
+ create_table :action_text_rich_texts, id: primary_key_type do |t|
12
+ t.string :name, null: false
13
+ t.text :body, size: :long
14
+ t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
15
+
16
+ t.timestamps
17
+
18
+ t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
19
+ end
20
+ end
21
+
22
+ private
23
+ def primary_and_foreign_key_types
24
+ config = Rails.configuration.generators
25
+ setting = config.options[config.orm][:primary_key_type]
26
+ primary_key_type = setting || :primary_key
27
+ foreign_key_type = setting || :bigint
28
+ [primary_key_type, foreign_key_type]
29
+ end
30
+ end
data/demo/db/schema.rb CHANGED
@@ -10,10 +10,48 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema[7.0].define(version: 2023_05_28_041919) do
13
+ ActiveRecord::Schema[7.0].define(version: 2023_06_21_041642) do
14
14
  # These are extensions that must be enabled in order to support this database
15
15
  enable_extension "plpgsql"
16
16
 
17
+ create_table "action_text_rich_texts", force: :cascade do |t|
18
+ t.string "name", null: false
19
+ t.text "body"
20
+ t.string "record_type", null: false
21
+ t.bigint "record_id", null: false
22
+ t.datetime "created_at", null: false
23
+ t.datetime "updated_at", null: false
24
+ t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
25
+ end
26
+
27
+ create_table "active_storage_attachments", force: :cascade do |t|
28
+ t.string "name", null: false
29
+ t.string "record_type", null: false
30
+ t.bigint "record_id", null: false
31
+ t.bigint "blob_id", null: false
32
+ t.datetime "created_at", null: false
33
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
34
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
35
+ end
36
+
37
+ create_table "active_storage_blobs", force: :cascade do |t|
38
+ t.string "key", null: false
39
+ t.string "filename", null: false
40
+ t.string "content_type"
41
+ t.text "metadata"
42
+ t.string "service_name", null: false
43
+ t.bigint "byte_size", null: false
44
+ t.string "checksum"
45
+ t.datetime "created_at", null: false
46
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
47
+ end
48
+
49
+ create_table "active_storage_variant_records", force: :cascade do |t|
50
+ t.bigint "blob_id", null: false
51
+ t.string "variation_digest", null: false
52
+ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
53
+ end
54
+
17
55
  create_table "addresses", primary_key: "user_id", force: :cascade do |t|
18
56
  t.bigint "country_id"
19
57
  t.string "street"
@@ -84,4 +122,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_28_041919) do
84
122
  t.index ["fruit_id"], name: "index_users_on_fruit_id"
85
123
  end
86
124
 
125
+ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
126
+ add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
87
127
  end
@@ -12,6 +12,9 @@ gem "sprockets-rails"
12
12
  # Use Sass to process CSS
13
13
  gem "sassc-rails"
14
14
 
15
+ # Use importmap to include JavaScript modules
16
+ gem "importmap-rails", "~> 1.2"
17
+
15
18
  # Add bootstrap support
16
19
  gem "bootstrap", "~> 5.3.0.alpha3"
17
20
 
@@ -25,7 +25,7 @@ module RailsBootstrapForm
25
25
  attr_accessor :layout
26
26
 
27
27
  # A CSS class that will be applied to all form fields.
28
- # The default value is `form-control`.
28
+ # The default value is `nil`.
29
29
  attr_accessor :field_class
30
30
 
31
31
  # An additional CSS class that will be added along with the existing
@@ -169,12 +169,20 @@ module RailsBootstrapForm
169
169
  define_method("#{method}?") { self.send(method) }
170
170
  end
171
171
 
172
+ def disable_floating_labels!
173
+ self.floating = false
174
+ end
175
+
176
+ def set_field_class!(css_class)
177
+ self.field_class ||= css_class
178
+ end
179
+
172
180
  def set_defaults
173
181
  @disabled = false
174
182
 
175
183
  @layout = "vertical"
176
184
 
177
- @field_class = "form-control"
185
+ @field_class = nil
178
186
  @additional_field_class = nil
179
187
 
180
188
  @help_text = nil
@@ -72,7 +72,7 @@ module RailsBootstrapForm
72
72
  def field_css_options(attribute, bootstrap, options, html_options)
73
73
  css_options = (html_options || options)
74
74
 
75
- field_classes = Array(bootstrap.field_class) << [bootstrap.additional_field_class || options[:class]]
75
+ field_classes = Array(bootstrap.field_class) << [bootstrap.additional_field_class || css_options[:class]]
76
76
  field_classes << "is-invalid" if is_invalid?(attribute)
77
77
  if is_size_valid?(bootstrap)
78
78
  field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
@@ -13,11 +13,11 @@ module RailsBootstrapForm
13
13
  has_association_error?(attribute)
14
14
  end
15
15
 
16
- def input_with_error(attribute, &block)
17
- input = capture(&block)
18
- input << generate_error(attribute)
19
- input
20
- end
16
+ # def input_with_error(attribute, &block)
17
+ # input = capture(&block)
18
+ # input << generate_error(attribute)
19
+ # input
20
+ # end
21
21
 
22
22
  def generate_error(attribute)
23
23
  if is_invalid?(attribute)
@@ -58,9 +58,8 @@ module RailsBootstrapForm
58
58
  (association.foreign_key == attribute.to_s)
59
59
  end
60
60
 
61
- private :is_invalid?, :input_with_error, :generate_error,
62
- :has_association_error?, :error_messages,
63
- :is_belongs_to_association?, :is_association_same?
61
+ private :is_invalid?, :generate_error, :has_association_error?,
62
+ :error_messages, :is_belongs_to_association?, :is_association_same?
64
63
  end
65
64
  end
66
65
  end
@@ -17,7 +17,7 @@ module RailsBootstrapForm
17
17
  input_options = {
18
18
  bootstrap: {
19
19
  label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
20
- inline: (bootstrap.inline? || bootstrap.layout_inline?)
20
+ inline: (bootstrap.inline? || bootstrap.layout_inline?)
21
21
  },
22
22
  required: false,
23
23
  id: sanitized_tag_name(attribute, value)
@@ -42,6 +42,8 @@ module RailsBootstrapForm
42
42
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
43
43
  return super(attribute, options) if bootstrap.disabled?
44
44
 
45
+ bootstrap.set_field_class!("form-control")
46
+
45
47
  field_wrapper_builder(attribute, bootstrap, options) do
46
48
  super(attribute, options)
47
49
  end
@@ -50,11 +52,12 @@ module RailsBootstrapForm
50
52
 
51
53
  def bootstrap_select_group(tag_name)
52
54
  define_method(tag_name) do |attribute, options = {}, html_options = {}|
53
- options = {bootstrap: {field_class: "form-select", floating: false}}.deep_merge!(options)
54
-
55
55
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
56
56
  return super(attribute, options, html_options) if bootstrap.disabled?
57
57
 
58
+ bootstrap.set_field_class!("form-select")
59
+ bootstrap.disable_floating_labels!
60
+
58
61
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
59
62
  tag.fieldset(class: control_specific_class(tag_name)) do
60
63
  super(attribute, options, html_options)
@@ -10,9 +10,12 @@ module RailsBootstrapForm
10
10
  included do
11
11
  def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- bootstrap.floating = false
14
13
  return super if bootstrap.disabled?
15
14
 
15
+ bootstrap.disable_floating_labels!
16
+
17
+ options[:multiple] = options.delete(:multiple) { true }
18
+
16
19
  inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
17
20
  bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
18
21
 
@@ -10,9 +10,10 @@ module RailsBootstrapForm
10
10
  included do
11
11
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- bootstrap.floating = false
14
13
  return super if bootstrap.disabled?
15
14
 
15
+ bootstrap.disable_floating_labels!
16
+
16
17
  inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
17
18
  bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
18
19
 
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-select")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, value_method, text_method, options, html_options)
19
19
  end
@@ -9,16 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def color_field(attribute, options = {})
12
- options = {
13
- bootstrap: {
14
- field_class: "form-control form-control-color",
15
- floating: false
16
- }
17
- }.deep_merge!(options)
18
-
19
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
20
13
  return super if bootstrap.disabled?
21
14
 
15
+ bootstrap.set_field_class!("form-control form-control-color")
16
+ bootstrap.disable_floating_labels!
17
+
22
18
  field_wrapper_builder(attribute, bootstrap, options) do
23
19
  super(attribute, options)
24
20
  end
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
12
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-select")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
19
19
  end
@@ -9,11 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def range_field(attribute, options = {})
12
- options = {bootstrap: {field_class: "form-range", floating: false}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-range")
16
+ bootstrap.disable_floating_labels!
17
+
17
18
  field_wrapper_builder(attribute, bootstrap, options) do
18
19
  super(attribute, options)
19
20
  end
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def rich_text_area(attribute, options = {})
12
- options[:class] = ["trix-content", options[:class]].compact.join(" ")
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("trix-content form-control")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def select(attribute, choices = nil, options = {}, html_options = {}, &block)
12
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-select")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, choices, options, html_options, &block)
19
19
  end
@@ -8,21 +8,19 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- def static_field(*args)
12
- options = args.extract_options!
13
- attribute = args.first
14
-
15
- static_options = options.merge(
16
- readonly: true,
17
- disabled: true,
18
- bootstrap: {
11
+ def static_field(attribute, options = {})
12
+ options.tap do |option|
13
+ option[:readonly] = true
14
+ option[:disabled] = true
15
+ option[:bootstrap] = {
16
+ floating: false,
19
17
  field_class: bootstrap_form_options.static_field_class
20
- }.reverse_merge!(options.delete(:bootstrap))
21
- )
18
+ }.reverse_merge!(options.fetch(:bootstrap, {}))
19
+ end
22
20
 
23
- static_options[:value] = object.send(attribute) unless options.key?(:value)
21
+ options[:value] = object.send(attribute) unless options.key?(:value)
24
22
 
25
- text_field(attribute, static_options)
23
+ text_field(attribute, options)
26
24
  end
27
25
  end
28
26
  end
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
12
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-select")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, priority_zones, options, html_options)
19
19
  end
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def weekday_select(attribute, options = {}, html_options = {}, &block)
12
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
-
14
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
13
  return super if bootstrap.disabled?
16
14
 
15
+ bootstrap.set_field_class!("form-select")
16
+
17
17
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, options, html_options, &block)
19
19
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.4".freeze
6
+ VERSION = "0.9.6".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
@@ -5,6 +5,7 @@
5
5
  require "action_view"
6
6
  require "action_pack"
7
7
  require "rails_bootstrap_form/action_view_extensions/bootstrap_form_helper"
8
+ require "#{Gem::Specification.find_by_name('actiontext').gem_dir}/app/helpers/action_text/tag_helper"
8
9
 
9
10
  module RailsBootstrapForm
10
11
  extend ActiveSupport::Autoload
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-17 00:00:00.000000000 Z
11
+ date: 2023-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec
@@ -75,12 +75,14 @@ files:
75
75
  - demo/.ruby-version
76
76
  - demo/Rakefile
77
77
  - demo/app/assets/config/manifest.js
78
+ - demo/app/assets/stylesheets/actiontext.scss
78
79
  - demo/app/assets/stylesheets/application.scss
79
80
  - demo/app/channels/application_cable/channel.rb
80
81
  - demo/app/channels/application_cable/connection.rb
81
82
  - demo/app/controllers/application_controller.rb
82
83
  - demo/app/controllers/users_controller.rb
83
84
  - demo/app/helpers/application_helper.rb
85
+ - demo/app/javascript/application.js
84
86
  - demo/app/jobs/application_job.rb
85
87
  - demo/app/mailers/application_mailer.rb
86
88
  - demo/app/models/address.rb
@@ -91,6 +93,8 @@ files:
91
93
  - demo/app/models/skill.rb
92
94
  - demo/app/models/user.rb
93
95
  - demo/app/models/user_skill.rb
96
+ - demo/app/views/active_storage/blobs/_blob.html.erb
97
+ - demo/app/views/layouts/action_text/contents/_content.html.erb
94
98
  - demo/app/views/layouts/application.html.erb
95
99
  - demo/app/views/users/_form.html.erb
96
100
  - demo/app/views/users/_form_without_bootstrap_helpers.html.erb
@@ -101,6 +105,7 @@ files:
101
105
  - demo/app/views/users/index.html.erb
102
106
  - demo/app/views/users/new.html.erb
103
107
  - demo/bin/bundle
108
+ - demo/bin/importmap
104
109
  - demo/bin/rails
105
110
  - demo/bin/rake
106
111
  - demo/bin/setup
@@ -113,6 +118,7 @@ files:
113
118
  - demo/config/environments/development.rb
114
119
  - demo/config/environments/production.rb
115
120
  - demo/config/environments/test.rb
121
+ - demo/config/importmap.rb
116
122
  - demo/config/initializers/assets.rb
117
123
  - demo/config/initializers/content_security_policy.rb
118
124
  - demo/config/initializers/filter_parameter_logging.rb
@@ -131,6 +137,8 @@ files:
131
137
  - demo/db/migrate/20230514061100_create_user_skills.rb
132
138
  - demo/db/migrate/20230516044126_create_cities.rb
133
139
  - demo/db/migrate/20230528041919_add_columns_in_users.rb
140
+ - demo/db/migrate/20230621041641_create_active_storage_tables.active_storage.rb
141
+ - demo/db/migrate/20230621041642_create_action_text_tables.action_text.rb
134
142
  - demo/db/schema.rb
135
143
  - demo/db/seeds.rb
136
144
  - demo/public/favicon.ico