Class: ApiDocGeneration::Generation

Inherits:
Object
  • Object
show all
Defined in:
lib/api_doc_generation/generation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codes_path = nil, title = '', opts = {}) ⇒ Generation

Returns a new instance of Generation.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api_doc_generation/generation.rb', line 10

def initialize(codes_path = nil, title = '', opts = {})
  codes_path ||= File.expand_path('app/controllers/api', Rails.root)
  @controller_documents = []
  @title = title
  @opts = opts

  each_api_controllers_file(codes_path) do |path|
    ctrl_doc = FormatFile.analyze_file(path)
    next if ctrl_doc['About']['Desc'].nil? || ctrl_doc['About']['Desc'].length == 0
    next if ctrl_doc['Actions'].length == 0
    @controller_documents << ctrl_doc
  end
end

Instance Attribute Details

#controller_documentsObject (readonly)

Returns the value of attribute controller_documents.



8
9
10
# File 'lib/api_doc_generation/generation.rb', line 8

def controller_documents
  @controller_documents
end

Instance Method Details

#generate_detailed_html_string(opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/api_doc_generation/generation.rb', line 35

def generate_detailed_html_string(opts = {})
  path = File.read(File.expand_path('templates/doc_detailed.html.erb', ROOT_PATH))

  ViewHelper.render(ERB.new(path), opts.merge({
    :documents => @controller_documents,
    :title => @title
  }), path)
end

#generate_html_string(opts = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/api_doc_generation/generation.rb', line 25

def generate_html_string(opts = {})
  path = File.read(File.expand_path('templates/doc.html.erb', ROOT_PATH))

  ViewHelper.render(ERB.new(path), opts.merge({
    :documents => @controller_documents,
    :title => @title
  }), path)
end