Class: ERBLint::Linters::ArgumentMappers::Label

Inherits:
Base
  • Object
show all
Defined in:
lib/primer/view_components/linters/argument_mappers/label.rb

Overview

Maps classes in a label element to arguments for the Label component.

Constant Summary collapse

SCHEME_MAPPINGS =
Primer::ViewComponents::Constants.get(
  component: "Primer::LabelComponent",
  constant: "SCHEME_MAPPINGS",
  symbolize: true
).freeze
VARIANT_MAPPINGS =
Primer::ViewComponents::Constants.get(
  component: "Primer::LabelComponent",
  constant: "VARIANT_MAPPINGS",
  symbolize: true
).freeze
DEFAULT_TAG =
Primer::ViewComponents::Constants.get(
  component: "Primer::LabelComponent",
  constant: "DEFAULT_TAG"
).freeze
ATTRIBUTES =
%w[title].freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize, #map_classes, #system_arguments_to_args, #to_args, #to_s

Constructor Details

This class inherits a constructor from ERBLint::Linters::ArgumentMappers::Base

Instance Method Details

#attribute_to_args(attribute) ⇒ Object



29
30
31
# File 'lib/primer/view_components/linters/argument_mappers/label.rb', line 29

def attribute_to_args(attribute)
  { title: erb_helper.convert(attribute) }
end

#classes_to_args(classes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/primer/view_components/linters/argument_mappers/label.rb', line 33

def classes_to_args(classes)
  classes.each_with_object({ classes: [] }) do |class_name, acc|
    next if class_name == "Label"

    if SCHEME_MAPPINGS[class_name] && acc[:scheme].nil?
      acc[:scheme] = SCHEME_MAPPINGS[class_name]
    elsif VARIANT_MAPPINGS[class_name] && acc[:variant].nil?
      acc[:variant] = VARIANT_MAPPINGS[class_name]
    else
      acc[:classes] << class_name
    end
  end
end