class ERBLint::Linters::ArgumentMappers::SystemArguments
Maps element attributes to system arguments.
Constants
- STRING_PARAMETERS
- TEST_SELECTOR_REGEX
Attributes
attribute[R]
erb_helper[R]
Public Class Methods
new(attribute)
click to toggle source
# File lib/primer/view_components/linters/argument_mappers/system_arguments.rb, line 16 def initialize(attribute) @attribute = attribute @erb_helper = Helpers::ErbBlock.new end
Public Instance Methods
attr_name()
click to toggle source
# File lib/primer/view_components/linters/argument_mappers/system_arguments.rb, line 42 def attr_name attribute.name end
to_args()
click to toggle source
# File lib/primer/view_components/linters/argument_mappers/system_arguments.rb, line 21 def to_args if attribute.erb? _, _, code_node = *attribute.node raise ConversionError, "Cannot convert erb block" if code_node.nil? code = code_node.loc.source.strip m = code.match(TEST_SELECTOR_REGEX) raise ConversionError, "Cannot convert erb block" if m.blank? { test_selector: m[:selector].tr("'", '"') } elsif attr_name == "data-test-selector" { test_selector: erb_helper.convert(attribute) } elsif attr_name.start_with?(*STRING_PARAMETERS) { "\"#{attr_name}\"" => erb_helper.convert(attribute) } else raise ConversionError, "Cannot convert attribute \"#{attr_name}\"" end end