Module: Infoboxer::Navigation::Sections::Node

Included in:
Tree::Node
Defined in:
lib/infoboxer/navigation/sections.rb

Overview

Part of Infoboxer::Navigation::Sections navigation, allowing each node to know exact list of sections it contained in.

See also parent module documentation.

Instance Method Summary collapse

Instance Method Details

#in_sectionsTree::Nodes<Section>

List of sections current node contained in (bottom-to-top: smallest section first).

Returns:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/infoboxer/navigation/sections.rb', line 139

def in_sections
  return parent.in_sections unless parent.is_a?(Tree::Document)
  return @in_sections if @in_sections

  heading =
    if is_a?(Tree::Heading)
      lookup_prev_sibling(Tree::Heading, level: level - 1)
    else
      lookup_prev_sibling(Tree::Heading)
    end
  unless heading
    @in_sections = Tree::Nodes[]
    return @in_sections
  end

  body = heading.next_siblings
                .take_while { |n| !n.is_a?(Tree::Heading) || n.level > heading.level }

  section = Section.new(heading, body)
  @in_sections = Tree::Nodes[section, *heading.in_sections]
end