Class: RailsRouteChecker::Parsers::HamlParser::Tree::TagNode

Inherits:
Node
  • Object
show all
Defined in:
lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb

Instance Attribute Summary

Attributes inherited from Node

#children, #line, #parent, #type

Instance Method Summary collapse

Methods inherited from Node

#directives, #each, #initialize, #inspect, #line_numbers, #lines, #next_node, #predecessor, #source_code, #subsequents, #successor, #text

Constructor Details

This class inherits a constructor from RailsRouteChecker::Parsers::HamlParser::Tree::Node

Instance Method Details

#attributes_sourceObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb', line 22

def attributes_source
  @attr_source ||= # rubocop:disable Naming/MemoizedInstanceVariableName
    begin
      _explicit_tag, static_attrs, rest =
        source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0]

      attr_types = {
        '{' => [:hash, %w[{ }]],
        '(' => [:html, %w[( )]],
        '[' => [:object_ref, %w[[ ]]]
      }

      attr_source = { static: static_attrs }
      while rest
        type, chars = attr_types[rest[0]]
        break unless type
        break if attr_source[type]

        attr_source[type], rest = Haml::Util.balance(rest, *chars)
      end

      attr_source
    end
end

#dynamic_attributes_sourceObject



17
18
19
20
# File 'lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb', line 17

def dynamic_attributes_source
  @dynamic_attributes_source ||=
    attributes_source.reject { |key| key == :static }
end

#dynamic_attributes_sourcesObject



8
9
10
11
12
13
14
15
# File 'lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb', line 8

def dynamic_attributes_sources
  @dynamic_attributes_sources ||=
    if Gem::Version.new(Haml::VERSION) < Gem::Version.new('5')
      @value[:attributes_hashes]
    else
      Array(@value[:dynamic_attributes].to_literal).reject(&:empty?)
    end
end

#hash_attributes?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb', line 47

def hash_attributes?
  !dynamic_attributes_source[:hash].nil?
end

#scriptObject



51
52
53
# File 'lib/rails-route-checker/parsers/haml_parser/tree/tag_node.rb', line 51

def script
  (@value[:value] if @value[:parse]) || ''
end