Class: GrapeDoc::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/doc/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/grape/doc/generator.rb', line 6

def initialize(opts={})

  raise(ArgumentError,'invalid options given') unless opts.class <= Hash
  @options = {
      'format' => 'html',
      'path'   => File.join(Helpers.doc_folder_path,'api_doc')
  }.merge(opts.reduce({}){|m,o| m.merge!(o[0].to_s => o[1]) ;m})
  self.options['path'] = self.options['path'].to_s.sub(/\..*$/,'')

  process_head
  process_endpoints
  process_table_of_content

end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/grape/doc/generator.rb', line 5

def options
  @options
end

Instance Method Details

#saveObject Also known as: save!



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/grape/doc/generator.rb', line 21

def save

  case @options['format'].to_s.downcase

    when /redmine/,/textile/
      File.write self.options['path'] + '.textile',
                 document.to_textile

    else
      File.write self.options['path'] + '.html',
                 document.to_textile.to_html


  end

  true;rescue;false
end