Sha256: 93a04acd15072d985a93b2937a7045a7db8ecc04bb12ce21c5d0b45ab73ec05a

Contents?: true

Size: 1.41 KB

Versions: 35

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require_relative "base"

module ERBLint
  module Linters
    module ArgumentMappers
      # Maps classes in a label element to arguments for the Label component.
      class Label < Base
        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

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

        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
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
primer_view_components-0.0.87 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.86 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.85 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.84 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.83 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.82 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.81 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.80 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.79 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.78 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.77 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.76 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.75 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.74 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.73 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.72 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.71 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.70 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.69 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.0.68 lib/primer/view_components/linters/argument_mappers/label.rb