Class: Katalyst::Content::HasTree::Builder
- Inherits:
-
Object
- Object
- Katalyst::Content::HasTree::Builder
- Defined in:
- app/models/concerns/katalyst/content/has_tree.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #add(node) ⇒ Object
- #add_sibling(node) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
16 17 18 19 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 16 def initialize @depth = 0 @children = @tree = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def children @children end |
#current ⇒ Object
Returns the value of attribute current.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def current @current end |
#depth ⇒ Object
Returns the value of attribute depth.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def depth @depth end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def tree @tree end |
Instance Method Details
#add(node) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 21 def add(node) if node.depth == depth add_sibling(node) elsif node.depth > depth push(children.last) add(node) else pop add(node) end end |
#add_sibling(node) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 33 def add_sibling(node) node.parent = current previous = children.last children << node if previous previous.next_sibling = node node.previous_sibling = previous end # If the node does not have an explicit theme set already then set a # rendering theme from context. if node.theme.blank? node.theme = current ? current.theme : Content.config.default_theme end self end |