forked from bootstrap-ruby/bootstrap_form
-
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.
Separation of inputs into separate more maintainable files (bootstrap…
…-ruby#518) * TextField example separation * Move all form inputs to separate files * Revert Gemfile * Add rich_text_area support back in, rebase against master * Add changelog entry * Only include `rich_text_area` if Rails version >= 6 * Add an unwrapped field test
- Loading branch information
Showing
53 changed files
with
863 additions
and
352 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
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
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,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module BootstrapForm | ||
module ActionViewExtensions | ||
# This module creates BootstrapForm wrappers around the default form_with | ||
# and form_for methods | ||
# | ||
# Example: | ||
# | ||
# bootstrap_form_for @user do |f| | ||
# f.text_field :name | ||
# end | ||
# | ||
# Example: | ||
# | ||
# bootstrap_form_with model: @user do |f| | ||
# f.text_field :name | ||
# end | ||
module FormHelper | ||
def bootstrap_form_for(record, options={}, &block) | ||
options.reverse_merge!(builder: BootstrapForm::FormBuilder) | ||
|
||
options = process_options(options) | ||
|
||
with_bootstrap_form_field_error_proc do | ||
form_for(record, options, &block) | ||
end | ||
end | ||
|
||
def bootstrap_form_with(options={}, &block) | ||
options.reverse_merge!(builder: BootstrapForm::FormBuilder) | ||
|
||
options = process_options(options) | ||
|
||
with_bootstrap_form_field_error_proc do | ||
form_with(options, &block) | ||
end | ||
end | ||
|
||
def bootstrap_form_tag(options={}, &block) | ||
options[:acts_like_form_tag] = true | ||
|
||
bootstrap_form_for("", options, &block) | ||
end | ||
|
||
private | ||
|
||
def process_options(options) | ||
options[:html] ||= {} | ||
options[:html][:role] ||= "form" | ||
|
||
options[:layout] == :inline && | ||
options[:html][:class] = [options[:html][:class], "form-inline"].compact.join(" ") | ||
|
||
options | ||
end | ||
|
||
def with_bootstrap_form_field_error_proc | ||
original_proc = ActionView::Base.field_error_proc | ||
ActionView::Base.field_error_proc = BootstrapForm.field_error_proc | ||
yield | ||
ensure | ||
ActionView::Base.field_error_proc = original_proc | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveSupport.on_load(:action_view) do | ||
include BootstrapForm::ActionViewExtensions::FormHelper | ||
end |
This file was deleted.
Oops, something went wrong.
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 | ||
|
||
require "rails/railtie" | ||
|
||
module BootstrapForm | ||
class Engine < Rails::Engine | ||
config.eager_load_namespaces << BootstrapForm | ||
config.autoload_paths << File.expand_path("lib", __dir__) | ||
end | ||
end |
Oops, something went wrong.