mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
29 lines
No EOL
916 B
Ruby
29 lines
No EOL
916 B
Ruby
module SimpleForm
|
|
module Wrappers
|
|
autoload :Many, 'simple_form/wrappers/many'
|
|
autoload :Root, 'simple_form/wrappers/root'
|
|
autoload :Single, 'simple_form/wrappers/single'
|
|
|
|
# TODO: Test the anonym case
|
|
def self.find(name)
|
|
SimpleForm.components.find { |c| c.namespace == name } || SingleForm::Wrappers::Many.new(name, name)
|
|
end
|
|
|
|
def self.wrap(array)
|
|
Root.new(
|
|
*(array.map do |item|
|
|
case item
|
|
when :error
|
|
Single.new(:error, :tag => SimpleForm.error_tag, :class => SimpleForm.error_class)
|
|
when :hint
|
|
Single.new(:hint, :tag => SimpleForm.hint_tag, :class => SimpleForm.hint_class)
|
|
else
|
|
item
|
|
end
|
|
end << { :tag => SimpleForm.wrapper_tag,
|
|
:class => SimpleForm.wrapper_class,
|
|
:error_class => SimpleForm.wrapper_error_class })
|
|
)
|
|
end
|
|
end
|
|
end |