class Autodoc::Documents

Public Class Methods

new() click to toggle source
# File lib/autodoc/documents.rb, line 5
def initialize
  @table = Hash.new {|table, key| table[key] = [] }
end

Public Instance Methods

append(context, example) click to toggle source
# File lib/autodoc/documents.rb, line 9
def append(context, example)
  document = Autodoc::Document.new(context.clone, example.clone)
  @table[document.pathname] << document
end
write() click to toggle source
# File lib/autodoc/documents.rb, line 14
def write
  write_toc if Autodoc.configuration.toc
  write_toc_html if Autodoc.configuration.toc_html

  write_documents
end

Private Instance Methods

render_toc() click to toggle source
# File lib/autodoc/documents.rb, line 35
def render_toc
  ERB.new(Autodoc.configuration.toc_template, trim_mode: "-").result(binding)
end
render_toc_html() click to toggle source
# File lib/autodoc/documents.rb, line 44
def render_toc_html
  ERB.new(Autodoc.configuration.toc_html_template, trim_mode: "-").result(binding)
end
toc_html_path() click to toggle source
# File lib/autodoc/documents.rb, line 52
def toc_html_path
  Autodoc.configuration.pathname + "toc.html"
end
toc_path() click to toggle source
# File lib/autodoc/documents.rb, line 48
def toc_path
  Autodoc.configuration.pathname + "toc.md"
end
write_documents() click to toggle source
# File lib/autodoc/documents.rb, line 23
def write_documents
  @table.each do |pathname, documents|
    pathname.parent.mkpath
    pathname.open("w") {|file| file << documents.sort_by(&:line_number).map(&:render).join("\n").rstrip + "\n" }
  end
end
write_toc() click to toggle source
# File lib/autodoc/documents.rb, line 30
def write_toc
  toc_path.parent.mkpath
  toc_path.open("w") {|file| file << render_toc }
end
write_toc_html() click to toggle source
# File lib/autodoc/documents.rb, line 39
def write_toc_html
  toc_html_path.parent.mkpath
  toc_html_path.open("w") {|file| file << render_toc_html }
end