Sha256: 845b520bd769e4c983009c5042e561493617abdb91dc8b7f5b42aa97d1ec329b

Contents?: true

Size: 790 Bytes

Versions: 2

Compression:

Stored size: 790 Bytes

Contents

class GhostWriter::DocumentIndex
  attr_reader :output, :documents

  def initialize(output, documents, format)
    format_module = "GhostWriter::Format::#{format.to_s.classify}"
    extend(format_module.constantize)

    @output = output
    @documents = documents
  end

  def write_index_file
    if GhostWriter.github_base_url
      base_url = GhostWriter.github_base_url + "/"
    else
      base_url = ""
    end

    document_list = documents.flat_map do |output, docs|
      docs.map do |d|
        list(
          link(d.description, base_url + "#{d.relative_path}")
        )
      end
    end

    index_file = File.open("#{output}.#{extname}", "w")
    index_file.write paragraph(<<EOP)
#{headword("API Examples")}
#{document_list.join("\n")}
EOP
    index_file.close
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ghost_writer-0.4.1 lib/ghost_writer/document_index.rb
ghost_writer-0.4.0 lib/ghost_writer/document_index.rb