Class: MiddlemanToc::Node

Inherits:
Struct
  • Object
show all
Defined in:
lib/middleman_toc/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



5
6
7
# File 'lib/middleman_toc/node.rb', line 5

def active
  @active
end

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



4
5
6
# File 'lib/middleman_toc/node.rb', line 4

def children
  @children
end

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



4
5
6
# File 'lib/middleman_toc/node.rb', line 4

def level
  @level
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/middleman_toc/node.rb', line 4

def path
  @path
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


32
33
34
# File 'lib/middleman_toc/node.rb', line 32

def active?
  @active
end

#directory?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/middleman_toc/node.rb', line 28

def directory?
  children.any?
end

#expanded?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/middleman_toc/node.rb', line 36

def expanded?
  directory? && active? || children.any?(&:active?)
end

#flattenObject



7
8
9
# File 'lib/middleman_toc/node.rb', line 7

def flatten
  [self, children.map(&:flatten)].flatten
end

#renderObject



16
17
18
# File 'lib/middleman_toc/node.rb', line 16

def render
  Renderer.new(self).render
end

#root?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/middleman_toc/node.rb', line 24

def root?
  level == 0
end