Module: GenericFormFor::Inputs::Base::Label

Included in:
GenericFormFor::Inputs::Base
Defined in:
lib/generic_form_for/inputs/base/label.rb

Instance Method Summary collapse

Instance Method Details

#label_html(config_options = {}) ⇒ Object



6
7
8
9
# File 'lib/generic_form_for/inputs/base/label.rb', line 6

def label_html(config_options={})
  return unless render_label?
  template.concat builder.label(method, label_text, label_html_options(config_options))
end

#label_html_options(config_options = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/generic_form_for/inputs/base/label.rb', line 11

def label_html_options(config_options={})
  opts = (options[:label_html] || {}).dup
  opts[:for] ||= options[:id]
  opts[:class] = [*opts[:class], *config_options[:class]].compact.join(' ').strip
  config_options.merge(opts)
end

#label_textObject



18
19
20
# File 'lib/generic_form_for/inputs/base/label.rb', line 18

def label_text
  (translated_label << requirement_text).html_safe
end

#render_label?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/generic_form_for/inputs/base/label.rb', line 35

def render_label?
  !(options[:label] == false)
end

#requirement_textObject



22
23
24
25
26
27
28
29
# File 'lib/generic_form_for/inputs/base/label.rb', line 22

def requirement_text
  return "" unless required?
  if builder.required_string.respond_to?(:call)
    builder.required_string.call
  else
    builder.required_string
  end
end

#translated_labelObject



31
32
33
# File 'lib/generic_form_for/inputs/base/label.rb', line 31

def translated_label
  translate_label(options[:label] || method)
end