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)
|
2011-09-02 20:14:23 +00:00
|
|
|
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
|
2012-06-27 02:23:40 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def html_options(options)
|
2012-06-27 02:34:07 +00:00
|
|
|
[:label, :input].include?(namespace) ? {} : super
|
2012-06-27 02:23:40 +00:00
|
|
|
end
|
2011-09-02 18:33:03 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-20 01:25:43 +00:00
|
|
|
end
|