Class: RubyUIConverter::Nodes::Element
- Defined in:
- lib/ruby_ui_converter/nodes.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#self_closing ⇒ Object
Returns the value of attribute self_closing.
Instance Method Summary collapse
- #attr?(name) ⇒ Boolean
-
#initialize(name:, attributes: [], self_closing: false) ⇒ Element
constructor
A new instance of Element.
-
#static_attr(name) ⇒ Object
Returns the literal value of an attribute when it has no ERB parts, otherwise nil.
-
#static_classes ⇒ Object
Returns the static CSS classes when the ‘class` attribute has no ERB, otherwise an empty array.
Constructor Details
#initialize(name:, attributes: [], self_closing: false) ⇒ Element
Returns a new instance of Element.
25 26 27 28 29 30 |
# File 'lib/ruby_ui_converter/nodes.rb', line 25 def initialize(name:, attributes: [], self_closing: false) @name = name @attributes = attributes @children = [] @self_closing = self_closing end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
22 23 24 |
# File 'lib/ruby_ui_converter/nodes.rb', line 22 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
22 23 24 |
# File 'lib/ruby_ui_converter/nodes.rb', line 22 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/ruby_ui_converter/nodes.rb', line 22 def name @name end |
#self_closing ⇒ Object
Returns the value of attribute self_closing.
23 24 25 |
# File 'lib/ruby_ui_converter/nodes.rb', line 23 def self_closing @self_closing end |
Instance Method Details
#attr?(name) ⇒ Boolean
48 49 50 |
# File 'lib/ruby_ui_converter/nodes.rb', line 48 def attr?(name) attributes.any? { |attr_name, _| attr_name == name } end |
#static_attr(name) ⇒ Object
Returns the literal value of an attribute when it has no ERB parts, otherwise nil. Useful for ComponentMap matchers/emitters.
34 35 36 37 38 39 40 |
# File 'lib/ruby_ui_converter/nodes.rb', line 34 def static_attr(name) attr = attributes.find { |attr_name, _| attr_name == name } return nil unless attr && attr[1] return nil unless attr[1].all? { |kind, _| kind == :text } attr[1].map { |_, value| value }.join end |
#static_classes ⇒ Object
Returns the static CSS classes when the ‘class` attribute has no ERB, otherwise an empty array. Useful for ComponentMap matchers.
44 45 46 |
# File 'lib/ruby_ui_converter/nodes.rb', line 44 def static_classes static_attr("class").to_s.split end |