Class: Asciidoctor::AbstractNode

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-multipage.rb

Instance Method Summary collapse

Instance Method Details

Is this node (self) of interest when generating a TOC for node?

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/asciidoctor-multipage.rb', line 13

def related_to?(node)
  return true if self.level == 0
  node_tree = []
  current = node
  while current.class != Asciidoctor::Document
    node_tree << current
    current = current.parent
  end
  node_tree << current
  if node_tree.include?(self) ||
     node_tree.include?(self.parent)
    return true
  end
  # If this is a leaf page, include all child sections in TOC
  if node.mplevel == :leaf
    self_tree = []
    current = self
    while current && current.level >= node.level
      self_tree << current
      current = current.parent
    end
    return true if self_tree.include?(node)
  end
  return false
end