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
|
|
|
|
def initialize(*args)
|
|
|
|
super(:wrapper, *args)
|
|
|
|
end
|
|
|
|
|
2011-09-04 05:31:24 -04:00
|
|
|
# Provide a fallback if name cannot be found.
|
|
|
|
def find(name)
|
|
|
|
super || SingleForm::Wrappers::Many.new(name, [name])
|
|
|
|
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]
|
|
|
|
css += input.input_html_classes
|
|
|
|
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
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
|