Class: A11y::Lint::ErbNode
- Inherits:
-
Object
- Object
- A11y::Lint::ErbNode
- 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
Instance Attribute Summary collapse
-
#block_body_codes ⇒ Object
readonly
Returns the value of attribute block_body_codes.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#ruby_code ⇒ Object
readonly
Returns the value of attribute ruby_code.
Instance Method Summary collapse
- #attribute?(name) ⇒ Boolean
- #attributes ⇒ Object
- #block_has_text_children? ⇒ Boolean
- #call_node ⇒ Object
-
#children ⇒ Object
Returns direct element children wrapped as ErbNode objects.
-
#initialize(line:, block_body_codes: nil, block_has_text_children: false, nokogiri_node: nil, ruby_code: nil) ⇒ ErbNode
constructor
A new instance of ErbNode.
- #tag_name ⇒ Object
Methods included from BlockInspection
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_codes ⇒ Object (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 |
#line ⇒ Object (readonly)
Returns the value of attribute line.
10 11 12 |
# File 'lib/a11y/lint/erb_node.rb', line 10 def line @line end |
#ruby_code ⇒ Object (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
30 31 32 |
# File 'lib/a11y/lint/erb_node.rb', line 30 def attribute?(name) attributes.key?(name) end |
#attributes ⇒ Object
34 35 36 |
# File 'lib/a11y/lint/erb_node.rb', line 34 def attributes @attributes ||= extract_attributes end |
#block_has_text_children? ⇒ Boolean
42 43 44 |
# File 'lib/a11y/lint/erb_node.rb', line 42 def block_has_text_children? @block_has_text_children end |
#call_node ⇒ Object
38 39 40 |
# File 'lib/a11y/lint/erb_node.rb', line 38 def call_node @call_node ||= RubyCode.new(ruby_code).call_node end |
#children ⇒ Object
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_name ⇒ Object
26 27 28 |
# File 'lib/a11y/lint/erb_node.rb', line 26 def tag_name nokogiri_node&.name end |