Class: Dato::Node
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Dato::Node
- Defined in:
- app/components/dato/node.rb
Direct Known Subclasses
DastNode, ImageBlockRecord, InlineItem, ResponsiveImage, StructuredText, UnknownBlock
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #blocks ⇒ Object
- #debug_node ⇒ Object
-
#find_ancestor(type) ⇒ Node?
Find the first ancestor of a specific type.
-
#initialize(node, root = nil, parent = nil) ⇒ Node
constructor
A new instance of Node.
- #links ⇒ Object
-
#node_type ⇒ String?
Get the type of the immediate parent node.
- #overrides ⇒ Object
- #parent_type ⇒ Object
- #render_node(node) ⇒ Object
Constructor Details
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'app/components/dato/node.rb', line 5 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'app/components/dato/node.rb', line 5 def parent @parent end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'app/components/dato/node.rb', line 5 def root @root end |
Instance Method Details
#blocks ⇒ Object
35 36 37 |
# File 'app/components/dato/node.rb', line 35 def blocks root.blocks end |
#debug_node ⇒ Object
47 48 49 |
# File 'app/components/dato/node.rb', line 47 def debug_node content_tag("pre", JSON.pretty_generate(@node)) end |
#find_ancestor(type) ⇒ Node?
Find the first ancestor of a specific type
20 21 22 23 24 25 26 27 |
# File 'app/components/dato/node.rb', line 20 def find_ancestor(type) current = parent while current return current if current.node_type == type current = current.parent end nil end |
#links ⇒ Object
39 40 41 |
# File 'app/components/dato/node.rb', line 39 def links root.links end |
#node_type ⇒ String?
Get the type of the immediate parent node
31 |
# File 'app/components/dato/node.rb', line 31 def node_type = node&.type |
#overrides ⇒ Object
43 44 45 |
# File 'app/components/dato/node.rb', line 43 def overrides root.overrides end |
#parent_type ⇒ Object
33 |
# File 'app/components/dato/node.rb', line 33 def parent_type = parent&.node_type |
#render_node(node) ⇒ Object
13 14 15 |
# File 'app/components/dato/node.rb', line 13 def render_node(node) render class_for_node(node).new(node, root, self) end |