Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rolemodel_rails (0.21.0)
rolemodel_rails (0.22.0)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rolemodel/saas/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# 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
# :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]}": options[:size].present?,
'segmented-control--full-width': options[:full_width].present?
)
end
end
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rolemodel_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RolemodelRails
VERSION = '0.21.0'
VERSION = '0.22.0'
end
18 changes: 18 additions & 0 deletions spec/generators/rolemodel/simple_form_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -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