Class: A11y::Lint::PhlexNode
- Inherits:
-
Object
- Object
- A11y::Lint::PhlexNode
- 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 collapse
- TAG_ALIASES =
Phlex method names that map to a different HTML tag.
{ "ruby_element" => "ruby", "template_tag" => "template" }.freeze
- HTML_TAGS =
Set.new( %w[ a abbr address article aside b bdi bdo blockquote body br button caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd label legend li link main map mark menu meter nav noscript object ol optgroup option output p picture pre progress q rp rt ruby_element s samp script search section select slot small span strong style sub summary sup table tbody td template_tag textarea tfoot th thead time title tr u ul var video wbr ] ).freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Class Method Summary collapse
- .build_helper(call_node, source) ⇒ Object
- .build_tag(call_node, children: []) ⇒ Object
- .html_tag?(method_name) ⇒ Boolean
- .html_tag_name(method_name) ⇒ Object
Instance Method Summary collapse
- #attribute?(name) ⇒ Boolean
- #attributes ⇒ Object
-
#initialize(line:, tag_name: nil, attributes: {}, ruby_code: nil, children: []) ⇒ PhlexNode
constructor
A new instance of PhlexNode.
- #ruby_code ⇒ Object
- #tag_name ⇒ Object
Constructor Details
#initialize(line:, tag_name: nil, attributes: {}, ruby_code: nil, children: []) ⇒ PhlexNode
Returns a new instance of PhlexNode.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/a11y/lint/phlex_node.rb', line 35 def initialize( line:, tag_name: nil, attributes: {}, ruby_code: nil, children: [] ) @tag_name_string = tag_name @attributes_hash = attributes @ruby_code_string = ruby_code @line = line @children = children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/a11y/lint/phlex_node.rb', line 8 def children @children end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
8 9 10 |
# File 'lib/a11y/lint/phlex_node.rb', line 8 def line @line end |
Class Method Details
.build_helper(call_node, source) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/a11y/lint/phlex_node.rb', line 80 def self.build_helper(call_node, source) new( ruby_code: ruby_code_for(call_node, source), line: call_node.location.start_line ) end |
.build_tag(call_node, children: []) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/a11y/lint/phlex_node.rb', line 70 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 |
.html_tag?(method_name) ⇒ Boolean
62 63 64 |
# File 'lib/a11y/lint/phlex_node.rb', line 62 def self.html_tag?(method_name) HTML_TAGS.include?(method_name) end |
.html_tag_name(method_name) ⇒ Object
66 67 68 |
# File 'lib/a11y/lint/phlex_node.rb', line 66 def self.html_tag_name(method_name) TAG_ALIASES.fetch(method_name, method_name) end |
Instance Method Details
#attribute?(name) ⇒ Boolean
50 51 52 |
# File 'lib/a11y/lint/phlex_node.rb', line 50 def attribute?(name) @attributes_hash.key?(name) end |
#attributes ⇒ Object
54 55 56 |
# File 'lib/a11y/lint/phlex_node.rb', line 54 def attributes @attributes_hash end |
#ruby_code ⇒ Object
58 59 60 |
# File 'lib/a11y/lint/phlex_node.rb', line 58 def ruby_code @ruby_code_string end |
#tag_name ⇒ Object
46 47 48 |
# File 'lib/a11y/lint/phlex_node.rb', line 46 def tag_name @tag_name_string end |