Skip to content

Commit

Permalink
refactored wrapper_html_options into smaller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Mar 18, 2012
1 parent b9dafa3 commit d2be26a
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/formtastic/inputs/base/wrapping.rb
Expand Up @@ -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
Expand Down

0 comments on commit d2be26a

Please sign in to comment.