inline_forms 8.1.3 → 8.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 977ef4ea7379846bb2c176ef945cdaddb16816aed800d283b0655d08f0e0cfa8
4
- data.tar.gz: 5dc4778948c43efa3b4348f7c906137aae4e25545229727ed83172bab4d776f2
3
+ metadata.gz: a67a5a2a208fff953c0ffe9145425d30e7ae8fefae955271436033c1b2a99771
4
+ data.tar.gz: a7b359f732f395f368be30c35277b9eecbd1cbd253e388c8f59165b207297a6c
5
5
  SHA512:
6
- metadata.gz: 513ca378e912320a20a982210cad7f625788f79858a75310ea04e164de83a6124ca25ce43af7162065efc161e8693ec0464ac8f96e05659b46b53a2564647ba2
7
- data.tar.gz: e4ec7479913bdeaa570064e1946884d00481774a07758af7e86170342464a55f2269c029822edecaf4f31130c3e822ca18338e8a34d2ef5d60e8d240e170525f
6
+ metadata.gz: 49e2f7a7fb54b318959f5c003793e4190c812f527fa5a36ed9160260ee217d0761bf1f5c28bdf1cc241f650dcde82662b084140903551f17aadf7c2f0a539498
7
+ data.tar.gz: bc33c4b2ee408988f01c166f2fcfc5ac07e684c3b966501db41edec5b7eb0e42e8ca50904c9fa5936005974bf0ca527c9abf2086771fea6e051a8fd255ab169f
data/CHANGELOG.md CHANGED
@@ -4,6 +4,73 @@ All notable changes to this project are documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [8.1.5] - 2026-05-27
8
+
9
+ ### Changed (hard-breaking)
10
+
11
+ - **`inline_forms_attribute_list` rows are now 2-element by default.** The empty 2nd element (the unused human-name string) has been removed from every row across the gem, installer, generators, helpers, views, validators, tests, and docs. Labels have come from `Klass.human_attribute_name(attribute)` via locale files for a long time, so the slot was redundant. The migration in 8.1.5 makes that explicit by dropping the slot entirely.
12
+
13
+ Old shape:
14
+
15
+ ```ruby
16
+ [ :name, "name", :text_field ],
17
+ [ :sex, "sex", :radio_button, { 1 => 'f', 2 => 'm' } ],
18
+ [ :sex, "sex", :dropdown_with_values, values_hash, options_disabled ],
19
+ ```
20
+
21
+ New shape:
22
+
23
+ ```ruby
24
+ [ :name, :text_field ],
25
+ [ :sex, :radio_button, { 1 => 'f', 2 => 'm' } ],
26
+ [ :sex, :dropdown_with_values, values_hash, options_disabled ],
27
+ ```
28
+
29
+ **This is a hard break.** Consumers that read positions inside the row (`attributes.assoc(:foo)[3]` for `attribute_values`, `attributes.assoc(:foo)[4]` for `dropdown_with_values`' `options_disabled`) have shifted to `[2]` / `[3]`. Any model file left in the old 3/4/5-element shape will silently misbehave (the empty string `""` will be returned where the values hash or `options_disabled` array used to be), so every existing `inline_forms_attribute_list` in downstream apps must be rewritten.
30
+
31
+ Minimal migration for the common 3-element shape — run this once over `app/models/**/*.rb`:
32
+
33
+ ```ruby
34
+ # In your app's root, with a backup or in a clean git tree:
35
+ Dir.glob("app/models/**/*.rb").each do |path|
36
+ src = File.read(path)
37
+ new = src.gsub(/\[\s*(:\w+)\s*,\s*["'][^"']*["']\s*,\s*(:\w+)\s*\]/) { "[ #{$1}, #{$2} ]" }
38
+ File.write(path, new) if new != src
39
+ end
40
+ ```
41
+
42
+ For 4/5-element rows (`dropdown_with_values`, `radio_button`, `scale_*`, `slider_*`, `check_box`, `simple_file_field`, `must_be_a_value` validator targets), drop only the empty 2nd element and keep the trailing `values` / `options_disabled` arguments unchanged.
43
+
44
+ ### Changed (mechanical follow-through)
45
+
46
+ - **`InlineFormsGenerator`** and **`InlineFormsAddtoGenerator`** emit the new 2-element row shape.
47
+ - **Installer** (`inline_forms_installer/installer_core.rb`): hand-written `User` / `<custom>` model `inline_forms_attribute_list` rewritten; `gsub_file` injections for `Apartment#owner` and `Owner#apartments` updated to the new shape.
48
+ - **Runtime consumers** (`InlineFormsController#create`, `app/views/inline_forms/_show.html.erb`, `_new.html.erb`, `_new_nested.html.erb`, `InlineForms.validate_plain_text_configuration_for!`, `InlineForms.validate_no_archived_form_elements_for!`) updated their row destructuring to `|attribute, form_element|`.
49
+ - **Positional lookups** in `InlineFormsHelper#attribute_values`, `MustBeAValueValidator#attribute_values`, and `DropdownWithValuesHelper#…_edit` shifted from `[3]` / `[4]` to `[2]` / `[3]`.
50
+ - **Tests & docs:** all fixtures, assertions, and code samples (USAGE files, READMEs, `archived/*/README.md`) updated to the new shape.
51
+
52
+ ### Notes
53
+
54
+ - **Example app gate (recorded):** `inline_forms create MyApp -d sqlite --example` against the freshly built **8.1.5** gem trio: install in ~73s, `bundle check: ok`, **88 runs, 502 assertions, 0 failures, 0 errors, 0 skips**. Gem unit tests: 42 runs, 240 assertions, 0 failures.
55
+
56
+ ## [8.1.4] - 2026-05-26
57
+
58
+ ### Fixed
59
+
60
+ - **Search box on `/users` (or `/members`, etc.) silently returned the full list.** The installer-generated user model declared `scope :inline_forms_list, -> { order(:name, :id) }` but **no** `inline_forms_search` scope, so `InlineFormsController#index`'s `merge(@Klass.inline_forms_search(params[:search]))` fell through to the `ApplicationRecord` no-op (`scope :inline_forms_search, ->(_q) { all }`) and emitted `SELECT … FROM users ORDER BY name ASC, id ASC LIMIT 7` — no `WHERE`, no filter, regardless of the search query. Installer's `User` / `<custom>` model template now ships `scope :inline_forms_search, ->(q) { where("name LIKE :q OR email LIKE :q", q: "%#{q}%") }`, so `/users?search=ad` now returns rows whose name or email matches `%ad%`. Custom user-model classes via `-U <Class>` get the same scope.
61
+ - **Top-bar "More" dropdown was empty in every generated app** (long-standing latent bug). `lib/generators/inline_forms_generator.rb#add_tab` looked for the marker `ActionView::CompiledTemplates::MODEL_TABS = %w(` in `app/controllers/application_controller.rb`, but the installer wrote the initializer at `config/initializers/inline_forms.rb` with the marker `MODEL_TABS = %w(` and the application controller had no marker at all. Thor's `inject_into_file` silently skipped (no error, no message), so `MODEL_TABS` stayed `%w()` through every `rails g inline_forms` call. The header partial (`app/views/inline_forms/_header.html.erb`) iterated an empty list and the dropdown rendered just the chevron with no children — for years.
62
+ - `add_tab` now targets `config/initializers/inline_forms.rb` with the simpler marker `MODEL_TABS = %w(`, no-ops if the file or marker is missing (so consumers running `rails g inline_forms` in a non-installer-shaped app still work), and stays idempotent on re-run (skips the token if already present).
63
+ - Installer's initializer is now created **before** the `Locale` / `Role` `generate "inline_forms"` calls (was created at the end of the run), and is pre-seeded with the user-model's pluralised route — `MODEL_TABS = %w(<plural_route> )` — because the user model is hand-written by the installer (not generated) and would otherwise never be added.
64
+ - Net effect on a fresh `inline_forms create MyApp -d sqlite --example`: `MODEL_TABS = %w(owners apartments roles locales users )` (with `-U Member`: `… members `). The top-bar "More" dropdown now lists every HTML-reachable model the current `current_user` `can? :update`.
65
+
66
+ ### Changed
67
+
68
+ - **Test skeleton (`test/inline_forms_generator_test.rb#build_destination_skeleton!`)** writes `config/initializers/inline_forms.rb` with `MODEL_TABS = %w()` (matching the installer) instead of the legacy `ActionView::CompiledTemplates::MODEL_TABS = %w()` in `application_controller.rb`. `test_generates_model_controller_route_migration_and_tab_injection` now asserts the token lands in the initializer.
69
+
70
+ ### Notes
71
+
72
+ - **Example app gate (recorded):** `inline_forms create MyApp -d sqlite --example` against the freshly built **8.1.4** gem trio: install in ~71s, `bundle check: ok`, `MODEL_TABS = %w(owners apartments roles locales users )` in the initializer, **88 runs, 502 assertions, 0 failures, 0 errors, 0 skips**. Same result with `-U Member`, with `users → members` in `MODEL_TABS`.
73
+
7
74
  ## [8.1.3] - 2026-05-26
8
75
 
9
76
  ### Changed
data/README.rdoc CHANGED
@@ -62,7 +62,7 @@ You can install the example application manually if you like:
62
62
  rails g migration AddOwnerToApartments owner:references
63
63
  # Then in app/models/apartment.rb, add (under has_paper_trail):
64
64
  # belongs_to :owner, optional: true
65
- # and prepend `[ :owner, "owner", :dropdown ],` to inline_forms_attribute_list.
65
+ # and prepend `[ :owner, :dropdown ],` to inline_forms_attribute_list.
66
66
  bundle exec rake db:migrate
67
67
  rails s
68
68
 
@@ -208,7 +208,7 @@ Active-tab highlighting is unchanged from upstream (still driven by +set_tab :fo
208
208
  tab = ALL_TABS.include?(params[:tab].to_s) ? params[:tab].to_s : ALL_TABS.first
209
209
  set_tab tab.to_sym
210
210
  @inline_forms_attribute_list = TAB_FIELDS.fetch(tab).map { |a|
211
- @object.inline_forms_attribute_list.find { |attr, _, _| attr == a }
211
+ @object.inline_forms_attribute_list.find { |attr, _| attr == a }
212
212
  }
213
213
  render "clients/show_with_tabs",
214
214
  layout: turbo_frame_request? ? "turbo_rails/frame" : "inline_forms"
@@ -135,7 +135,7 @@ class InlineFormsController < ApplicationController
135
135
  @object ||= @Klass.new
136
136
  @update_span = params[:update]
137
137
  attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list
138
- attributes.each do | attribute, name, form_element |
138
+ attributes.each do | attribute, form_element |
139
139
  InlineForms.assert_plain_text_column!(object: @object, attribute: attribute, form_element: form_element)
140
140
  send("#{form_element.to_s}_update", @object, attribute) unless form_element == :associated || (cancan_enabled? && cannot?(:read, @object, attribute))
141
141
  end
@@ -310,7 +310,7 @@ module InlineFormsHelper
310
310
  # if we have a hash { 0=>'a', 2=>'b', 3=>'d' } will result in [[0,'a'],[2,'b'],[3,'d']] (it will keep the index and sort on the index)
311
311
  # TODO work this out better!
312
312
  # 2012-01-23 Use Cases
313
- # [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ],
313
+ # [ :sex, :radio_button, { 1 => 'f', 2 => 'm' } ],
314
314
  # in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value.
315
315
  # using an array, won't work, since [ 'f', 'm' ][1] would be 'm' in stead of 'f'
316
316
  # so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random.
@@ -326,10 +326,13 @@ module InlineFormsHelper
326
326
  # In the dropdown (or the slider) we definately need the order preserverd.
327
327
  # attribulte_values turns this into
328
328
  # [ [0,'???'], [1, '--'] .... [5, '++'] ]
329
-
329
+ #
330
+ # Row shape (since 8.1.x): [ :attr, :form_element, values, options_disabled ].
331
+ # `values` lives at index 2 (was index 3 before the empty label string was
332
+ # dropped in 8.1.x).
330
333
 
331
334
  attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!!
332
- values = attributes.assoc(attribute.to_sym)[3]
335
+ values = attributes.assoc(attribute.to_sym)[2]
333
336
  raise t("fatal.no_values_defined_in", @Klass, attribute) if values.nil?
334
337
  if values.is_a?(Hash)
335
338
  temp = Array.new
@@ -28,7 +28,7 @@ class MustBeAValueValidator < ActiveModel::EachValidator
28
28
  # if we have a hash { 0=>'a', 2=>'b', 3=>'d' } will result in [[0,'a'],[2,'b'],[3,'d']] (it will keep the index and sort on the index)
29
29
  # TODO work this out better!
30
30
  # 2012-01-23 Use Cases
31
- # [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ],
31
+ # [ :sex, :radio_button, { 1 => 'f', 2 => 'm' } ],
32
32
  # in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value.
33
33
  # using an array, won't work, since [ 'v', 'm' ][1] would be 'm' in stead of 'v'
34
34
  # so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random.
@@ -40,8 +40,11 @@ class MustBeAValueValidator < ActiveModel::EachValidator
40
40
  # like value=values.assoc(attribute_from_database)[1] (the [1] is needed since the result of #assoc = [1,'v'] and we need the 'v')
41
41
  # I feel it's ugly but it works.
42
42
 
43
+ # Row shape (since 8.1.x): [ :attr, :form_element, values, options_disabled ].
44
+ # `values` lives at index 2 (was index 3 before the empty label string was
45
+ # dropped in 8.1.x).
43
46
  attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!!
44
- values = attributes.assoc(attribute.to_sym)[3]
47
+ values = attributes.assoc(attribute.to_sym)[2]
45
48
  raise "No Values defined in #{@Klass}, #{attribute}" if values.nil?
46
49
  if values.is_a?(Hash)
47
50
  temp = Array.new
@@ -39,7 +39,7 @@
39
39
  parent_id: @parent_id),
40
40
  new_form_opts do -%>
41
41
  <% attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list -%>
42
- <% attributes.each do | attribute, name, form_element | -%>
42
+ <% attributes.each do | attribute, form_element | -%>
43
43
  <% unless form_element.to_sym == :associated || (cancan_enabled? && cannot?(:read, @object, attribute)) -%>
44
44
  <% css_class_id = "attribute_#{attribute}_#{@object.id}" -%>
45
45
  <% if form_element && form_element.to_sym == :header %>
@@ -14,7 +14,7 @@ This goes in _new.html.erb
14
14
  </div>
15
15
  </div>
16
16
  <% nested_attributes = @nested_object.inline_forms_attribute_list -%>
17
- <% nested_attributes.each do | nested_attribute, nested_name, nested_form_element | -%>
17
+ <% nested_attributes.each do | nested_attribute, nested_form_element | -%>
18
18
  <% @nested_form_element = nested_form_element %>
19
19
  <% @nested_attribute = nested_attribute %>
20
20
  <% unless @nested_form_element.to_sym == :associated -%>
@@ -20,7 +20,7 @@
20
20
  </div>
21
21
  <% end %>
22
22
  <% attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list -%>
23
- <% attributes.each do | attribute, name, form_element | -%>
23
+ <% attributes.each do | attribute, form_element | -%>
24
24
  <% if cancan_disabled? || can?(:read, @object, attribute) %>
25
25
  <% css_class_id = "#{@object.class.name.underscore}_#{@object.id}_#{attribute}" -%>
26
26
  <% if form_element == :header %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## What it did
7
7
 
8
- Declare in `inline_forms_attribute_list`, e.g. `[ :children, "Children", :tree ]`:
8
+ Declare in `inline_forms_attribute_list`, e.g. `[ :children, :tree ]`:
9
9
 
10
10
  - **`_show.html.erb`:** header “Children”, `+` for new child, `<turbo-frame>` wrapping **`_tree.html.erb`**.
11
11
  - **`_tree.html.erb`:** lists `parent.children` with Turbo row open, list-frame pagination (`update=…_list`).
data/inline_forms.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency("validation_hints", ">= 8.1.3", "< 9.0")
22
+ s.add_dependency("validation_hints", ">= 8.1.4", "< 9.0")
23
23
  s.add_dependency("rails", ">= 8.1", "< 8.2")
24
24
  s.add_dependency("rails-i18n", ">= 8.1", "< 9.0")
25
25
 
data/lib/generators/USAGE CHANGED
@@ -16,14 +16,14 @@ This will create:
16
16
  def _presentation
17
17
  #define your presentation here
18
18
  end
19
- def inline_forms_field_list
20
- [
21
- [ :name, 'name', :text_field ],
22
- [ :description, 'description', :plain_text ],
23
- [ :yesno, 'yesno', :check_box ],
24
- [ :gender, 'gender', :boolean_with_values ],
19
+ def inline_forms_attribute_list
20
+ @inline_forms_attribute_list ||= [
21
+ [ :name, :text_field ],
22
+ [ :description, :plain_text ],
23
+ [ :yesno, :check_box ],
24
+ [ :gender, :boolean_with_values ],
25
25
  ]
26
- end
26
+ end
27
27
  end
28
28
 
29
29
  app/controllers/things_controller.rb
@@ -0,0 +1,46 @@
1
+ Description:
2
+ Add fields to an existing inline_forms model. The model file must already
3
+ exist (from `rails g inline_forms` or the installer). Generates an additive
4
+ migration (`add_column`, `add_reference` for belongs_to/dropdown, a single
5
+ :string column for image_field/audio_field; no column for rich_text /
6
+ has_many / has_one / habtm) and updates the model: associations,
7
+ `has_rich_text`, `mount_uploader`, and new rows in `inline_forms_attribute_list`.
8
+
9
+ Does NOT create routes, a controller, or MODEL_TABS — those stay as-is for
10
+ the existing model. Use `rails g inline_forms` to scaffold new models.
11
+
12
+ Install-time-only names (`_no_model`, `_no_migration`, `_id`, `_enabled`) are
13
+ rejected. `_presentation`, `_list_order`, `_list_search`, and `_order` are
14
+ skipped unless you pass `--replace`.
15
+
16
+ Example:
17
+ rails generate inline_forms_addto User occupation:text_field birthdate:date organization:dropdown bio:rich_text
18
+
19
+ This will create:
20
+ create db/migrate/20260527120000_inline_forms_add_to_users_occupation_birthdate.rb
21
+ insert app/models/user.rb
22
+
23
+ db/migrate/..._inline_forms_add_to_users_occupation_birthdate.rb:
24
+ class InlineFormsAddToUsersOccupationBirthdate < ActiveRecord::Migration[8.1]
25
+ def change
26
+ add_column :users, :occupation, :string
27
+ add_column :users, :birthdate, :date
28
+ add_reference :users, :organization, foreign_key: true
29
+ end
30
+ end
31
+
32
+ app/models/user.rb (excerpt):
33
+ class User < ApplicationRecord
34
+ belongs_to :organization
35
+ has_rich_text :bio
36
+
37
+ def inline_forms_attribute_list
38
+ @inline_forms_attribute_list ||= [
39
+ ...
40
+ [ :occupation, :text_field ],
41
+ [ :birthdate, :date ],
42
+ [ :organization, :dropdown ],
43
+ [ :bio, :rich_text ],
44
+ ]
45
+ end
46
+ end
@@ -39,7 +39,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
39
39
  class_option :replace, type: :boolean, default: false,
40
40
  desc: "Replace existing _presentation/_list_order/_list_search instead of skipping."
41
41
 
42
- source_root File.expand_path("templates", __dir__)
42
+ source_root File.expand_path("inline_forms_addto/templates", __dir__)
43
43
 
44
44
  def validate!
45
45
  unless File.exist?(File.join(destination_root, model_file_path))
@@ -209,7 +209,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
209
209
  # `ApplicationRecord`) and no body.
210
210
  def add_attribute_list_row!(attribute)
211
211
  content = File.read(File.join(destination_root, model_file_path))
212
- row = " [ :#{attribute.name} , \"#{attribute.name}\", :#{attribute.attribute_type} ],\n"
212
+ row = " [ :#{attribute.name}, :#{attribute.attribute_type} ],\n"
213
213
 
214
214
  if content.match?(/@inline_forms_attribute_list \|\|=\s*\[/)
215
215
  if content.match?(/\[\s*:#{Regexp.escape(attribute.name)}\s*,/)
@@ -235,7 +235,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
235
235
 
236
236
  def inline_forms_attribute_list
237
237
  @inline_forms_attribute_list ||= [
238
- [ :#{attribute.name} , "#{attribute.name}", :#{attribute.attribute_type} ],
238
+ [ :#{attribute.name}, :#{attribute.attribute_type} ],
239
239
  ]
240
240
  end
241
241
  RUBY
@@ -123,8 +123,7 @@ module InlineForms
123
123
  @inline_forms_attribute_list << commenter +
124
124
  ' [ :' +
125
125
  attribute.name +
126
- ' , "' + attribute.name +
127
- '", :' + attribute.attribute_type.to_s +
126
+ ', :' + attribute.attribute_type.to_s +
128
127
  " ], \n"
129
128
  end
130
129
  end
@@ -186,11 +185,22 @@ module InlineForms
186
185
  def add_tab
187
186
  return if @flag_not_accessible_through_html
188
187
 
189
- relative_path = "app/controllers/application_controller.rb"
190
- marker = "ActionView::CompiledTemplates::MODEL_TABS = %w("
188
+ # The installer seeds `MODEL_TABS = %w(<user_model_route> )` in
189
+ # `config/initializers/inline_forms.rb` before any `rails g inline_forms`
190
+ # runs. Inject each generated model's pluralised route token into that
191
+ # list so the inline_forms top-bar dropdown (rendered by
192
+ # `app/views/inline_forms/_header.html.erb`) surfaces every
193
+ # HTML-reachable model. No-op when the initializer is absent (e.g. a
194
+ # consumer running `rails g inline_forms` in a non-installer-shaped app)
195
+ # or when the token is already present (idempotent re-run).
196
+ relative_path = "config/initializers/inline_forms.rb"
197
+ marker = "MODEL_TABS = %w("
191
198
  tab_token = "#{name.pluralize.underscore} "
192
199
  full_path = File.join(destination_root, relative_path)
200
+ return unless File.exist?(full_path)
201
+
193
202
  content = File.read(full_path)
203
+ return unless content.include?(marker)
194
204
  return if content.include?(tab_token.rstrip)
195
205
 
196
206
  inject_into_file relative_path, tab_token, after: marker
@@ -50,7 +50,7 @@ module InlineForms
50
50
  def self.validate_no_archived_form_elements_for!(klass)
51
51
  return unless klass.instance_methods.include?(:inline_forms_attribute_list)
52
52
 
53
- klass.new.inline_forms_attribute_list.each do |attribute, _label, form_element|
53
+ klass.new.inline_forms_attribute_list.each do |attribute, form_element|
54
54
  key = form_element.to_sym
55
55
  next unless ARCHIVED_FORM_ELEMENTS.key?(key)
56
56
 
@@ -16,7 +16,7 @@ module InlineForms
16
16
  values = attribute_values(object, attribute)
17
17
 
18
18
  attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list
19
- options_disabled = attributes.assoc(attribute.to_sym)[4]
19
+ options_disabled = attributes.assoc(attribute.to_sym)[3]
20
20
 
21
21
  collection_select( ('_' + object.class.to_s.underscore).to_sym,
22
22
  attribute.to_sym,
@@ -6,7 +6,7 @@ module InlineForms
6
6
  # -*- encoding : utf-8 -*-
7
7
  # radio buttons are integers in this version
8
8
  # us like this:
9
- # [ :sex , "gender", :radio_button, { 1 => 'male', 2 => 'female' } ],
9
+ # [ :sex, :radio_button, { 1 => 'male', 2 => 'female' } ],
10
10
 
11
11
  def radio_button_show(object, attribute)
12
12
  values = attribute_values(object, attribute)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineForms
3
- VERSION = "8.1.3"
3
+ VERSION = "8.1.5"
4
4
  end
data/lib/inline_forms.rb CHANGED
@@ -58,10 +58,10 @@ module InlineForms
58
58
  #
59
59
  # class Example < ApplicationRecord
60
60
  # def inline_forms_attribute_list
61
- # {
62
- # :name => [ "name", :text_field ],
63
- # :price => [ "price", :text_field ],
64
- # }
61
+ # [
62
+ # [ :name, :text_field ],
63
+ # [ :price, :text_field ],
64
+ # ]
65
65
  # end
66
66
  # end
67
67
  # as you see, both :string and :integer are mapped to a :text_field
@@ -92,7 +92,7 @@ module InlineForms
92
92
  # t.belongs_to :country
93
93
  # to the migration. (In fact AR will add t.integer :country_id). And
94
94
  # it will add
95
- # :country => [ "country", :dropdown ],
95
+ # [ :country, :dropdown ],
96
96
  # to the inline_forms_attribute_list in the model.
97
97
  #
98
98
  SPECIAL_COLUMN_TYPES = {
@@ -127,7 +127,7 @@ module InlineForms
127
127
  return unless klass.table_exists?
128
128
 
129
129
  attributes = klass.new.inline_forms_attribute_list
130
- attributes.each do |attribute, _label, form_element|
130
+ attributes.each do |attribute, form_element|
131
131
  next unless plain_text_form_element?(form_element)
132
132
  next if klass.column_names.include?(attribute.to_s)
133
133
 
@@ -6,13 +6,13 @@ require "inline_forms/archived_form_elements"
6
6
  class ArchivedFormElementsTest < Minitest::Test
7
7
  class ModelWithArchivedElement
8
8
  def inline_forms_attribute_list
9
- [[:address, "Address", :geo_code_curacao]]
9
+ [[:address, :geo_code_curacao]]
10
10
  end
11
11
  end
12
12
 
13
13
  class ModelWithArchivedTree
14
14
  def inline_forms_attribute_list
15
- [[:children, "Children", :tree]]
15
+ [[:children, :tree]]
16
16
  end
17
17
  end
18
18
 
@@ -17,8 +17,8 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
17
17
 
18
18
  def inline_forms_attribute_list
19
19
  @inline_forms_attribute_list ||= [
20
- [ :name , "name", :text_field ],
21
- [ :category , "category", :belongs_to ],
20
+ [ :name, :text_field ],
21
+ [ :category, :belongs_to ],
22
22
  ]
23
23
  end
24
24
 
@@ -38,13 +38,13 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
38
38
 
39
39
  def inline_forms_attribute_list
40
40
  @inline_forms_attribute_list ||= [
41
- [ :header_user_login, '', :header ],
42
- [ :name, '', :text_field ],
43
- [ :email, '', :text_field ],
44
- [ :locale , '', :dropdown ],
45
- [ :password, '', :devise_password_field ],
46
- [ :header_user_roles, '', :header ],
47
- [ :roles, '', :check_list ],
41
+ [ :header_user_login, :header ],
42
+ [ :name, :text_field ],
43
+ [ :email, :text_field ],
44
+ [ :locale, :dropdown ],
45
+ [ :password, :devise_password_field ],
46
+ [ :header_user_roles, :header ],
47
+ [ :roles, :check_list ],
48
48
  ]
49
49
  end
50
50
 
@@ -94,13 +94,13 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
94
94
  assert_includes(model, "belongs_to :supplier")
95
95
  assert_includes(model, "has_rich_text :bio")
96
96
  assert_includes(model, "mount_uploader :avatar, AvatarUploader")
97
- assert_includes(model, '[ :occupation , "occupation", :text_field ]')
97
+ assert_includes(model, '[ :occupation, :text_field ]')
98
98
  # :belongs_to is a relation -> no row in inline_forms_attribute_list
99
99
  # (matches InlineFormsGenerator semantics). :dropdown is not a relation
100
100
  # at lookup time, so it does get a row.
101
- refute_includes(model, '[ :organization , "organization", :belongs_to ]')
102
- assert_includes(model, '[ :supplier , "supplier", :dropdown ]')
103
- assert_includes(model, '[ :avatar , "avatar", :image_field ]')
101
+ refute_includes(model, '[ :organization, :belongs_to ]')
102
+ assert_includes(model, '[ :supplier, :dropdown ]')
103
+ assert_includes(model, '[ :avatar, :image_field ]')
104
104
 
105
105
  assert_includes(migration, "add_column :widgets, :occupation, :string")
106
106
  assert_includes(migration, "add_reference :widgets, :organization, foreign_key: true")
@@ -120,7 +120,7 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
120
120
  model = read("app/models/widget.rb")
121
121
 
122
122
  assert_equal(1, model.scan("belongs_to :organization").size)
123
- assert_equal(1, model.scan('[ :occupation , "occupation", :text_field ]').size)
123
+ assert_equal(1, model.scan('[ :occupation, :text_field ]').size)
124
124
  end
125
125
 
126
126
  def test_appends_row_to_installer_shaped_user_attribute_list
@@ -130,8 +130,8 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
130
130
 
131
131
  model = read("app/models/user.rb")
132
132
 
133
- assert_includes(model, '[ :occupation , "occupation", :text_field ]')
134
- assert_includes(model, '[ :birthdate , "birthdate", :date_select ]')
133
+ assert_includes(model, '[ :occupation, :text_field ]')
134
+ assert_includes(model, '[ :birthdate, :date_select ]')
135
135
  refute_match(/\]\s*\n\s*\[\s*:occupation/, model)
136
136
 
137
137
  user_array_section = model[/@inline_forms_attribute_list \|\|=\s*\[(.|\n)*?\n\s*\]/]
@@ -150,7 +150,7 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
150
150
 
151
151
  assert_includes(out, "no inline_forms_attribute_list found")
152
152
  assert_includes(model, "def inline_forms_attribute_list")
153
- assert_includes(model, '[ :occupation , "occupation", :text_field ]')
153
+ assert_includes(model, '[ :occupation, :text_field ]')
154
154
  end
155
155
 
156
156
  def test_unknown_type_raises_thor_error_by_default
@@ -174,7 +174,7 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
174
174
  model = read("app/models/widget.rb")
175
175
  migration = read_single_addto_migration_for("widgets")
176
176
 
177
- assert_includes(model, '[ :payload , "payload", :unknown ]')
177
+ assert_includes(model, '[ :payload, :unknown ]')
178
178
  assert_includes(migration, "# add_column :widgets, :payload, :unknown")
179
179
  end
180
180
 
@@ -32,7 +32,7 @@ class InlineFormsGeneratorTest < Minitest::Test
32
32
  model = read("app/models/thing.rb")
33
33
  controller = read("app/controllers/things_controller.rb")
34
34
  routes = read("config/routes.rb")
35
- application_controller = read("app/controllers/application_controller.rb")
35
+ inline_forms_initializer = read("config/initializers/inline_forms.rb")
36
36
  migration = read_single_migration_for("things")
37
37
 
38
38
  assert_includes(model, "class Thing < ApplicationRecord")
@@ -44,8 +44,8 @@ class InlineFormsGeneratorTest < Minitest::Test
44
44
  refute_includes(model, "scope :inline_forms_search")
45
45
  assert_includes(model, "belongs_to :category")
46
46
  assert_includes(model, "has_many :photos")
47
- assert_includes(model, "[ :name , \"name\", :text_field ]")
48
- assert_includes(model, "[ :category , \"category\", :dropdown ]")
47
+ assert_includes(model, "[ :name, :text_field ]")
48
+ assert_includes(model, "[ :category, :dropdown ]")
49
49
 
50
50
  assert_includes(controller, "class ThingsController < InlineFormsController")
51
51
  assert_includes(controller, "set_tab :thing")
@@ -54,7 +54,7 @@ class InlineFormsGeneratorTest < Minitest::Test
54
54
  assert_includes(routes, "post 'revert', :on => :member")
55
55
  assert_includes(routes, "get 'list_versions', :on => :member")
56
56
 
57
- assert_includes(application_controller, "MODEL_TABS = %w(things ")
57
+ assert_includes(inline_forms_initializer, "MODEL_TABS = %w(things ")
58
58
 
59
59
  assert_includes(migration, "class InlineFormsCreateThings < ActiveRecord::Migration[8.1]")
60
60
  assert_includes(migration, "create_table :things do |t|")
@@ -91,7 +91,7 @@ class InlineFormsGeneratorTest < Minitest::Test
91
91
  model = read("app/models/mystery.rb")
92
92
  migration = read_single_migration_for("mysteries")
93
93
 
94
- assert_includes(model, "# [ :payload , \"payload\", :unknown ]")
94
+ assert_includes(model, "# [ :payload, :unknown ]")
95
95
  assert_includes(migration, "# t.unknown :payload")
96
96
  end
97
97
 
@@ -167,7 +167,7 @@ class InlineFormsGeneratorTest < Minitest::Test
167
167
  model = read("app/models/note.rb")
168
168
  migration = read_single_migration_for("notes")
169
169
 
170
- assert_includes(model, "[ :description , \"description\", :plain_text ]")
170
+ assert_includes(model, "[ :description, :plain_text ]")
171
171
  assert_includes(migration, "t.text :description")
172
172
  end
173
173
 
@@ -175,6 +175,7 @@ class InlineFormsGeneratorTest < Minitest::Test
175
175
 
176
176
  def build_destination_skeleton!
177
177
  mkdir_p("config")
178
+ mkdir_p("config/initializers")
178
179
  mkdir_p("app/controllers")
179
180
  mkdir_p("app/models")
180
181
  mkdir_p("db/migrate")
@@ -192,7 +193,17 @@ class InlineFormsGeneratorTest < Minitest::Test
192
193
  "app/controllers/application_controller.rb",
193
194
  <<~RUBY
194
195
  class ApplicationController < ActionController::Base
195
- ActionView::CompiledTemplates::MODEL_TABS = %w()
196
+ end
197
+ RUBY
198
+ )
199
+
200
+ # Matches the file the installer writes; the generator's `add_tab` step
201
+ # injects `<plural_route> ` tokens after the `MODEL_TABS = %w(` marker.
202
+ write(
203
+ "config/initializers/inline_forms.rb",
204
+ <<~RUBY
205
+ Rails.application.reloader.to_prepare do
206
+ MODEL_TABS = %w()
196
207
  end
197
208
  RUBY
198
209
  )
@@ -20,7 +20,7 @@ class PlainTextConfigurationTest < Minitest::Test
20
20
 
21
21
  def inline_forms_attribute_list
22
22
  [
23
- [:description, "description", :plain_text]
23
+ [:description, :plain_text]
24
24
  ]
25
25
  end
26
26
  end
@@ -40,7 +40,7 @@ class PlainTextConfigurationTest < Minitest::Test
40
40
 
41
41
  def inline_forms_attribute_list
42
42
  [
43
- [:description, "description", :plain_text]
43
+ [:description, :plain_text]
44
44
  ]
45
45
  end
46
46
  end
@@ -56,7 +56,7 @@ class PlainTextConfigurationTest < Minitest::Test
56
56
 
57
57
  def inline_forms_attribute_list
58
58
  [
59
- [:description, "description", :rich_text]
59
+ [:description, :rich_text]
60
60
  ]
61
61
  end
62
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.3
4
+ version: 8.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
@@ -17,7 +17,7 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 8.1.3
20
+ version: 8.1.4
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
23
  version: '9.0'
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 8.1.3
30
+ version: 8.1.4
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '9.0'
@@ -495,11 +495,12 @@ files:
495
495
  - inline_forms.gemspec
496
496
  - lib/generators/USAGE
497
497
  - lib/generators/assets/stylesheets/inline_forms_devise.css
498
+ - lib/generators/inline_forms_addto/USAGE
499
+ - lib/generators/inline_forms_addto/templates/add_columns_migration.erb
498
500
  - lib/generators/inline_forms_addto_generator.rb
499
501
  - lib/generators/inline_forms_attribute_overrides.rb
500
502
  - lib/generators/inline_forms_generator.rb
501
503
  - lib/generators/templates/_inline_forms_tabs.html.erb
502
- - lib/generators/templates/add_columns_migration.erb
503
504
  - lib/generators/templates/application_record.rb
504
505
  - lib/generators/templates/controller.erb
505
506
  - lib/generators/templates/migration.erb