Module: Releaf::Builders::FormBuilder::Label

Included in:
Releaf::Builders::FormBuilder
Defined in:
app/builders/releaf/builders/form_builder/label.rb

Instance Method Summary collapse

Instance Method Details

#label_attributes(_name, attributes, _options) ⇒ Object


31
32
33
# File 'app/builders/releaf/builders/form_builder/label.rb', line 31

def label_attributes(_name, attributes, _options)
  attributes
end

#label_text(name, options = {}) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/builders/releaf/builders/form_builder/label.rb', line 17

def label_text(name, options = {})
  if options[:label_text].present?
    options[:label_text]
  else
    if options[:translation_key].present?
      key = options[:translation_key]
    else
      key = name.to_s.sub(/_uid$/, '')
    end

    translate_attribute(key)
  end
end

#releaf_label(name, attributes, options = {}) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/builders/releaf/builders/form_builder/label.rb', line 2

def releaf_label(name, attributes, options = {})
  label_options = options.fetch(:label, {})
  attributes = label_attributes(name, attributes, options)
  text = label_text(name, label_options)

  content = label(name, text, attributes)

  if label_options.fetch(:minimal, false) == true
    content
  else
    content += wrapper(label_options[:description], class: "description") if label_options.fetch(:description, nil).present?
    wrapper(content, class: "label-wrap")
  end
end