2011-09-02 16:14:23 -04:00
|
|
|
module SimpleForm
|
|
|
|
module Wrappers
|
2011-09-03 03:15:47 -04:00
|
|
|
# `Root` is the root wrapper for all components. It is special cased to
|
|
|
|
# always have a namespace and to add special html classes.
|
2011-09-02 16:14:23 -04:00
|
|
|
class Root < Many
|
2011-12-04 08:57:12 -05:00
|
|
|
attr_reader :options
|
|
|
|
|
2011-09-02 16:14:23 -04:00
|
|
|
def initialize(*args)
|
|
|
|
super(:wrapper, *args)
|
2012-01-10 21:39:20 -05:00
|
|
|
@options = @defaults.except(:tag, :class, :error_class, :hint_class)
|
2011-12-04 08:57:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def render(input)
|
|
|
|
input.options.reverse_merge!(@options)
|
|
|
|
super
|
2011-09-02 16:14:23 -04:00
|
|
|
end
|
|
|
|
|
2011-09-04 05:31:24 -04:00
|
|
|
# Provide a fallback if name cannot be found.
|
|
|
|
def find(name)
|
2012-01-11 15:12:49 -05:00
|
|
|
super || SimpleForm::Wrappers::Many.new(name, [name])
|
2011-09-04 05:31:24 -04:00
|
|
|
end
|
|
|
|
|
2011-09-02 16:14:23 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def html_classes(input, options)
|
2011-09-02 17:34:02 -04:00
|
|
|
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
2011-12-05 13:03:41 -05:00
|
|
|
css += input.html_classes
|
2011-09-02 17:34:02 -04:00
|
|
|
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
2012-01-10 16:00:14 -05:00
|
|
|
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
2011-09-11 17:46:47 -04:00
|
|
|
css
|
2011-09-02 16:14:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-09-11 17:46:47 -04:00
|
|
|
end
|