class Madness::TableOfContents
Generate a markdown Table of Contents for the entire site
Attributes
dir[R]
Public Class Methods
new(dir = nil)
click to toggle source
# File lib/madness/table_of_contents.rb, line 8 def initialize(dir = nil) @dir = dir || docroot end
Public Instance Methods
build(file)
click to toggle source
# File lib/madness/table_of_contents.rb, line 12 def build(file) file += '.md' unless file.end_with? '.md' File.write "#{dir}/#{file}", toc end
toc()
click to toggle source
# File lib/madness/table_of_contents.rb, line 17 def toc @toc ||= toc!.join("\n") end
Private Instance Methods
make_link(item)
click to toggle source
# File lib/madness/table_of_contents.rb, line 39 def make_link(item) "[#{item.label}](#{item.href})" end
toc!(path = dir, indent = 0)
click to toggle source
# File lib/madness/table_of_contents.rb, line 23 def toc!(path = dir, indent = 0) list = Directory.new(path).list result = [] list.each do |item| case item.type when :dir result.push "#{' ' * indent}1. #{make_link item}" result += toc! item.path, indent + 4 when :file result.push "#{' ' * indent}1. #{make_link item}" end end result end