class SimpleForm::Wrappers::Root

`Root` is the root wrapper for all components. It is special cased to always have a namespace and to add special html classes.

Attributes

options[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method SimpleForm::Wrappers::Many::new
# File lib/simple_form/wrappers/root.rb, line 9
def initialize(*args)
  super(:wrapper, *args)
  @options = @defaults.except(:tag, :class, :error_class, :hint_class)
end

Public Instance Methods

find(name) click to toggle source

Provide a fallback if name cannot be found.

Calls superclass method SimpleForm::Wrappers::Many#find
# File lib/simple_form/wrappers/root.rb, line 20
def find(name)
  super || SimpleForm::Wrappers::Many.new(name, [Leaf.new(name)])
end
render(input) click to toggle source
Calls superclass method SimpleForm::Wrappers::Many#render
# File lib/simple_form/wrappers/root.rb, line 14
def render(input)
  input.options.reverse_merge!(@options)
  super
end

Private Instance Methods

html_class(key, options) { || ... } click to toggle source
# File lib/simple_form/wrappers/root.rb, line 37
def html_class(key, options)
  css = (options[:"wrapper_#{key}"] || @defaults[key])
  css if css && yield
end
html_classes(input, options) click to toggle source
# File lib/simple_form/wrappers/root.rb, line 26
def html_classes(input, options)
  css = options[:wrapper_class] ? Array(options[:wrapper_class]) : @defaults[:class]
  css += SimpleForm.additional_classes_for(:wrapper) do
    input.additional_classes + [input.input_class]
  end
  css << html_class(:error_class, options) { input.has_errors? }
  css << html_class(:hint_class, options) { input.has_hint? }
  css << html_class(:valid_class, options) { input.valid? }
  css.compact
end