Class: ComponentEmbeddedRuby::Parser::AttributeParser

Inherits:
Base
  • Object
show all
Defined in:
lib/component_embedded_ruby/parser/attribute_parser.rb

Overview

Internal: Parses an HTML tag attributes into a hash of key values

This class parses HTML attributes into a hash of key values, keys are always strings but since values can be dynamic, they will either be a string or an instance of ‘Eval`.

Given how we parse these attributes, they are intentionally either a string or Ruby, not a combination of the two.

Valid attributes may look like ‘id=“document” class=my_classes`

The following is invalid ‘class=“mb-0 my_classes”`

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ComponentEmbeddedRuby::Parser::Base

Instance Method Details

#callObject



19
20
21
22
23
24
25
# File 'lib/component_embedded_ruby/parser/attribute_parser.rb', line 19

def call
  attributes = {}

  attributes.merge!(parse_attribute) while current_token.type == :identifier

  attributes
end