rails_bootstrap_form 0.9.5 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/Gemfile.lock +5 -1
  4. data/README.md +62 -4
  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/admin_user.rb +11 -0
  12. data/demo/app/models/super_user.rb +13 -0
  13. data/demo/app/models/user.rb +4 -0
  14. data/demo/app/views/active_storage/blobs/_blob.html.erb +14 -0
  15. data/demo/app/views/layouts/action_text/contents/_content.html.erb +3 -0
  16. data/demo/app/views/layouts/application.html.erb +1 -0
  17. data/demo/app/views/users/_horizontal_form.html.erb +2 -0
  18. data/demo/app/views/users/_vertical_form.html.erb +2 -0
  19. data/demo/bin/importmap +7 -0
  20. data/demo/config/environment.rb +2 -0
  21. data/demo/config/importmap.rb +7 -0
  22. data/demo/config/locales/en.rb +2 -0
  23. data/demo/db/migrate/20230621041641_create_active_storage_tables.active_storage.rb +61 -0
  24. data/demo/db/migrate/20230621041642_create_action_text_tables.action_text.rb +30 -0
  25. data/demo/db/schema.rb +41 -1
  26. data/gemfiles/common.gemfile +3 -0
  27. data/lib/rails_bootstrap_form/helpers/errors.rb +9 -10
  28. data/lib/rails_bootstrap_form/helpers/required_field.rb +1 -1
  29. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +2 -0
  30. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +2 -2
  31. data/lib/rails_bootstrap_form/version.rb +1 -1
  32. data/lib/rails_bootstrap_form.rb +1 -0
  33. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f852149d96066acbbb48afc05ba8dd6d11f535401e9cdff2e6535829f9669303
4
- data.tar.gz: d322c72387d0933048e789d849dfe79f9ee7c23f46b8eb2872d349e7698a1008
3
+ metadata.gz: 3ffc0cdcd818f57b7e0b683ec59b2ac3a59b80edab6e40f9eebe1da8d32cd376
4
+ data.tar.gz: 676be2383b1d1421b70a50ad5dc044eed15dfe4707b26ca345077644de9abebc
5
5
  SHA512:
6
- metadata.gz: 33a938a56a607b29bccd8c5ef712a68d7cd3caee5486b6002a8783023779222f211396d47ffa9e7aaf392820acd22e26d5d20a72c9e765a5aceec07355a34525
7
- data.tar.gz: 1418938ffaadcf8a58439324e844f3acff4f437f07ff58e14df45eafb539c35211a28f567b1e3d6409b1e14c7667d62bbd650c7d8f90ea6fa5ba99fc3a37ea66
6
+ metadata.gz: cdf31544bc3fd0032dff7b12bb95b1af33466d8e5a199ea0ecd263e1a8cdfdc2d00b02cc95425a1e712c6f2edd8ca626cf5e9ca6523fdf7eecf66a5a4776b17e
7
+ data.tar.gz: 60e72524a66706827e25fd018ffbe4dc75e823d346a86627c525e0e9f095af6a490846dc04526127708f4c30811f59c30c94b32936543055dcc6bf2fd6a3af4f
data/CHANGELOG.md CHANGED
@@ -4,7 +4,22 @@ 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.4](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.4...v0.9.5) - 2023-06-21
7
+ ## [0.9.7](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.6...v0.9.7) - 2023-06-26
8
+
9
+ ### What's new
10
+
11
+ - Added specs for field helpers to ensure validation errors are rendered correctly in each layout.
12
+
13
+ ## [0.9.6](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.5...v0.9.6) - 2023-06-25
14
+
15
+ ### What's new
16
+
17
+ - Integrated `importmap` and `actiontext` in demo application for demonstrating implementation of `rich_text_area`.
18
+ - Added spec examples for `date_field`, `datetime_field`, `datetime_local_field`, `datetime_select`, `email_field`,
19
+ `file_field`, `hidden_field`, `month_field`, `number_field`, `password_field`, `phone_field`, `search_field`,
20
+ `telephone_field`, `text_area`, `time_field`, `time_select`, `url_field`, and `week_field` helpers.
21
+
22
+ ## [0.9.5](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.4...v0.9.5) - 2023-06-21
8
23
 
9
24
  ### What's changed
10
25
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.9.5)
4
+ rails_bootstrap_form (0.9.7)
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.5"
31
+ gem "rails_bootstrap_form", "~> 0.9.6"
32
32
  ```
33
33
 
34
34
  Then:
@@ -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` |
@@ -1192,6 +1192,64 @@ This generates the following HTML:
1192
1192
  </div>
1193
1193
  ```
1194
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
+
1195
1253
  ### search_field
1196
1254
 
1197
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).
@@ -1490,12 +1548,12 @@ This generates the following HTML:
1490
1548
  ### collection_check_boxes
1491
1549
 
1492
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
1493
- 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`.
1494
1552
 
1495
1553
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1496
1554
 
1497
1555
  ```erb
1498
- <%= 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();"}, {} %>
1499
1557
  ```
1500
1558
 
1501
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
@@ -0,0 +1,11 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ class AdminUser
6
+ include ActiveModel::Model
7
+
8
+ attr_accessor :email, :password
9
+
10
+ validates :email, :password, presence: true
11
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ class SuperUser
6
+ attr_accessor :email, :password
7
+
8
+ def initialize(attributes = {})
9
+ attributes.each do |name, value|
10
+ send("#{name}=", value)
11
+ end
12
+ end
13
+ end
@@ -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
 
@@ -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)
@@ -29,7 +29,7 @@ module RailsBootstrapForm
29
29
  end
30
30
 
31
31
  def has_association_error?(attribute)
32
- object.class.reflections.any? do |association_name, association|
32
+ object.class.try(:reflections)&.any? do |association_name, association|
33
33
  next unless is_belongs_to_association?(association)
34
34
  next unless is_association_same?(attribute, association)
35
35
 
@@ -40,7 +40,7 @@ module RailsBootstrapForm
40
40
  def error_messages(attribute)
41
41
  messages = object.errors[attribute]
42
42
 
43
- object.class.reflections.each do |association_name, association|
43
+ object.class.try(:reflections)&.each do |association_name, association|
44
44
  next unless is_belongs_to_association?(association)
45
45
  next unless is_association_same?(attribute, association)
46
46
 
@@ -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
@@ -48,7 +48,7 @@ module RailsBootstrapForm
48
48
  end
49
49
 
50
50
  def is_required_association?(target, attribute)
51
- target.reflections.find do |name, a|
51
+ target.try(:reflections)&.find do |name, a|
52
52
  next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
53
53
  next unless a.foreign_key == attribute.to_s
54
54
 
@@ -14,6 +14,8 @@ module RailsBootstrapForm
14
14
 
15
15
  bootstrap.disable_floating_labels!
16
16
 
17
+ options[:multiple] = options.delete(:multiple) { true }
18
+
17
19
  inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
18
20
  bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
19
21
 
@@ -9,11 +9,11 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def rich_text_area(attribute, options = {})
12
- add_css_class!(options, "trix-content")
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
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.5".freeze
6
+ VERSION = "0.9.7".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.5
4
+ version: 0.9.7
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-21 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec
@@ -75,22 +75,28 @@ 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
89
+ - demo/app/models/admin_user.rb
87
90
  - demo/app/models/application_record.rb
88
91
  - demo/app/models/city.rb
89
92
  - demo/app/models/country.rb
90
93
  - demo/app/models/fruit.rb
91
94
  - demo/app/models/skill.rb
95
+ - demo/app/models/super_user.rb
92
96
  - demo/app/models/user.rb
93
97
  - demo/app/models/user_skill.rb
98
+ - demo/app/views/active_storage/blobs/_blob.html.erb
99
+ - demo/app/views/layouts/action_text/contents/_content.html.erb
94
100
  - demo/app/views/layouts/application.html.erb
95
101
  - demo/app/views/users/_form.html.erb
96
102
  - demo/app/views/users/_form_without_bootstrap_helpers.html.erb
@@ -101,6 +107,7 @@ files:
101
107
  - demo/app/views/users/index.html.erb
102
108
  - demo/app/views/users/new.html.erb
103
109
  - demo/bin/bundle
110
+ - demo/bin/importmap
104
111
  - demo/bin/rails
105
112
  - demo/bin/rake
106
113
  - demo/bin/setup
@@ -113,6 +120,7 @@ files:
113
120
  - demo/config/environments/development.rb
114
121
  - demo/config/environments/production.rb
115
122
  - demo/config/environments/test.rb
123
+ - demo/config/importmap.rb
116
124
  - demo/config/initializers/assets.rb
117
125
  - demo/config/initializers/content_security_policy.rb
118
126
  - demo/config/initializers/filter_parameter_logging.rb
@@ -131,6 +139,8 @@ files:
131
139
  - demo/db/migrate/20230514061100_create_user_skills.rb
132
140
  - demo/db/migrate/20230516044126_create_cities.rb
133
141
  - demo/db/migrate/20230528041919_add_columns_in_users.rb
142
+ - demo/db/migrate/20230621041641_create_active_storage_tables.active_storage.rb
143
+ - demo/db/migrate/20230621041642_create_action_text_tables.action_text.rb
134
144
  - demo/db/schema.rb
135
145
  - demo/db/seeds.rb
136
146
  - demo/public/favicon.ico