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:, has_erb_output: false) ⇒ ErbElementNode

Returns a new instance of ErbElementNode.



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

def initialize(nokogiri_node:, line:, has_erb_output: false)
  @nokogiri_node = nokogiri_node
  @line = line
  @has_erb_output = has_erb_output
end

Instance Attribute Details

#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)


20
21
22
# File 'lib/a11y/lint/erb_element_node.rb', line 20

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

#attributesObject



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

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

#block_body_codesObject



39
40
41
# File 'lib/a11y/lint/erb_element_node.rb', line 39

def block_body_codes
  nil
end

#block_has_text_children?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/a11y/lint/erb_element_node.rb', line 43

def block_has_text_children?
  false
end

#call_nodeObject



31
32
33
# File 'lib/a11y/lint/erb_element_node.rb', line 31

def call_node
  nil
end

#childrenObject

Returns direct element children wrapped as ErbElementNode objects.



52
53
54
55
56
# File 'lib/a11y/lint/erb_element_node.rb', line 52

def children
  @nokogiri_node.element_children.map do |child|
    ErbElementNode.new(nokogiri_node: child, line: child.line)
  end
end

#ruby_codeObject



35
36
37
# File 'lib/a11y/lint/erb_element_node.rb', line 35

def ruby_code
  nil
end

#tag_nameObject



16
17
18
# File 'lib/a11y/lint/erb_element_node.rb', line 16

def tag_name
  @nokogiri_node.name
end

#text_content?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/a11y/lint/erb_element_node.rb', line 47

def text_content?
  @has_erb_output || !@nokogiri_node.text.strip.empty?
end