Class: A11y::Lint::ErbNode

Inherits:
Object
  • Object
show all
Includes:
BlockInspection
Defined in:
lib/a11y/lint/erb_node.rb

Overview

Wraps a Nokogiri node or extracted ERB output tag as a queryable node for lint rules.

Constant Summary

Constants included from BlockInspection

BlockInspection::ICON_HELPERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlockInspection

#block_has_only_icon_helpers?

Constructor Details

#initialize(line:, block_body_codes: nil, block_has_text_children: false, nokogiri_node: nil, ruby_code: nil) ⇒ ErbNode

Returns a new instance of ErbNode.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/a11y/lint/erb_node.rb', line 12

def initialize(
  line:,
  block_body_codes: nil,
  block_has_text_children: false,
  nokogiri_node: nil,
  ruby_code: nil
)
  @line = line
  @block_body_codes = block_body_codes
  @block_has_text_children = block_has_text_children
  @nokogiri_node = nokogiri_node
  @ruby_code = ruby_code
end

Instance Attribute Details

#block_body_codesObject (readonly)

Returns the value of attribute block_body_codes.



10
11
12
# File 'lib/a11y/lint/erb_node.rb', line 10

def block_body_codes
  @block_body_codes
end

#lineObject (readonly)

Returns the value of attribute line.



10
11
12
# File 'lib/a11y/lint/erb_node.rb', line 10

def line
  @line
end

#ruby_codeObject (readonly)

Returns the value of attribute ruby_code.



10
11
12
# File 'lib/a11y/lint/erb_node.rb', line 10

def ruby_code
  @ruby_code
end

Instance Method Details

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/a11y/lint/erb_node.rb', line 30

def attribute?(name)
  attributes.key?(name)
end

#attributesObject



34
35
36
# File 'lib/a11y/lint/erb_node.rb', line 34

def attributes
  @attributes ||= extract_attributes
end

#block_has_text_children?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/a11y/lint/erb_node.rb', line 42

def block_has_text_children?
  @block_has_text_children
end

#call_nodeObject



38
39
40
# File 'lib/a11y/lint/erb_node.rb', line 38

def call_node
  @call_node ||= RubyCode.new(ruby_code).call_node
end

#childrenObject

Returns direct element children wrapped as ErbNode objects.



47
48
49
50
51
52
53
# File 'lib/a11y/lint/erb_node.rb', line 47

def children
  return [] unless nokogiri_node

  nokogiri_node.element_children.map do |child|
    ErbNode.new(nokogiri_node: child, line: child.line)
  end
end

#tag_nameObject



26
27
28
# File 'lib/a11y/lint/erb_node.rb', line 26

def tag_name
  nokogiri_node&.name
end