Class: MiddlemanToc::Node
- Inherits:
-
Struct
- Object
- Struct
- MiddlemanToc::Node
- Defined in:
- lib/middleman_toc/node.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#children ⇒ Object
Returns the value of attribute children.
-
#level ⇒ Object
Returns the value of attribute level.
-
#path ⇒ Object
Returns the value of attribute path.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #activate(path) ⇒ Object
- #active? ⇒ Boolean
- #directory? ⇒ Boolean
- #expanded? ⇒ Boolean
- #flatten ⇒ Object
- #render ⇒ Object
- #root? ⇒ Boolean
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
5 6 7 |
# File 'lib/middleman_toc/node.rb', line 5 def active @active end |
#children ⇒ Object
Returns the value of attribute children
4 5 6 |
# File 'lib/middleman_toc/node.rb', line 4 def children @children end |
#level ⇒ Object
Returns the value of attribute level
4 5 6 |
# File 'lib/middleman_toc/node.rb', line 4 def level @level end |
#path ⇒ Object
Returns the value of attribute path
4 5 6 |
# File 'lib/middleman_toc/node.rb', line 4 def path @path end |
#title ⇒ Object
Returns the value of attribute title
4 5 6 |
# File 'lib/middleman_toc/node.rb', line 4 def title @title end |
Instance Method Details
#activate(path) ⇒ Object
11 12 13 14 |
# File 'lib/middleman_toc/node.rb', line 11 def activate(path) @active = path == self.path children.each { |child| child.activate(path) } end |
#active? ⇒ Boolean
32 33 34 |
# File 'lib/middleman_toc/node.rb', line 32 def active? @active end |
#directory? ⇒ Boolean
28 29 30 |
# File 'lib/middleman_toc/node.rb', line 28 def directory? children.any? end |
#expanded? ⇒ Boolean
36 37 38 |
# File 'lib/middleman_toc/node.rb', line 36 def directory? && active? || children.any?(&:active?) end |
#flatten ⇒ Object
7 8 9 |
# File 'lib/middleman_toc/node.rb', line 7 def flatten [self, children.map(&:flatten)].flatten end |
#render ⇒ Object
16 17 18 |
# File 'lib/middleman_toc/node.rb', line 16 def render Renderer.new(self).render end |
#root? ⇒ Boolean
24 25 26 |
# File 'lib/middleman_toc/node.rb', line 24 def root? level == 0 end |