lib/infoboxer/navigation/sections.rb in infoboxer-0.3.1.pre vs lib/infoboxer/navigation/sections.rb in infoboxer-0.3.1

- old
+ new

@@ -1,7 +1,5 @@ -# encoding: utf-8 - module Infoboxer module Navigation # `Sections` module provides logical view on document strcture. # # From this module's point of view, each {Tree::Document Document} is a @@ -79,10 +77,22 @@ else @sections.select { |s| names.first === s.heading.text_ }.sections(*names[1..-1]) end end + def subsections(*names) + sections = names.map { |name| + heading = lookup_children(:Heading, text_: name).first + next unless heading + body = heading.next_siblings + .take_while { |n| !n.is_a?(Tree::Heading) || n.level > heading.level } + + Section.new(heading, body) + }.compact + Tree::Nodes.new(sections) + end + def lookup_children(*arg) if arg.include?(:Section) sections.find(*(arg - [:Section])) else super @@ -136,10 +146,10 @@ @in_sections = Tree::Nodes[] return @in_sections end body = heading.next_siblings - .take_while { |n| !n.is_a?(Tree::Heading) || n.level < heading.level } + .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 end