Class: A11y::Lint::ErbElementNode
- Inherits:
-
Object
- Object
- A11y::Lint::ErbElementNode
- 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
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #attribute?(name) ⇒ Boolean
- #attributes ⇒ Object
- #block_body_codes ⇒ Object
- #block_has_text_children? ⇒ Boolean
- #call_node ⇒ Object
-
#children ⇒ Object
Returns direct element children wrapped as ErbElementNode objects.
-
#initialize(nokogiri_node:, line:, has_erb_output: false) ⇒ ErbElementNode
constructor
A new instance of ErbElementNode.
- #ruby_code ⇒ Object
- #tag_name ⇒ Object
- #text_content? ⇒ Boolean
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
#line ⇒ Object (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
20 21 22 |
# File 'lib/a11y/lint/erb_element_node.rb', line 20 def attribute?(name) attributes.key?(name) end |
#attributes ⇒ Object
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_codes ⇒ Object
39 40 41 |
# File 'lib/a11y/lint/erb_element_node.rb', line 39 def block_body_codes nil end |
#block_has_text_children? ⇒ Boolean
43 44 45 |
# File 'lib/a11y/lint/erb_element_node.rb', line 43 def block_has_text_children? false end |
#call_node ⇒ Object
31 32 33 |
# File 'lib/a11y/lint/erb_element_node.rb', line 31 def call_node nil end |
#children ⇒ Object
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_code ⇒ Object
35 36 37 |
# File 'lib/a11y/lint/erb_element_node.rb', line 35 def ruby_code nil end |
#tag_name ⇒ Object
16 17 18 |
# File 'lib/a11y/lint/erb_element_node.rb', line 16 def tag_name @nokogiri_node.name end |
#text_content? ⇒ 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 |