Module: ViewComponent::Form::ClassNamesHelper

Included in:
BaseComponent
Defined in:
lib/view_component/form/class_names_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_tag_values(*args) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/view_component/form/class_names_helper.rb', line 10

def build_tag_values(*args)
  tag_values = []

  args.each do |tag_value|
    case tag_value
    when Hash
      tag_value.each do |key, val|
        tag_values << key.to_s if val && key.present?
      end
    when Array
      tag_values.concat build_tag_values(*tag_value)
    else
      tag_values << tag_value.to_s if tag_value.present?
    end
  end

  tag_values
end

#class_names(*args) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength



31
32
33
34
35
# File 'lib/view_component/form/class_names_helper.rb', line 31

def class_names(*args)
  tokens = build_tag_values(*args).flat_map { |value| value.to_s.split(/\s+/) }.uniq

  safe_join(tokens, " ")
end