Parent

Methods

Files

Class/Module Index [+]

Quicksearch

SimpleForm::Wrappers::Many

A wrapper is an object that holds several components and render them. A component may either be a symbol or any object that responds to `render`. This API allows inputs/components to be easily wrapped, removing the need to modify the code only to wrap input in an extra tag.

`Many` represents a wrapper around several components at the same time. It may optionally receive a namespace, allowing it to be configured on demand on input generation.

Attributes

components[R]
defaults[R]
namespace[R]
to_sym[R]

Public Instance Methods

find(name) click to toggle source
# File lib/simple_form/wrappers/many.rb, line 36
def find(name)
  return self if namespace == name

  @components.each do |c|
    if c.is_a?(Symbol)
      return nil if c == namespace
    elsif value = c.find(name)
      return value
    end
  end

  nil
end
render(input) click to toggle source
# File lib/simple_form/wrappers/many.rb, line 23
def render(input)
  content = "".html_safe
  options = input.options

  components.each do |component|
    next if options[component] == false
    rendered = component.respond_to?(:render) ? component.render(input) : input.send(component)
    content.safe_concat rendered.to_s if rendered
  end

  wrap(input, options, content)
end

Public Class Methods

new(namespace, components, defaults={}) click to toggle source
# File lib/simple_form/wrappers/many.rb, line 15
def initialize(namespace, components, defaults={})
  @namespace  = namespace
  @components = components
  @defaults   = defaults
  @defaults[:tag]   = :div unless @defaults.key?(:tag)
  @defaults[:class] = Array.wrap(@defaults[:class])
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.