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.
-
#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) ⇒ Object
- .build_tag(call_node, children: [], text_content: false) ⇒ 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) ⇒ 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) ⇒ PhlexNode
rubocop:disable Metrics/ParameterLists
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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, text_content: 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 @text_content = text_content 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 |
#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) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/a11y/lint/phlex_node.rb', line 66 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: [], text_content: false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/a11y/lint/phlex_node.rb', line 55 def self.build_tag(call_node, children: [], text_content: false) 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 ) end |
Instance Method Details
#attribute?(name) ⇒ Boolean
43 44 45 |
# File 'lib/a11y/lint/phlex_node.rb', line 43 def attribute?(name) attributes.key?(name) end |
#block_has_text_children? ⇒ Boolean
47 48 49 |
# File 'lib/a11y/lint/phlex_node.rb', line 47 def block_has_text_children? @block_has_text_children end |
#ruby_code ⇒ Object
rubocop:enable Metrics/ParameterLists
39 40 41 |
# File 'lib/a11y/lint/phlex_node.rb', line 39 def ruby_code nil end |
#text_content? ⇒ Boolean
51 52 53 |
# File 'lib/a11y/lint/phlex_node.rb', line 51 def text_content? @text_content end |