Class: A11y::Lint::SlimNode

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#lineObject (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

Returns:

  • (Boolean)


24
25
26
# File 'lib/a11y/lint/slim_node.rb', line 24

def attribute?(name)
  attributes.key?(name)
end

#attributesObject



28
29
30
# File 'lib/a11y/lint/slim_node.rb', line 28

def attributes
  @attributes ||= extract_attributes
end

#childrenObject

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_codeObject



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_nameObject



14
15
16
# File 'lib/a11y/lint/slim_node.rb', line 14

def tag_name
  @sexp[2]
end