Class: A11y::Lint::ErbElementNode

Inherits:
Object
  • Object
show all
Defined in:
lib/a11y/lint/erb_element_node.rb

Overview

Wraps a Nokogiri HTML element from an ERB template as a queryable node for lint rules.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_node:, line:, configuration: Configuration.new) ⇒ ErbElementNode

Returns a new instance of ErbElementNode.



10
11
12
13
14
15
16
# File 'lib/a11y/lint/erb_element_node.rb', line 10

def initialize(
  nokogiri_node:, line:, configuration: Configuration.new
)
  @nokogiri_node = nokogiri_node
  @line = line
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/a11y/lint/erb_element_node.rb', line 8

def configuration
  @configuration
end

#lineObject (readonly)

Returns the value of attribute line.



8
9
10
# File 'lib/a11y/lint/erb_element_node.rb', line 8

def line
  @line
end

Instance Method Details

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/a11y/lint/erb_element_node.rb', line 22

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

#attributesObject



26
27
28
29
30
31
# File 'lib/a11y/lint/erb_element_node.rb', line 26

def attributes
  @attributes ||=
    @nokogiri_node
    .attributes
    .transform_values(&:value)
end

#block_body_codesObject



41
42
43
# File 'lib/a11y/lint/erb_element_node.rb', line 41

def block_body_codes
  nil
end

#block_has_text_children?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/a11y/lint/erb_element_node.rb', line 45

def block_has_text_children?
  false
end

#call_nodeObject



33
34
35
# File 'lib/a11y/lint/erb_element_node.rb', line 33

def call_node
  nil
end

#childrenObject

Returns direct element children wrapped as ErbElementNode objects. Excludes elements whose class attribute matches a configured hidden-wrapper class, since CSS-hidden subtrees do not contribute to the accessible name.



59
60
61
62
63
64
65
66
67
68
# File 'lib/a11y/lint/erb_element_node.rb', line 59

def children
  @nokogiri_node.element_children.filter_map do |child|
    next if hidden_wrapper?(child)

    ErbElementNode.new(
      nokogiri_node: child, line: child.line,
      configuration: configuration
    )
  end
end

#ruby_codeObject



37
38
39
# File 'lib/a11y/lint/erb_element_node.rb', line 37

def ruby_code
  nil
end

#tag_nameObject



18
19
20
# File 'lib/a11y/lint/erb_element_node.rb', line 18

def tag_name
  @nokogiri_node.name
end

#text_content?Boolean

Returns:

  • (Boolean)


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

def text_content?
  return false if hidden_wrapper?(@nokogiri_node)

  visible_text_or_output?(@nokogiri_node)
end