lib/infoboxer/navigation/sections.rb in infoboxer-0.3.0.pre vs lib/infoboxer/navigation/sections.rb in infoboxer-0.3.0
- old
+ new
@@ -121,28 +121,24 @@
# List of sections current node contained in (bottom-to-top:
# smallest section first).
#
# @return {Tree::Nodes<Section>}
def in_sections
- return parent.in_sections unless parent.is_a?(Tree::Document)
- return @in_sections if @in_sections
+ main_node = parent.is_a?(Tree::Document) ? self : lookup_parents[-2]
heading =
- if is_a?(Tree::Heading)
- lookup_prev_sibling(Tree::Heading, level: level - 1)
+ if main_node.is_a?(Tree::Heading)
+ main_node.lookup_prev_siblings(Tree::Heading, level: main_node.level - 1).last
else
- lookup_prev_sibling(Tree::Heading)
+ main_node.lookup_prev_siblings(Tree::Heading).last
end
- unless heading
- @in_sections = Tree::Nodes[]
- return @in_sections
- end
+ return Tree::Nodes[] unless heading
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]
+ Tree::Nodes[section, *heading.in_sections]
end
end
# Part of {Sections} navigation, allowing chains of section search.
#