Class: Madness::TableOfContents

Inherits:
Object
  • Object
show all
Includes:
ServerHelper
Defined in:
lib/madness/table_of_contents.rb

Overview

Generate a markdown Table of Contents

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ServerHelper

#config, #docroot, #log

Constructor Details

#initialize(dir = nil) ⇒ TableOfContents

Returns a new instance of TableOfContents.



8
9
10
# File 'lib/madness/table_of_contents.rb', line 8

def initialize(dir=nil)
  @dir = dir || docroot
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/madness/table_of_contents.rb', line 6

def dir
  @dir
end

Instance Method Details

#build(file) ⇒ Object



12
13
14
15
# 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

#tocObject



17
18
19
# File 'lib/madness/table_of_contents.rb', line 17

def toc
  @toc ||= toc!.join("\n")
end