Class: ERBLint::Linters::ArgumentMappers::CloseButton

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

Overview

Maps classes in a close-button element to arguments for the CloseButton component.

Constant Summary collapse

ATTRIBUTES =
%w[type].freeze
TYPE_OPTIONS =
Yattho::ViewComponents::Constants.get(
  component: "Yattho::Beta::CloseButton",
  constant: "TYPE_OPTIONS"
).freeze
DEFAULT_TYPE =
Yattho::ViewComponents::Constants.get(
  component: "Yattho::Beta::CloseButton",
  constant: "DEFAULT_TYPE"
).freeze
DEFAULT_CLASS =
"close-button"

Constants inherited from Base

Base::DEFAULT_TAG

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yattho/view_components/linters/argument_mappers/close_button.rb', line 24

def attribute_to_args(attribute)
  # button is the default type, so we don't need to do anything.
  return {} if attribute.value == DEFAULT_TYPE

  unless TYPE_OPTIONS.include?(attribute.value)
    raise ConversionError,
          "CloseButton component does not support type \"#{attribute.value}\""
  end

  { type: ":#{attribute.value}" }
end

#classes_to_args(classes) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/yattho/view_components/linters/argument_mappers/close_button.rb', line 36

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

    acc[:classes] << class_name
  end
end