heartcombo--simple_form/lib/simple_form/wrappers/single.rb

25 lines
568 B
Ruby
Raw Normal View History

2011-09-02 18:33:03 +00:00
module SimpleForm
module Wrappers
2011-09-03 07:15:47 +00:00
# `Single` is an optimization for a wrapper that has only one component.
2011-09-02 18:33:03 +00:00
class Single < Many
2011-09-03 07:08:36 +00:00
def initialize(name, options={})
super(name, [name], options)
end
2011-09-02 18:33:03 +00:00
def render(input)
options = input.options
2012-01-20 01:26:51 +00:00
if options[namespace] != false
2011-09-02 18:33:03 +00:00
content = input.send(namespace)
wrap(input, options, content) if content
2012-01-20 01:25:43 +00:00
end
2011-09-02 18:33:03 +00:00
end
private
def html_options(options)
2012-06-27 02:34:07 +00:00
[:label, :input].include?(namespace) ? {} : super
end
2011-09-02 18:33:03 +00:00
end
end
2012-01-20 01:25:43 +00:00
end