Class: RspecApiDocumentation::Writers::SlateWriter

Inherits:
MarkdownWriter show all
Defined in:
lib/rspec_api_documentation/writers/slate_writer.rb

Constant Summary collapse

EXTENSION =
'html.md'
FILENAME =
'index'

Constants inherited from GeneralMarkupWriter

GeneralMarkupWriter::INDEX_FILE_NAME

Instance Attribute Summary

Attributes inherited from Writer

#configuration, #index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GeneralMarkupWriter

#index_file_name

Methods inherited from Writer

#initialize, write

Constructor Details

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

Class Method Details

.clear_docs(docs_dir) ⇒ Object



8
9
10
11
# File 'lib/rspec_api_documentation/writers/slate_writer.rb', line 8

def self.clear_docs(docs_dir)
  FileUtils.mkdir_p(docs_dir)
  FileUtils.rm Dir[File.join docs_dir, "#{FILENAME}.*"]
end

Instance Method Details

#extension ⇒ Object



40
41
42
# File 'lib/rspec_api_documentation/writers/slate_writer.rb', line 40

def extension
  EXTENSION
end

#markup_example_class ⇒ Object



17
18
19
# File 'lib/rspec_api_documentation/writers/slate_writer.rb', line 17

def markup_example_class
  RspecApiDocumentation::Views::SlateExample
end

#markup_index_class ⇒ Object



13
14
15
# File 'lib/rspec_api_documentation/writers/slate_writer.rb', line 13

def markup_index_class
  RspecApiDocumentation::Views::SlateIndex
end

#write ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec_api_documentation/writers/slate_writer.rb', line 21

def write
  File.open(configuration.docs_dir.join("#{FILENAME}.#{extension}"), 'w+') do |file|

    file.write markup_index_class.new(index, configuration).render

    IndexHelper.sections(index.examples, @configuration).each do |section|
      file.write "# #{section[:resource_name]}\n\n"
      file.write "#{section[:resource_explanation]}\n\n"

      section[:examples].each do |example|
        markup_example = markup_example_class.new(example, configuration)
        file.write markup_example.render
      end

    end

  end
end