1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00
heartcombo--simple_form/lib/simple_form/wrappers/root.rb

35 lines
1 KiB
Ruby
Raw Normal View History

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.
class Root < Many
attr_reader :options
def initialize(*args)
super(:wrapper, *args)
@options = @defaults.except(:tag, :class, :error_class, :hint_class)
end
def render(input)
input.options.reverse_merge!(@options)
super
end
2011-09-04 05:31:24 -04:00
# Provide a fallback if name cannot be found.
def find(name)
super || SimpleForm::Wrappers::Many.new(name, [name])
2011-09-04 05:31:24 -04:00
end
private
def html_classes(input, options)
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
css += input.html_classes
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
2011-09-11 17:46:47 -04:00
css
end
end
end
2011-09-11 17:46:47 -04:00
end