Class: SexyForm::Themes::Default

Inherits:
BaseTheme show all
Defined in:
lib/sexy_form/themes/default.rb

Instance Method Summary collapse

Methods inherited from BaseTheme

theme_name

Instance Method Details

#build_html_error(error:, html_attrs:, field_type:) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/sexy_form/themes/default.rb', line 45

def build_html_error(error:, html_attrs:, field_type:)
  s = ""
  s << (html_attrs.empty? ? "<div>" : "<div #{SexyForm.build_html_attr_string(html_attrs)}>")
  s << "#{error}"
  s << "</div>"
  s
end

#build_html_help_text(help_text:, html_attrs:, field_type:) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/sexy_form/themes/default.rb', line 37

def build_html_help_text(help_text:, html_attrs:, field_type:)
  s = ""
  s << (html_attrs.empty? ? "<div>" : "<div #{SexyForm.build_html_attr_string(html_attrs)}>")
  s << "#{help_text}"
  s << "</div>"
  s
end

#form_html_attributes(html_attrs:) ⇒ Object



33
34
35
# File 'lib/sexy_form/themes/default.rb', line 33

def form_html_attributes(html_attrs:)
  html_attrs
end

#input_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object



25
26
27
# File 'lib/sexy_form/themes/default.rb', line 25

def input_html_attributes(html_attrs:, field_type:, has_errors:)
  html_attrs
end

#label_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object



29
30
31
# File 'lib/sexy_form/themes/default.rb', line 29

def label_html_attributes(html_attrs:, field_type:, has_errors:)
  html_attrs
end

#wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sexy_form/themes/default.rb', line 5

def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
  s = ""

  attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
  s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"

  if ["checkbox", "radio"].include?(field_type) && html_label
    s << html_label.sub("\">", "\">#{html_field} ")
  else
    s << html_label.to_s
    s << html_field.to_s
  end
  s << html_help_text.to_s
  s << html_errors.join if html_errors

  s << "</div>"

  s
end