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
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#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:, configuration: Configuration.new) ⇒ 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:, configuration: Configuration.new) ⇒ SlimNode
Returns a new instance of SlimNode.
11 12 13 14 15 |
# File 'lib/a11y/lint/slim_node.rb', line 11 def initialize(sexp, line:, configuration: Configuration.new) @sexp = sexp @line = line @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/a11y/lint/slim_node.rb', line 9 def configuration @configuration end |
#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
33 34 35 |
# File 'lib/a11y/lint/slim_node.rb', line 33 def attribute?(name) attributes.key?(name) end |
#attributes ⇒ Object
37 38 39 |
# File 'lib/a11y/lint/slim_node.rb', line 37 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`).
55 56 57 58 59 |
# File 'lib/a11y/lint/slim_node.rb', line 55 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).
63 64 65 66 67 |
# File 'lib/a11y/lint/slim_node.rb', line 63 def block_has_text_children? return false unless slim_output? block_text_content?(@sexp[4]) end |
#call_node ⇒ Object
27 28 29 30 31 |
# File 'lib/a11y/lint/slim_node.rb', line 27 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.
45 46 47 48 49 50 |
# File 'lib/a11y/lint/slim_node.rb', line 45 def children return [] unless html_tag? body = @sexp[4] collect_children(body) end |
#ruby_code ⇒ Object
21 22 23 24 25 |
# File 'lib/a11y/lint/slim_node.rb', line 21 def ruby_code return unless slim_output? @sexp[3] end |
#tag_name ⇒ Object
17 18 19 |
# File 'lib/a11y/lint/slim_node.rb', line 17 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.
72 73 74 75 76 |
# File 'lib/a11y/lint/slim_node.rb', line 72 def text_content? return false unless html_tag? text_or_output?(@sexp[4]) end |