lib/nanoc/toolbox/helpers/navigation.rb
def find_toc_sections(section, section_xpath, title_level=1)
      return {} unless section.xpath(section_xpath)

      # For each section found call the find_toc_sections on it with an
      # increased header level (ex: h1 => h2) and then generate the hash res
      sections = section.xpath(section_xpath).map do |subsection|
        header = subsection.css("h1, h2, h3, h4, h5, h6").first
        sub_id = subsection['id']
        sub_title = header ? header.inner_html : 'untitled'
        subsections = {}

        if subsection.xpath("#{section_xpath}") && title_level <= 6
          subsections = find_toc_sections(subsection, "#{section_xpath}", title_level+1)
        end
        { :title => sub_title, :link => '#' + sub_id, :subsections =>  subsections }
      end
    end
# Recursive method that extract from an XPath pattern the document structure
# and return the "permalinks" to each sections in an Array of Hash that
# could be used by the rendering method. The structure is deducted by the
# H1-6 header within the html element defined by the XPATH
Recursive method that extract from an XPath pattern the document structure
and return the "permalinks" to each sections in an Array of Hash that
could be used by the rendering method. The structure is deducted by the
H1-6 header within the html element defined by the XPATH
Recursive method that extract from an XPath pattern the document structure and return the " permalinks " to each sections in an Array of Hash that could be used by the rendering method . The structure is deducted by the H1 - 6 header within the html element defined by the XPATH
def find_toc_sections(section, section_xpath, title_level=1)
      return {} unless section.xpath(section_xpath)
      sections = section.xpath(section_xpath).map do |subsection|
        header = subsection.css("h1, h2, h3, h4, h5, h6").first
        sub_id = subsection['id']
        sub_title = header ? header.inner_html : 'untitled'
        subsections = {}
        if subsection.xpath("#{section_xpath}") && title_level <= 6
          subsections = find_toc_sections(subsection, "#{section_xpath}", title_level+1)
        end
        { :title => sub_title, :link => '#' + sub_id, :subsections =>  subsections }
      end
    end
def find_toc_sections ( section , section_xpath , title_level = 1 ) return { } unless section . xpath ( section_xpath ) sections = section . xpath ( section_xpath ) . map do | subsection | header = subsection . css ( "h1, h2, h3, h4, h5, h6" ) . first sub_id = subsection [ 'id' ] sub_title = header ? header . inner_html : 'untitled' subsections = { } if subsection . xpath ( "#{section_xpath}" ) && title_level <= 6 subsections = find_toc_sections ( subsection , "#{section_xpath}" , title_level + 1 ) end { :title => sub_title , :link => '#' + sub_id , :subsections => subsections } end end
Recursive method that extract from an XPath pattern the document structure
and return the "permalinks" to each sections in an Array of Hash that
could be used by the rendering method.
Recursive method that extract from an XPath pattern the document structure and return the " permalinks " to each sections in an Array of Hash that could be used by the rendering method .
# For each section found call the find_toc_sections on it with an # increased header level (ex: h1 => h2) and then generate the hash res
section
section_xpath
title_level