Class: ComponentEmbeddedRuby::Node
- Inherits:
-
Object
- Object
- ComponentEmbeddedRuby::Node
- Defined in:
- lib/component_embedded_ruby/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#component? ⇒ Boolean
If the tag starts with a capital, we assume it’s a component.
- #component_class ⇒ Object
- #html? ⇒ Boolean
-
#initialize(tag, attributes, children) ⇒ Node
constructor
A new instance of Node.
- #output_ruby? ⇒ Boolean
- #ruby? ⇒ Boolean
- #text? ⇒ Boolean
Constructor Details
#initialize(tag, attributes, children) ⇒ Node
Returns a new instance of Node.
5 6 7 8 9 |
# File 'lib/component_embedded_ruby/node.rb', line 5 def initialize(tag, attributes, children) @tag = tag @attributes = attributes @children = children end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/component_embedded_ruby/node.rb', line 3 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/component_embedded_ruby/node.rb', line 3 def children @children end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
3 4 5 |
# File 'lib/component_embedded_ruby/node.rb', line 3 def tag @tag end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/component_embedded_ruby/node.rb', line 11 def ==(other) if other other.tag == tag && other.attributes == attributes && other.children == children else false end end |
#component? ⇒ Boolean
If the tag starts with a capital, we assume it’s a component
24 25 26 |
# File 'lib/component_embedded_ruby/node.rb', line 24 def component? @_component ||= tag && !!/[[:upper:]]/.match(tag[0]) end |
#component_class ⇒ Object
19 20 21 |
# File 'lib/component_embedded_ruby/node.rb', line 19 def component_class @_component_class = Object.const_get(tag) end |
#html? ⇒ Boolean
40 41 42 |
# File 'lib/component_embedded_ruby/node.rb', line 40 def html? !component? && tag end |
#output_ruby? ⇒ Boolean
32 33 34 |
# File 'lib/component_embedded_ruby/node.rb', line 32 def output_ruby? ruby? && children.output end |
#ruby? ⇒ Boolean
28 29 30 |
# File 'lib/component_embedded_ruby/node.rb', line 28 def ruby? children.is_a?(Eval) end |
#text? ⇒ Boolean
36 37 38 |
# File 'lib/component_embedded_ruby/node.rb', line 36 def text? tag.nil? && !ruby? end |