lib/webby/filters/outline.rb
def toc
    ary = []

    lopen = "<#@toc_style>"
    lclose = "</#@toc_style>"
    prev_depth = open = 0

    @toc.each do |a|
      cur = a.first

      # close out the previous list item if we're at the same level
      if cur == prev_depth
        ary << "</li>"

      # if we are increasing the level, then start a new list
      elsif cur > prev_depth
        ary << if ary.empty? then @list_opening else lopen end
        open += 1

      # we are decreasing the level; close out tags but ensure we don't
      # close out all the tags (leave one open)
      else
        (prev_depth - cur).times {
          ary << "</li>" << lclose
          open -= 1
          break if open <= 0
        }
        if open > 0
          ary << "</li>"
        else
          ary << lopen
          open += 1
        end
      end

      # add the current element
      ary << "<li>" << a.last
      prev_depth = cur
    end

    # close out the remaingling tags
    ary << "</li>" << lclose
    ary.join("\n")
  end
# Returns the table of contents as a collection of nested ordered lists.
# This is fully formatted HTML.
#
Returns the table of contents as a collection of nested ordered lists.
This is fully formatted HTML.
Returns the table of contents as a collection of nested ordered lists . This is fully formatted HTML .
def toc
    ary = []
    lopen = "<#@toc_style>"
    lclose = "</#@toc_style>"
    prev_depth = open = 0
    @toc.each do |a|
      cur = a.first
      if cur == prev_depth
        ary << "</li>"
      elsif cur > prev_depth
        ary << if ary.empty? then @list_opening else lopen end
        open += 1
      else
        (prev_depth - cur).times {
          ary << "</li>" << lclose
          open -= 1
          break if open <= 0
        }
        if open > 0
          ary << "</li>"
        else
          ary << lopen
          open += 1
        end
      end
      ary << "<li>" << a.last
      prev_depth = cur
    end
    ary << "</li>" << lclose
    ary.join("\n")
  end
def toc ary = [ ] lopen = "<#@toc_style>" lclose = "</#@toc_style>" prev_depth = open = 0 @toc . each do | a | cur = a . first if cur == prev_depth ary << "</li>" elsif cur > prev_depth ary << if ary . empty? then @list_opening else lopen end open += 1 else ( prev_depth - cur ) . times { ary << "</li>" << lclose open -= 1 break if open <= 0 } if open > 0 ary << "</li>" else ary << lopen open += 1 end end ary << "<li>" << a . last prev_depth = cur end ary << "</li>" << lclose ary . join ( "\n" ) end
Returns the table of contents as a collection of nested ordered lists.
Returns the table of contents as a collection of nested ordered lists .
# close out the previous list item if we're at the same level # if we are increasing the level, then start a new list # we are decreasing the level; close out tags but ensure we don't # close out all the tags (leave one open) # add the current element # close out the remaingling tags