Store the component on the instance

We already own the component so we don't need to ask for it again
This commit is contained in:
Rafael Mendonça França 2014-03-14 10:57:46 -03:00
parent 724dff54d5
commit 3d53595112
1 changed files with 4 additions and 6 deletions

View File

@ -3,23 +3,21 @@ module SimpleForm
# `Single` is an optimization for a wrapper that has only one component.
class Single < Many
def initialize(name, wrapper_options = {}, options = {})
super(name, [Leaf.new(name, options)], wrapper_options)
@component = Leaf.new(name, options)
super(name, [@component], wrapper_options)
end
def render(input)
options = input.options
if options[namespace] != false
content = component.render(input)
content = @component.render(input)
wrap(input, options, content) if content
end
end
private
def component
components.first
end
def html_options(options)
[:label, :input].include?(namespace) ? {} : super
end