view_component-form 0.2.9 → 0.2.11

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: 124aec584d29d1b7d181aa25ee3293d0719d9cf4c531f7a0d5cb5859b6be734b
4
- data.tar.gz: b78538a52578b141f4c6d8eb45a92d80d8f7bf4f693a63acd9ce36fce80d8921
3
+ metadata.gz: bbaba838148ba0ba79c3cebbcd9b7ed05cbce8cd560387c9c2ffbf4560105bd6
4
+ data.tar.gz: 06b8522d30a3d9395c6041f92377b53bef7d1d0a45a695fc9de056bbb5a87168
5
5
  SHA512:
6
- metadata.gz: d18ac72e6c391c0466be730ab40c6d61ebbf807bc7d2f6a6fb53e35d6f9a23f223a0250e7cf87c6ad5bef507c84e63b141f21af1f2bbcd5baaca050b3b4ab904
7
- data.tar.gz: 31353a6e4c1ff4547981b311229cfdfd01d590601a95b38688d357f4db02c5b2ccaed71cffdf1db1290d3a5bb515132eeecd2c1c0881cb00d5eae0da349b966d
6
+ metadata.gz: 4690faaca7948671849a45d396f9d1c18959c21168cee26bf010ee875086a6bbc2bb775e77e18115eb8a8defa3bdd8e9d39f1a00c988066b6f9750a440a27a8d
7
+ data.tar.gz: 873c9bd135115de3b95d19f32923dc0e24b6646e1a30b1d3512584c51016406dbb3661da3409a4b9233be13b67bd81a0138368190ae7a00eab40108e1af3e419
data/CHANGELOG.md CHANGED
@@ -5,7 +5,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
- Nothing yet.
8
+ Nothing yet
9
+
10
+ ## [0.2.11] - 2025-04-05
11
+ ### Fixed
12
+ - Fix Rails 8 integration (#189)
13
+
14
+ ## [0.2.10] - 2025-03-17 (yanked)
15
+ ### Added
16
+ - Support for Ruby 3.4 (#186)
17
+ ### Removed
18
+ - Drop Ruby 3.0 support (#186)
19
+ - Drop Rails 6.1 support (#186)
20
+ ### Fixed
21
+ - Add `text_area` alias to `textarea` helper to follow Rails 8.0 change (#181)
9
22
 
10
23
  ## [0.2.9] - 2024-11-09
11
24
  ### Added
@@ -124,7 +137,9 @@ Nothing yet.
124
137
  - Add CHANGELOG (#50)
125
138
  - Add CI (#2)
126
139
 
127
- [Unreleased]: https://github.com/pantographe/view_component-form/compare/v0.2.9...HEAD
140
+ [Unreleased]: https://github.com/pantographe/view_component-form/compare/v0.2.11...HEAD
141
+ [0.2.11]: https://github.com/pantographe/view_component-form/compare/v0.2.10...v0.2.11
142
+ [0.2.10]: https://github.com/pantographe/view_component-form/compare/v0.2.9...v0.2.10
128
143
  [0.2.9]: https://github.com/pantographe/view_component-form/compare/v0.2.8...v0.2.9
129
144
  [0.2.8]: https://github.com/pantographe/view_component-form/compare/v0.2.7...v0.2.8
130
145
  [0.2.7]: https://github.com/pantographe/view_component-form/compare/v0.2.6...v0.2.7
data/README.md CHANGED
@@ -13,8 +13,8 @@ Development of this gem is sponsored by:
13
13
 
14
14
  This gem is tested on:
15
15
 
16
- - Rails 6.1+ (with or without ActionText)
17
- - Ruby 3.0+
16
+ - Rails 7.0+ (with or without ActionText)
17
+ - Ruby 3.1+
18
18
 
19
19
  ## Installation
20
20
 
@@ -100,7 +100,7 @@ Then use ActionView form builder helpers as you would normally:
100
100
  <%= f.label :password %> <%# renders a ViewComponent::Form::LabelComponent %>
101
101
  <%= f.password_field :password, aria: { describedby: f.field_id(:password, :description) } %>
102
102
  <%# renders a ViewComponent::Form::PasswordFieldComponent %>
103
- <div id="<%= f.field_id(:title, :description) %>">
103
+ <div id="<%= f.field_id(:password, :description) %>">
104
104
  <%= f.hint :password, 'The password should be at least 8 characters long' %>
105
105
  <%# renders a ViewComponent::Form::HintComponent %>
106
106
  <%= f.error_message :password %> <%# renders a ViewComponent::Form::ErrorMessageComponent %>
@@ -358,9 +358,9 @@ The following helpers are currently supported by `ViewComponent::Form`.
358
358
 
359
359
  ### `ActionView::Helpers::FormBuilder`
360
360
 
361
- **Supported:** `button` `check_box` `collection_check_boxes` `collection_radio_buttons` `collection_select` `color_field` `date_field` `date_select` `datetime_field` `datetime_local_field` `datetime_select` `email_field` `fields` `fields_for` `file_field` `field_id` `grouped_collection_select` `hidden_field` `month_field` `number_field` `password_field` `phone_field` `radio_button` `range_field` `search_field` `select` `submit` `telephone_field` `text_area` `text_field` `time_field` `time_select` `time_zone_select` `to_model` `to_partial_path` `url_field` `week_field` `weekday_select`
361
+ **Supported:** `button` `check_box` `collection_check_boxes` `collection_radio_buttons` `collection_select` `color_field` `date_field` `date_select` `datetime_field` `datetime_local_field` `datetime_select` `email_field` `fields` `fields_for` `file_field` `field_id` `grouped_collection_select` `hidden_field` `month_field` `number_field` `password_field` `phone_field` `radio_button` `range_field` `search_field` `select` `submit` `telephone_field` `textarea` (formerly `text_area` before Rails 8) `text_field` `time_field` `time_select` `time_zone_select` `to_model` `to_partial_path` `url_field` `week_field` `weekday_select`
362
362
 
363
- **Partially supported:** `label` (blocks not supported) `rich_text_area` (untested)
363
+ **Partially supported:** `label` (blocks not supported) `rich_textarea` (formerly`rich_text_area` before Rails 8) (untested)
364
364
 
365
365
  **Unsupported for now:** `field_name`
366
366
 
@@ -7,8 +7,6 @@ module ViewComponent
7
7
  attr_accessor :default_options
8
8
  end
9
9
 
10
- include ClassNamesHelper if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("6.1")
11
-
12
10
  attr_reader :form, :object_name, :options
13
11
 
14
12
  delegate :object, to: :form, allow_nil: true
@@ -41,6 +41,16 @@ module ViewComponent
41
41
  ).render(&element_proc)
42
42
  end
43
43
 
44
+ # See: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/actionview/lib/action_view/helpers/tags/label.rb#L64
45
+ def builder
46
+ @builder ||= begin
47
+ tag_value = options.delete("value")
48
+
49
+ ActionView::Helpers::Tags::Label::LabelBuilder.new(@view_context, object_name, method_name, object, tag_value)
50
+ end
51
+ end
52
+ delegate :translation, to: :builder
53
+
44
54
  protected
45
55
 
46
56
  def set_html_options!
@@ -32,18 +32,10 @@ module ViewComponent
32
32
  .map(&:upcase_first)
33
33
  end
34
34
 
35
- if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("6.1")
36
- def method_errors?
37
- return false unless object_errors
35
+ def method_errors?
36
+ return false unless object_errors
38
37
 
39
- (object_errors.attribute_names & object_method_names).any?
40
- end
41
- else
42
- def method_errors?
43
- return false unless object_errors
44
-
45
- (object_errors.keys & object_method_names).any?
46
- end
38
+ (object_errors.attribute_names & object_method_names).any?
47
39
  end
48
40
 
49
41
  def value
@@ -6,9 +6,7 @@ module ViewComponent
6
6
  self.tag_klass = ActionView::Helpers::Tags::FileField
7
7
 
8
8
  def before_render
9
- if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("7.0")
10
- @options = { include_hidden: multiple_file_field_include_hidden }.merge!(options)
11
- end
9
+ @options = { include_hidden: multiple_file_field_include_hidden }.merge!(options)
12
10
  @options = convert_direct_upload_option_to_url(@options.dup)
13
11
 
14
12
  super
@@ -28,7 +28,7 @@ module ViewComponent
28
28
  options).render
29
29
  end
30
30
 
31
- # See: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/actionview/lib/action_view/helpers/tags/label.rb#L48
31
+ # See: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/actionview/lib/action_view/helpers/tags/label.rb#L64
32
32
  def builder
33
33
  @builder ||= begin
34
34
  tag_value = options.delete("value")
@@ -13,18 +13,14 @@ module ViewComponent
13
13
  set_html_options!
14
14
  end
15
15
 
16
- def call # rubocop:disable Metrics/MethodLength
17
- if Rails::VERSION::MAJOR >= 7 # rubocop:disable Style/GuardClause
18
- ActionView::Helpers::Tags::WeekdaySelect.new(
19
- object_name,
20
- method_name,
21
- @view_context,
22
- options,
23
- html_options
24
- ).render
25
- else
26
- raise NotImplementedError, "#{self.class} is only available in Rails >= 7"
27
- end
16
+ def call
17
+ ActionView::Helpers::Tags::WeekdaySelect.new(
18
+ object_name,
19
+ method_name,
20
+ @view_context,
21
+ options,
22
+ html_options
23
+ ).render
28
24
  end
29
25
 
30
26
  protected
@@ -14,8 +14,8 @@ class <%= class_name %> < ViewComponent::Form::Builder
14
14
  # All standard Rails form helpers
15
15
  # include ViewComponent::Form::Helpers::Rails
16
16
 
17
- # Backports of Rails 7 form helpers (can be removed if you're running Rails >= 7)
18
- # include ViewComponent::Form::Helpers::Rails7Backports
17
+ # Adds support for Rails 8
18
+ # include ViewComponent::Form::Helpers::Rails8
19
19
 
20
20
  # Additional form helpers provided by ViewComponent::Form
21
21
  # include ViewComponent::Form::Helpers::Custom
@@ -6,7 +6,9 @@ module ViewComponent
6
6
  include ViewComponent::Form::Renderer
7
7
  include ViewComponent::Form::ValidationContext
8
8
  include ViewComponent::Form::Helpers::Rails
9
- include ViewComponent::Form::Helpers::Rails7Backports if ::Rails::VERSION::MAJOR < 7
9
+ if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("8.0")
10
+ include ViewComponent::Form::Helpers::Rails8
11
+ end
10
12
  include ViewComponent::Form::Helpers::Custom
11
13
  end
12
14
  end
@@ -7,9 +7,12 @@ module ViewComponent
7
7
  module Rails
8
8
  # rubocop:disable Metrics/MethodLength
9
9
  def self.included(base)
10
- base.class_eval do
10
+ base.class_eval do # rubocop:disable Metrics/BlockLength
11
11
  (field_helpers - %i[
12
+ text_area
13
+ textarea
12
14
  check_box
15
+ checkbox
13
16
  datetime_field
14
17
  datetime_local_field
15
18
  fields
@@ -31,11 +34,16 @@ module ViewComponent
31
34
  end # end
32
35
  RUBY_EVAL
33
36
  end
37
+
34
38
  alias_method :phone_field, :telephone_field
35
39
  end
36
40
  end
37
41
  # rubocop:enable Metrics/MethodLength
38
42
 
43
+ def text_area(method, options = {})
44
+ render_component(:text_area, @object_name, method, objectify_options(options))
45
+ end
46
+
39
47
  # See: https://github.com/rails/rails/blob/33d60cb02dcac26d037332410eabaeeb0bdc384c/actionview/lib/action_view/helpers/form_helper.rb#L2280
40
48
  def label(method, text = nil, options = {}, &block)
41
49
  render_component(:label, @object_name, method, text, objectify_options(options), &block)
@@ -49,9 +57,7 @@ module ViewComponent
49
57
  alias datetime_local_field datetime_field
50
58
 
51
59
  def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
52
- render_component(
53
- :check_box, @object_name, method, checked_value, unchecked_value, objectify_options(options)
54
- )
60
+ render_component(:check_box, @object_name, method, checked_value, unchecked_value, objectify_options(options))
55
61
  end
56
62
 
57
63
  def radio_button(method, tag_value, options = {})
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Form
5
+ module Helpers
6
+ # Rails 8.0 changed the spelling of a couple form builder methods while adding aliases
7
+ # for backward compatibility. This module adds those new methods.
8
+ #
9
+ # https://github.com/rails/rails/blob/8-0-stable/actionview/CHANGELOG.md#rails-800beta1-september-26-2024
10
+ module Rails8
11
+ def textarea(method, options = {})
12
+ render_component(:text_area, @object_name, method, objectify_options(options))
13
+ end
14
+
15
+ def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0")
16
+ render_component(:check_box, @object_name, method, checked_value, unchecked_value, objectify_options(options))
17
+ end
18
+
19
+ def collection_checkboxes(method, collection, value_method, text_method, options = {}, html_options = {}, # rubocop:disable Metrics/ParameterLists
20
+ &block)
21
+ render_component(
22
+ :collection_check_boxes, @object_name, method, collection, value_method, text_method,
23
+ objectify_options(options), @default_html_options.merge(html_options), &block
24
+ )
25
+ end
26
+
27
+ if defined?(ActionView::Helpers::Tags::ActionText)
28
+ def rich_textarea(method, options = {})
29
+ render_component(:rich_text_area, @object_name, method, objectify_options(options))
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -4,6 +4,10 @@ require "action_controller"
4
4
  require "action_controller/test_case"
5
5
  require "action_view"
6
6
 
7
+ class TestView < ActionView::Base
8
+ include ActionText::TagHelper if defined?(ActionText)
9
+ end
10
+
7
11
  module ViewComponent
8
12
  module Form
9
13
  module TestHelpers
@@ -15,18 +19,10 @@ module ViewComponent
15
19
  :user
16
20
  end
17
21
 
18
- if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("6.1")
19
- def template
20
- lookup_context = ActionView::LookupContext.new(ActionController::Base.view_paths)
21
-
22
- ActionView::Base.new(lookup_context, {}, ApplicationController.new)
23
- end
24
- else
25
- def template
26
- lookup_context = ActionView::LookupContext.new(ActionController::Base.view_paths)
22
+ def template
23
+ lookup_context = ActionView::LookupContext.new(ActionController::Base.view_paths)
27
24
 
28
- ActionView::Base.new(lookup_context, {})
29
- end
25
+ TestView.new(lookup_context, {}, ApplicationController.new)
30
26
  end
31
27
  end
32
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ViewComponent
4
4
  module Form
5
- VERSION = "0.2.9"
5
+ VERSION = "0.2.11"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pantographe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-09 00:00:00.000000000 Z
11
+ date: 2025-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.0
19
+ version: 7.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '8.1'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 6.1.0
29
+ version: 7.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8.1'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 6.1.0
39
+ version: 7.0.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '8.1'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 6.1.0
49
+ version: 7.0.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '8.1'
@@ -135,12 +135,11 @@ files:
135
135
  - lib/generators/vcf/builder/templates/builder.rb.erb
136
136
  - lib/view_component/form.rb
137
137
  - lib/view_component/form/builder.rb
138
- - lib/view_component/form/class_names_helper.rb
139
138
  - lib/view_component/form/configuration.rb
140
139
  - lib/view_component/form/engine.rb
141
140
  - lib/view_component/form/helpers/custom.rb
142
141
  - lib/view_component/form/helpers/rails.rb
143
- - lib/view_component/form/helpers/rails_7_backports.rb
142
+ - lib/view_component/form/helpers/rails8.rb
144
143
  - lib/view_component/form/renderer.rb
145
144
  - lib/view_component/form/test_helpers.rb
146
145
  - lib/view_component/form/validation_context.rb
@@ -154,7 +153,7 @@ metadata:
154
153
  source_code_uri: https://github.com/pantographe/view_component-form
155
154
  bug_tracker_uri: https://github.com/pantographe/view_component-form/issues
156
155
  rubygems_mfa_required: 'true'
157
- post_install_message:
156
+ post_install_message:
158
157
  rdoc_options: []
159
158
  require_paths:
160
159
  - lib
@@ -170,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
169
  version: '0'
171
170
  requirements: []
172
171
  rubygems_version: 3.5.22
173
- signing_key:
172
+ signing_key:
174
173
  specification_version: 4
175
174
  summary: Rails FormBuilder for ViewComponent
176
175
  test_files: []
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Backport of https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-class_names
4
- # :nocov:
5
- module ViewComponent
6
- module Form
7
- module ClassNamesHelper
8
- # rubocop:disable Metrics/CyclomaticComplexity
9
- # rubocop:disable Metrics/MethodLength
10
- def build_tag_values(*args)
11
- tag_values = []
12
-
13
- args.each do |tag_value|
14
- case tag_value
15
- when Hash
16
- tag_value.each do |key, val|
17
- tag_values << key.to_s if val && key.present?
18
- end
19
- when Array
20
- tag_values.concat build_tag_values(*tag_value)
21
- else
22
- tag_values << tag_value.to_s if tag_value.present?
23
- end
24
- end
25
-
26
- tag_values
27
- end
28
- # rubocop:enable Metrics/CyclomaticComplexity
29
- # rubocop:enable Metrics/MethodLength
30
-
31
- def class_names(*args)
32
- tokens = build_tag_values(*args).flat_map { |value| value.to_s.split(/\s+/) }.uniq
33
-
34
- safe_join(tokens, " ")
35
- end
36
- end
37
- end
38
- end
39
- # :nocov:
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- module Form
5
- module Helpers
6
- module Rails7Backports
7
- def field_id(method_name, *suffixes, namespace: @options[:namespace], index: @index)
8
- object_name = object_name.model_name.singular if object_name.respond_to?(:model_name)
9
-
10
- sanitized_object_name = object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").delete_suffix("_")
11
-
12
- sanitized_method_name = method_name.to_s.delete_suffix("?")
13
-
14
- [
15
- namespace,
16
- sanitized_object_name.presence,
17
- (index unless sanitized_object_name.empty?),
18
- sanitized_method_name,
19
- *suffixes
20
- ].tap(&:compact!).join("_")
21
- end
22
- end
23
- end
24
- end
25
- end