From 7a24b5d184eae6b2e499ae812136118d72e4d4f0 Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Wed, 5 Nov 2025 12:52:38 -0500 Subject: [PATCH 1/5] Add segmented control input --- .../app/inputs/segmented_control_input.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb diff --git a/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb new file mode 100644 index 00000000..ccf8cb82 --- /dev/null +++ b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +# SegmentedControlInput is a custom input type for SimpleForm that renders a radio group as an optics segmented control +# +# Options: +# :size (:small, :medium, :large) - renders the control at different sizes +# :full_width - renders the control to take the full width of its container +# +# Usage: +# <%= f.input :my_field, as: :segmented_control, collection: collection_options %> +# <%= f.input :my_field, as: :segmented_control, collection: collection_options, size: :small %> +# <%= f.input :my_field, as: :segmented_control, collection: collection_options, disabled: true %> +# <%= f.input :my_field, as: :segmented_control, collection: collection_options, full_width: true %> +class SegmentedControlInput < SimpleForm::Inputs::CollectionRadioButtonsInput + def input_type + 'radio_buttons' + end + + def input_options + options = super + options[:item_wrapper_tag] = false + options[:collection_wrapper_tag] = 'div' + options[:collection_wrapper_class] = collection_wrapper_classes + options[:item_label_class] = 'segmented-control__label' + options + end + + def input_html_options + super.tap do |options| + options[:class].delete('form-control') + end + end + + def input_html_classes + classes = super + classes.push('segmented-control__input') + classes + end + + private + + def collection_wrapper_classes + class_names( + 'segmented-control', + options[:class], + "segmented-control--#{options[:size] || 'large'}": options[:size].present?, + 'segmented-control--full-width': options[:full_width].present? + ) + end +end From 013693b95871fcf50cbf7ba873cffe52ec846fee Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Wed, 5 Nov 2025 12:53:05 -0500 Subject: [PATCH 2/5] Add spec for simple form and replace deprecated method --- .../rolemodel/saas/devise/devise_generator.rb | 2 +- .../simple_form/simple_form_generator.rb | 4 +++- .../rolemodel/simple_form_generator_spec.rb | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/generators/rolemodel/simple_form_generator_spec.rb diff --git a/lib/generators/rolemodel/saas/devise/devise_generator.rb b/lib/generators/rolemodel/saas/devise/devise_generator.rb index 2f9afdef..54629258 100644 --- a/lib/generators/rolemodel/saas/devise/devise_generator.rb +++ b/lib/generators/rolemodel/saas/devise/devise_generator.rb @@ -15,7 +15,7 @@ def install_devise # Devise tries to install bcrypt, but it fails because the bundle command # is run using the wrong platform causing the native extension to fail. # Using clean env fixes this. - Bundler.with_clean_env do + Bundler.with_unbundled_env do run 'bundle add devise' end diff --git a/lib/generators/rolemodel/simple_form/simple_form_generator.rb b/lib/generators/rolemodel/simple_form/simple_form_generator.rb index 9e9c443c..60a43701 100644 --- a/lib/generators/rolemodel/simple_form/simple_form_generator.rb +++ b/lib/generators/rolemodel/simple_form/simple_form_generator.rb @@ -6,7 +6,9 @@ class SimpleFormGenerator < Rails::Generators::Base source_root File.expand_path('templates', __dir__) def add_gem - run 'bundle add simple_form' + Bundler.with_unbundled_env do + run 'bundle add simple_form' + end end def add_files diff --git a/spec/generators/rolemodel/simple_form_generator_spec.rb b/spec/generators/rolemodel/simple_form_generator_spec.rb new file mode 100644 index 00000000..8674a112 --- /dev/null +++ b/spec/generators/rolemodel/simple_form_generator_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +RSpec.describe Rolemodel::SimpleFormGenerator, type: :generator do + before { run_generator_against_test_app } + + it 'generates a simple form initializer' do + assert_file 'config/initializers/simple_form.rb' + end + + it 'generates custom input files' do + assert_file 'app/inputs/collection_check_boxes_input.rb' + assert_file 'app/inputs/collection_select_input.rb' + assert_file 'app/inputs/grouped_collection_select_input.rb' + assert_file 'app/inputs/segmented_control_input.rb' + assert_file 'app/inputs/switch_checkbox_input.rb' + assert_file 'app/inputs/tailored_select_input.rb' + end +end From 37838cc9dc2667baf20f3d8462b1bbc6f92f65d4 Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Wed, 5 Nov 2025 12:53:39 -0500 Subject: [PATCH 3/5] Update Optics related inputs to specify their version number availability --- .../simple_form/templates/app/inputs/segmented_control_input.rb | 2 +- .../simple_form/templates/app/inputs/switch_checkbox_input.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb index ccf8cb82..0dd2c55f 100644 --- a/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb +++ b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# SegmentedControlInput is a custom input type for SimpleForm that renders a radio group as an optics segmented control +# SegmentedControlInput is a custom input type for SimpleForm that renders a radio group as an optics (v2.2.0+) segmented control # # Options: # :size (:small, :medium, :large) - renders the control at different sizes diff --git a/lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb b/lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb index 383eb266..413c13f4 100644 --- a/lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb +++ b/lib/generators/rolemodel/simple_form/templates/app/inputs/switch_checkbox_input.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# SwitchCheckboxInput is a custom input type for SimpleForm that renders a checkbox as a switch control +# SwitchCheckboxInput is a custom input type for SimpleForm that renders a checkbox as an optics (v0.5.0+) switch control # # Options: # :small - renders a smaller switch control From cf551f0ee779be01653b5b542eaf3cb78d2d0a0b Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Wed, 5 Nov 2025 12:55:21 -0500 Subject: [PATCH 4/5] Bump version number --- Gemfile.lock | 2 +- lib/rolemodel_rails/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8faca137..eec0d2f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rolemodel_rails (0.21.0) + rolemodel_rails (0.22.0) GEM remote: https://rubygems.org/ diff --git a/lib/rolemodel_rails/version.rb b/lib/rolemodel_rails/version.rb index 9c255072..0754cd45 100644 --- a/lib/rolemodel_rails/version.rb +++ b/lib/rolemodel_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RolemodelRails - VERSION = '0.21.0' + VERSION = '0.22.0' end From 836a95cc2f390b0372dc97d9955c6f72473b899e Mon Sep 17 00:00:00 2001 From: Jeremy Walton Date: Wed, 5 Nov 2025 13:10:11 -0500 Subject: [PATCH 5/5] Remove unnecessary option --- .../simple_form/templates/app/inputs/segmented_control_input.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb index 0dd2c55f..ab19b84e 100644 --- a/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb +++ b/lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb @@ -43,7 +43,7 @@ def collection_wrapper_classes class_names( 'segmented-control', options[:class], - "segmented-control--#{options[:size] || 'large'}": options[:size].present?, + "segmented-control--#{options[:size]}": options[:size].present?, 'segmented-control--full-width': options[:full_width].present? ) end