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.
7 8 9 10 11 |
# File 'lib/component_embedded_ruby/node.rb', line 7 def initialize(tag, attributes, children) @tag = tag @attributes = attributes @children = children end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/component_embedded_ruby/node.rb', line 5 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/component_embedded_ruby/node.rb', line 5 def children @children end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
5 6 7 |
# File 'lib/component_embedded_ruby/node.rb', line 5 def tag @tag end |
Instance Method Details
#==(other) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/component_embedded_ruby/node.rb', line 13 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
26 27 28 |
# File 'lib/component_embedded_ruby/node.rb', line 26 def component? @_component ||= tag && !!/[[:upper:]]/.match(tag[0]) end |
#component_class ⇒ Object
21 22 23 |
# File 'lib/component_embedded_ruby/node.rb', line 21 def component_class @_component_class = Object.const_get(tag) end |
#html? ⇒ Boolean
42 43 44 |
# File 'lib/component_embedded_ruby/node.rb', line 42 def html? !component? && tag end |
#output_ruby? ⇒ Boolean
34 35 36 |
# File 'lib/component_embedded_ruby/node.rb', line 34 def output_ruby? ruby? && children.output end |
#ruby? ⇒ Boolean
30 31 32 |
# File 'lib/component_embedded_ruby/node.rb', line 30 def ruby? children.is_a?(Eval) end |
#text? ⇒ Boolean
38 39 40 |
# File 'lib/component_embedded_ruby/node.rb', line 38 def text? tag.nil? && !ruby? end |