Class: A11y::Lint::SlimNode
- Inherits:
-
Object
- Object
- A11y::Lint::SlimNode
- Includes:
- BlockInspection
- Defined in:
- lib/a11y/lint/slim_node.rb
Overview
Wraps a Slim AST s-expression as a queryable node for lint rules.
Constant Summary
Constants included from BlockInspection
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
Returns ruby_code strings from child :slim :output nodes inside a block body.
-
#block_has_text_children? ⇒ Boolean
Returns true when the block body contains visible text or HTML tag children (i.e. content that provides an accessible name).
- #call_node ⇒ Object
-
#children ⇒ Object
Returns direct HTML element children as SlimNode objects.
-
#initialize(sexp, line:) ⇒ SlimNode
constructor
A new instance of SlimNode.
- #ruby_code ⇒ Object
- #tag_name ⇒ Object
-
#text_content? ⇒ Boolean
Returns true when the HTML element body contains visible text or dynamic output (i.e. content that could provide an accessible name).
Methods included from BlockInspection
Constructor Details
#initialize(sexp, line:) ⇒ SlimNode
Returns a new instance of SlimNode.
11 12 13 14 |
# File 'lib/a11y/lint/slim_node.rb', line 11 def initialize(sexp, line:) @sexp = sexp @line = line end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
9 10 11 |
# File 'lib/a11y/lint/slim_node.rb', line 9 def line @line end |
Instance Method Details
#attribute?(name) ⇒ Boolean
32 33 34 |
# File 'lib/a11y/lint/slim_node.rb', line 32 def attribute?(name) attributes.key?(name) end |
#attributes ⇒ Object
36 37 38 |
# File 'lib/a11y/lint/slim_node.rb', line 36 def attributes @attributes ||= extract_attributes end |
#block_body_codes ⇒ Object
Returns ruby_code strings from child :slim :output nodes inside a block body. Only meaningful for output nodes (e.g. ‘= button_tag(…) do`).
54 55 56 57 58 |
# File 'lib/a11y/lint/slim_node.rb', line 54 def block_body_codes return unless slim_output? collect_output_codes(@sexp[4]) end |
#block_has_text_children? ⇒ Boolean
Returns true when the block body contains visible text or HTML tag children (i.e. content that provides an accessible name).
62 63 64 65 66 |
# File 'lib/a11y/lint/slim_node.rb', line 62 def block_has_text_children? return false unless slim_output? block_text_content?(@sexp[4]) end |
#call_node ⇒ Object
26 27 28 29 30 |
# File 'lib/a11y/lint/slim_node.rb', line 26 def call_node return unless slim_output? @call_node ||= parse_call_node end |
#children ⇒ Object
Returns direct HTML element children as SlimNode objects. Walks through [:multi] and [:slim, :control] wrappers so that tags nested inside control flow are still treated as direct children. Opaque [:slim, :output] blocks are skipped.
44 45 46 47 48 49 |
# File 'lib/a11y/lint/slim_node.rb', line 44 def children return [] unless html_tag? body = @sexp[4] collect_children(body) end |
#ruby_code ⇒ Object
20 21 22 23 24 |
# File 'lib/a11y/lint/slim_node.rb', line 20 def ruby_code return unless slim_output? @sexp[3] end |
#tag_name ⇒ Object
16 17 18 |
# File 'lib/a11y/lint/slim_node.rb', line 16 def tag_name @sexp[2] end |
#text_content? ⇒ Boolean
Returns true when the HTML element body contains visible text or dynamic output (i.e. content that could provide an accessible name). Only meaningful for HTML tag nodes.
71 72 73 74 75 |
# File 'lib/a11y/lint/slim_node.rb', line 71 def text_content? return false unless html_tag? text_or_output?(@sexp[4]) end |