Class: A11y::Lint::SlimNode
- Inherits:
-
Object
- Object
- A11y::Lint::SlimNode
- Defined in:
- lib/a11y/lint/slim_node.rb
Overview
Wraps a Slim AST s-expression 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
-
#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
Constructor Details
#initialize(sexp, line:) ⇒ SlimNode
Returns a new instance of SlimNode.
9 10 11 12 |
# File 'lib/a11y/lint/slim_node.rb', line 9 def initialize(sexp, line:) @sexp = sexp @line = line end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
7 8 9 |
# File 'lib/a11y/lint/slim_node.rb', line 7 def line @line end |
Instance Method Details
#attribute?(name) ⇒ Boolean
24 25 26 |
# File 'lib/a11y/lint/slim_node.rb', line 24 def attribute?(name) attributes.key?(name) end |
#attributes ⇒ Object
28 29 30 |
# File 'lib/a11y/lint/slim_node.rb', line 28 def attributes @attributes ||= extract_attributes 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.
36 37 38 39 40 41 |
# File 'lib/a11y/lint/slim_node.rb', line 36 def children return [] unless html_tag? body = @sexp[4] collect_children(body) end |
#ruby_code ⇒ Object
18 19 20 21 22 |
# File 'lib/a11y/lint/slim_node.rb', line 18 def ruby_code return unless @sexp[0] == :slim && @sexp[1] == :output @sexp[3] end |
#tag_name ⇒ Object
14 15 16 |
# File 'lib/a11y/lint/slim_node.rb', line 14 def tag_name @sexp[2] end |