-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Description: | ||
Install the simple form bulma config file in your app. | ||
|
||
Example: | ||
bin/rails generate simple_form:theme:bulma install | ||
|
||
This will create: | ||
config/initializers/simple_form_bulma.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class SimpleForm::Theme::BulmaGenerator < Rails::Generators::NamedBase | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
desc 'Copy the bulma initializer file for simple_form' | ||
def copy_initializer_file | ||
template 'config/initializers/simple_form_bulma.rb', 'config/initializers/simple_form_bulma.rb' | ||
end | ||
end |
126 changes: 126 additions & 0 deletions
126
lib/generators/simple_form/theme/bulma/templates/config/initializers/simple_form_bulma.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# frozen_string_literal: true | ||
|
||
# Use this setup block to configure all options available in SimpleForm. | ||
SimpleForm.setup do |config| | ||
# Default class for buttons | ||
config.button_class = 'button' | ||
|
||
# Define the default class of the input wrapper of the boolean input. | ||
config.boolean_label_class = 'checkbox' | ||
|
||
# How the label text should be generated altogether with the required text. | ||
config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" } | ||
|
||
# Define the way to render check boxes / radio buttons with labels. | ||
config.boolean_style = :inline | ||
|
||
# You can wrap each item in a collection of radio/check boxes with a tag | ||
config.item_wrapper_tag = :div | ||
|
||
# Defines if the default input wrapper class should be included in radio | ||
# collection wrappers. | ||
config.include_default_input_wrapper_class = false | ||
|
||
# CSS class to add for error notification helper. | ||
config.error_notification_class = 'notification is-danger' | ||
|
||
# Method used to tidy up errors. Specify any Rails Array method. | ||
# :first lists the first message for each field. | ||
# :to_sentence to list all errors for each field. | ||
config.error_method = :to_sentence | ||
|
||
# add validation classes to `input_field` | ||
config.input_field_error_class = 'is-danger' | ||
config.input_field_valid_class = 'is-success' | ||
|
||
# vertical forms | ||
# | ||
# bulma vertical default_wrapper | ||
config.wrappers :vertical_form, tag: 'div', class: 'field' do |b| | ||
b.use :html5 | ||
b.use :placeholder | ||
b.optional :maxlength | ||
b.optional :minlength | ||
b.optional :pattern | ||
b.optional :min_max | ||
b.optional :readonly | ||
b.use :label, class: 'label' | ||
b.use :input, class: 'input', wrap_with: { tag: 'div', class: 'control' }, error_class: 'is-danger', valid_class: 'is-success' | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } | ||
end | ||
|
||
# bulma vertical select_form | ||
config.wrappers :select_form, tag: 'div', class: 'control' do |b| | ||
b.use :html5 | ||
b.use :placeholder | ||
b.optional :pattern | ||
b.optional :readonly | ||
b.use :input, wrap_with: { tag: 'div', class: 'select' } | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } | ||
end | ||
|
||
# bulma extension vertical input for boolean | ||
config.wrappers :vertical_boolean, tag: 'div', class: 'field' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.use :input, class: 'is-checkradio is-info' | ||
b.use :label | ||
# b.wrapper :form_check_wrapper, tag: 'div', class: 'control' do |bb| | ||
# bb.use :input, wrap_with: { tag: 'label', class: 'checkbox' } | ||
# bb.use :label, class: 'checkbox' | ||
# bb.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' } | ||
# bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } | ||
# end | ||
end | ||
|
||
## vertical input for radio buttons and check boxes | ||
config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| | ||
ba.use :label_text | ||
end | ||
b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } | ||
end | ||
|
||
## bulma vertical file input | ||
config.wrappers :vertical_file, tag: 'div', class: 'file' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.use :input, class: 'file-input', wrap_with: { tag: 'label', class: 'file-label' } | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' } | ||
end | ||
|
||
## bulma vertical multi select | ||
config.wrappers :vertical_multi_select, tag: 'div', class: 'field' do |b| | ||
b.use :html5 | ||
b.optional :readonly | ||
b.use :label, class: 'label' | ||
b.wrapper tag: 'div', class: 'control' do |ba| | ||
ba.use :input, class: 'input', error_class: 'is-danger', valid_class: 'is-success' | ||
end | ||
b.use :full_error, wrap_with: { tag: 'div', class: 'is-danger' } | ||
b.use :hint, wrap_with: { tag: 'small', class: 'help' } | ||
end | ||
|
||
# The default wrapper to be used by the FormBuilder. | ||
config.default_wrapper = :vertical_form | ||
|
||
# Custom wrappers for input types. This should be a hash containing an input | ||
# type as key and the wrapper that will be used for all inputs with specified type. | ||
config.wrapper_mappings = { | ||
boolean: :vertical_boolean, | ||
check_boxes: :vertical_collection, | ||
date: :vertical_multi_select, | ||
datetime: :vertical_multi_select, | ||
file: :vertical_file, | ||
radio_buttons: :vertical_collection, | ||
range: :vertical_range, | ||
time: :vertical_multi_select | ||
} | ||
end |
18 changes: 18 additions & 0 deletions
18
test/lib/generators/simple_form/theme/simple_form/theme/bulma_generator_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'generators/simple_form/theme/bulma/bulma_generator' | ||
|
||
module SimpleForm::Theme | ||
class SimpleForm::Theme::BulmaGeneratorTest < Rails::Generators::TestCase | ||
tests SimpleForm::Theme::BulmaGenerator | ||
destination Rails.root.join('tmp/generators') | ||
setup :prepare_destination | ||
|
||
test 'generator runs without errors' do | ||
assert_nothing_raised do | ||
run_generator ['arguments'] | ||
end | ||
end | ||
end | ||
end |