Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored wrapper_html_options into smaller methods

  • Loading branch information...
commit d2be26aa2aa48756bafc3866190af1233a3d7dcf 1 parent b9dafa3
@justinfrench justinfrench authored
Showing with 25 additions and 20 deletions.
  1. +25 −20 lib/formtastic/inputs/base/wrapping.rb
View
45 lib/formtastic/inputs/base/wrapping.rb
@@ -14,29 +14,34 @@ def input_wrapping(&block)
end
def wrapper_html_options
- opts = (options[:wrapper_html] || {}).dup
- opts[:class] =
- case opts[:class]
- when Array
- opts[:class].dup
- when nil
- []
- else
- [opts[:class].to_s]
- end
- opts[:class] << as
- opts[:class] << "input"
- opts[:class] << "error" if errors?
- opts[:class] << "optional" if optional?
- opts[:class] << "required" if required?
- opts[:class] << "autofocus" if autofocus?
- opts[:class] = opts[:class].join(' ')
-
- opts[:id] ||= wrapper_dom_id
-
+ opts = wrapper_html_options_raw
+ opts[:class] = wrapper_classes
+ opts[:id] ||= wrapper_dom_id
opts
end
+ def wrapper_html_options_raw
+ (options[:wrapper_html] || {}).dup
+ end
+
+ def wrapper_classes_raw
+ classes = wrapper_html_options_raw[:class] || []
+ return classes.dup if classes.is_a?(Array)
+ return [classes]
+ end
+
+ def wrapper_classes
+ classes = wrapper_classes_raw
+ classes << as
+ classes << "input"
+ classes << "error" if errors?
+ classes << "optional" if optional?
+ classes << "required" if required?
+ classes << "autofocus" if autofocus?
+
+ classes.join(' ')
+ end
+
def wrapper_dom_id
@wrapper_dom_id ||= "#{dom_id.to_s.gsub((association_primary_key || method).to_s, sanitized_method_name.to_s)}_input"
end
Please sign in to comment.
Something went wrong with that request. Please try again.