Class: A11y::Lint::PhlexNode
- Inherits:
-
Object
- Object
- A11y::Lint::PhlexNode
- 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
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#block_body_codes ⇒ Object
readonly
Returns the value of attribute block_body_codes.
-
#call_node ⇒ Object
readonly
Returns the value of attribute call_node.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#tag_name ⇒ Object
readonly
Returns the value of attribute tag_name.
Class Method Summary collapse
- .build_helper(call_node, block_body_codes: nil, block_has_text_children: false, configuration: Configuration.new) ⇒ Object
- .build_tag(call_node, children: [], text_content: false, configuration: Configuration.new) ⇒ Object
- .kwarg_class_values(call_node) ⇒ Object
Instance Method Summary collapse
- #attribute?(name) ⇒ Boolean
- #block_has_text_children? ⇒ Boolean
-
#initialize(line:, tag_name: nil, attributes: {}, call_node: nil, children: [], block_body_codes: nil, block_has_text_children: false, text_content: false, configuration: Configuration.new) ⇒ PhlexNode
constructor
rubocop:disable Metrics/ParameterLists.
-
#ruby_code ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #text_content? ⇒ Boolean
Methods included from PhlexTags
Methods included from BlockInspection
Constructor Details
#initialize(line:, tag_name: nil, attributes: {}, call_node: nil, children: [], block_body_codes: nil, block_has_text_children: false, text_content: false, configuration: Configuration.new) ⇒ PhlexNode
rubocop:disable Metrics/ParameterLists
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/a11y/lint/phlex_node.rb', line 22 def initialize( line:, tag_name: nil, attributes: {}, call_node: nil, children: [], block_body_codes: nil, block_has_text_children: false, text_content: false, configuration: Configuration.new ) @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 @text_content = text_content @configuration = configuration end |
Instance Attribute Details
#attributes ⇒ Object (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_codes ⇒ Object (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_node ⇒ Object (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 |
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/a11y/lint/phlex_node.rb', line 11 def children @children end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/a11y/lint/phlex_node.rb', line 11 def configuration @configuration end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
11 12 13 |
# File 'lib/a11y/lint/phlex_node.rb', line 11 def line @line end |
#tag_name ⇒ Object (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, configuration: Configuration.new) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/a11y/lint/phlex_node.rb', line 73 def self.build_helper( call_node, block_body_codes: nil, block_has_text_children: false, configuration: Configuration.new ) 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, configuration: configuration ) end |
.build_tag(call_node, children: [], text_content: false, configuration: Configuration.new) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/a11y/lint/phlex_node.rb', line 58 def self.build_tag( call_node, children: [], text_content: false, configuration: Configuration.new ) 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, text_content: text_content, configuration: configuration ) end |
.kwarg_class_values(call_node) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/a11y/lint/phlex_node.rb', line 88 def self.kwarg_class_values(call_node) return [] unless call_node.arguments value = kwarg_nodes(call_node).find do |elem| kwarg_key(elem.key) == "class" end&.value value.is_a?(Prism::StringNode) ? value.unescaped.split : [] end |
Instance Method Details
#attribute?(name) ⇒ Boolean
46 47 48 |
# File 'lib/a11y/lint/phlex_node.rb', line 46 def attribute?(name) attributes.key?(name) end |
#block_has_text_children? ⇒ Boolean
50 51 52 |
# File 'lib/a11y/lint/phlex_node.rb', line 50 def block_has_text_children? @block_has_text_children end |
#ruby_code ⇒ Object
rubocop:enable Metrics/ParameterLists
42 43 44 |
# File 'lib/a11y/lint/phlex_node.rb', line 42 def ruby_code nil end |
#text_content? ⇒ Boolean
54 55 56 |
# File 'lib/a11y/lint/phlex_node.rb', line 54 def text_content? @text_content end |