2011-09-02 20:14:23 +00:00
|
|
|
module SimpleForm
|
|
|
|
module Wrappers
|
2011-09-03 07:15:47 +00: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 20:14:23 +00:00
|
|
|
class Root < Many
|
2011-12-04 13:57:12 +00:00
|
|
|
attr_reader :options
|
|
|
|
|
2011-09-02 20:14:23 +00:00
|
|
|
def initialize(*args)
|
|
|
|
super(:wrapper, *args)
|
2012-01-11 02:39:20 +00:00
|
|
|
@options = @defaults.except(:tag, :class, :error_class, :hint_class)
|
2011-12-04 13:57:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def render(input)
|
|
|
|
input.options.reverse_merge!(@options)
|
|
|
|
super
|
2011-09-02 20:14:23 +00:00
|
|
|
end
|
|
|
|
|
2011-09-04 09:31:24 +00:00
|
|
|
# Provide a fallback if name cannot be found.
|
|
|
|
def find(name)
|
2012-01-11 20:12:49 +00:00
|
|
|
super || SimpleForm::Wrappers::Many.new(name, [name])
|
2011-09-04 09:31:24 +00:00
|
|
|
end
|
|
|
|
|
2011-09-02 20:14:23 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def html_classes(input, options)
|
2011-09-02 21:34:02 +00:00
|
|
|
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
2012-10-07 03:31:57 +00:00
|
|
|
css += SimpleForm.additional_classes_for(:wrapper) do
|
|
|
|
input.additional_classes + [input.input_class]
|
|
|
|
end
|
2011-09-02 21:34:02 +00:00
|
|
|
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
2012-01-10 21:00:14 +00:00
|
|
|
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
2012-06-29 19:13:15 +00:00
|
|
|
css.compact
|
2011-09-02 20:14:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-09-11 21:46:47 +00:00
|
|
|
end
|