Class: RspecApiDocumentation::Writers::GeneralMarkupWriter

Inherits:
Writer
  • Object
show all
Defined in:
lib/rspec_api_documentation/writers/general_markup_writer.rb

Overview

Base class for writers that write HTML

Constant Summary collapse

INDEX_FILE_NAME =
'index'

Instance Attribute Summary

Attributes inherited from Writer

#configuration, #index

Instance Method Summary collapse

Methods inherited from Writer

clear_docs, #initialize, write

Constructor Details

This class inherits a constructor from RspecApiDocumentation::Writers::Writer

Instance Method Details

#extension ⇒ Object



31
32
33
# File 'lib/rspec_api_documentation/writers/general_markup_writer.rb', line 31

def extension
  raise 'Parent class. This method should not be called.'
end

#index_file_name ⇒ Object



27
28
29
# File 'lib/rspec_api_documentation/writers/general_markup_writer.rb', line 27

def index_file_name
  INDEX_FILE_NAME
end

#write ⇒ Object

Write out the generated documentation



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec_api_documentation/writers/general_markup_writer.rb', line 8

def write
  if render_options.fetch(:index, true)
    File.open(configuration.docs_dir.join(index_file_name + '.' + extension), "w+") do |f|
      f.write markup_index_class.new(index, configuration).render
    end
  end

  if render_options.fetch(:examples, true)
    index.examples.each do |example|
      markup_example = markup_example_class.new(example, configuration)
      FileUtils.mkdir_p(configuration.docs_dir.join(markup_example.dirname))

      File.open(configuration.docs_dir.join(markup_example.dirname, markup_example.filename), "w+") do |f|
        f.write markup_example.render
      end
    end
  end
end