Class: BetterHtml::Tree::Attribute
- Inherits:
-
Object
- Object
- BetterHtml::Tree::Attribute
- Defined in:
- lib/better_html/tree/attribute.rb
Instance Attribute Summary collapse
-
#equal_node ⇒ Object
readonly
Returns the value of attribute equal_node.
-
#name_node ⇒ Object
readonly
Returns the value of attribute name_node.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#value_node ⇒ Object
readonly
Returns the value of attribute value_node.
Class Method Summary collapse
Instance Method Summary collapse
- #erb? ⇒ Boolean
-
#initialize(node) ⇒ Attribute
constructor
A new instance of Attribute.
- #loc ⇒ Object
- #name ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(node) ⇒ Attribute
Returns a new instance of Attribute.
16 17 18 19 |
# File 'lib/better_html/tree/attribute.rb', line 16 def initialize(node) @node = node @name_node, @equal_node, @value_node = *node if @node.type == :attribute end |
Instance Attribute Details
#equal_node ⇒ Object (readonly)
Returns the value of attribute equal_node.
8 9 10 |
# File 'lib/better_html/tree/attribute.rb', line 8 def equal_node @equal_node end |
#name_node ⇒ Object (readonly)
Returns the value of attribute name_node.
8 9 10 |
# File 'lib/better_html/tree/attribute.rb', line 8 def name_node @name_node end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
8 9 10 |
# File 'lib/better_html/tree/attribute.rb', line 8 def node @node end |
#value_node ⇒ Object (readonly)
Returns the value of attribute value_node.
8 9 10 |
# File 'lib/better_html/tree/attribute.rb', line 8 def value_node @value_node end |
Class Method Details
.from_node(node) ⇒ Object
11 12 13 |
# File 'lib/better_html/tree/attribute.rb', line 11 def from_node(node) new(node) end |
Instance Method Details
#erb? ⇒ Boolean
21 22 23 |
# File 'lib/better_html/tree/attribute.rb', line 21 def erb? @node.type == :erb end |
#loc ⇒ Object
25 26 27 |
# File 'lib/better_html/tree/attribute.rb', line 25 def loc @node.loc end |
#name ⇒ Object
29 30 31 |
# File 'lib/better_html/tree/attribute.rb', line 29 def name @name_node&.loc&.source&.downcase end |
#value ⇒ Object
33 34 35 36 |
# File 'lib/better_html/tree/attribute.rb', line 33 def value parts = value_node.to_a.reject { |node| node.is_a?(::AST::Node) && node.type == :quote } parts.map { |s| s.is_a?(::AST::Node) ? s.loc.source : CGI.unescapeHTML(s) }.join end |