Sha256: 3e29a66ab5ba78b49ab63417f1dea0d6d00aedc2a1599d1ba02cb80043394bf6

Contents?: true

Size: 1.65 KB

Versions: 124

Compression:

Stored size: 1.65 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::Beta::Label",
          constant: "SCHEME_MAPPINGS",
          symbolize: true
        ).freeze

        SIZE_MAPPINGS = ::Primer::ViewComponents::Constants.get(
          component: "Primer::Beta::Label",
          constant: "SIZE_MAPPINGS",
          symbolize: true
        ).freeze

        DEFAULT_TAG = ::Primer::ViewComponents::Constants.get(
          component: "Primer::Beta::Label",
          constant: "DEFAULT_TAG"
        ).freeze

        INLINE_CLASS = ::Primer::ViewComponents::Constants.get(
          component: "Primer::Beta::Label",
          constant: "INLINE_CLASS"
        ).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 SIZE_MAPPINGS[class_name] && acc[:size].nil?
              acc[:size] = SIZE_MAPPINGS[class_name]
            elsif class_name == INLINE_CLASS && acc[:inline].nil?
              acc[:inline] = true
            else
              acc[:classes] << class_name
            end
          end
        end
      end
    end
  end
end

Version data entries

124 entries across 124 versions & 2 rubygems

Version Path
primer_view_components-0.30.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.39.1 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.39.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.38.0 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.29.0 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.28.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.37.1 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.37.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.36.2 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.36.1 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.36.0 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.27.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.35.2 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.35.1 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.26.1 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.35.0 lib/primer/view_components/linters/argument_mappers/label.rb
primer_view_components-0.26.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.34.0 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.33.2 lib/primer/view_components/linters/argument_mappers/label.rb
openproject-primer_view_components-0.33.1 lib/primer/view_components/linters/argument_mappers/label.rb