Class: A11y::Lint::PhlexNode

Inherits:
Object
  • Object
show all
Extended by:
PhlexTags
Includes:
BlockInspection
Defined in:
lib/a11y/lint/phlex_node.rb

Overview

Wraps a Phlex HTML tag call or helper method call as a queryable node for lint rules.

Constant Summary

Constants included from PhlexTags

A11y::Lint::PhlexTags::HTML_TAGS, A11y::Lint::PhlexTags::TAG_ALIASES

Constants included from BlockInspection

BlockInspection::ICON_HELPERS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PhlexTags

html_tag?, html_tag_name

Methods included from BlockInspection

#block_has_only_icon_helpers?

Constructor Details

#initialize(line:, tag_name: nil, attributes: {}, call_node: nil, children: [], block_body_codes: nil, block_has_text_children: false) ⇒ PhlexNode

rubocop:disable Metrics/ParameterLists



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/a11y/lint/phlex_node.rb', line 21

def initialize(
  line:, tag_name: nil, attributes: {},
  call_node: nil, children: [],
  block_body_codes: nil,
  block_has_text_children: false
)
  @tag_name = tag_name
  @attributes = attributes
  @call_node = call_node
  @line = line
  @children = children
  @block_body_codes = block_body_codes
  @block_has_text_children = block_has_text_children
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def attributes
  @attributes
end

#block_body_codesObject (readonly)

Returns the value of attribute block_body_codes.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def block_body_codes
  @block_body_codes
end

#call_nodeObject (readonly)

Returns the value of attribute call_node.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def call_node
  @call_node
end

#childrenObject (readonly)

Returns the value of attribute children.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def children
  @children
end

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def line
  @line
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



11
12
13
# File 'lib/a11y/lint/phlex_node.rb', line 11

def tag_name
  @tag_name
end

Class Method Details

.build_helper(call_node, block_body_codes: nil, block_has_text_children: false) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/a11y/lint/phlex_node.rb', line 59

def self.build_helper(
  call_node,
  block_body_codes: nil,
  block_has_text_children: false
)
  new(
    call_node: CallNode.new(call_node),
    line: call_node.location.start_line,
    block_body_codes: block_body_codes,
    block_has_text_children: block_has_text_children
  )
end

.build_tag(call_node, children: []) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/a11y/lint/phlex_node.rb', line 49

def self.build_tag(call_node, children: [])
  name = call_node.name.to_s
  new(
    tag_name: html_tag_name(name),
    attributes: extract_attributes(call_node),
    line: call_node.location.start_line,
    children: children
  )
end

Instance Method Details

#attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/a11y/lint/phlex_node.rb', line 41

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

#block_has_text_children?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/a11y/lint/phlex_node.rb', line 45

def block_has_text_children?
  @block_has_text_children
end

#ruby_codeObject

rubocop:enable Metrics/ParameterLists



37
38
39
# File 'lib/a11y/lint/phlex_node.rb', line 37

def ruby_code
  nil
end