Class: RDoc::Generator::Docapi

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/generator/docapi.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Docapi

Returns a new instance of Docapi.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rdoc/generator/docapi.rb', line 23

def initialize(options)
  @options = options
    
  # set up a hash to keep track of all the classes/modules we have processed
  @already_processed = {}
    
  # set up a hash to keep track of all of the objects to be output
  @output = {
    :files => [], 
    :classes => [], 
    :modules => [], 
    :attributes => [], 
    :methods => [], 
    :aliases => [], 
    :constants => [], 
    :requires => [], 
    :includes => []
  }
end

Class Method Details

.for(options) ⇒ Object



19
20
21
# File 'lib/rdoc/generator/docapi.rb', line 19

def self.for(options)
  new(options)
end

Instance Method Details

#generate(files) ⇒ Object

Rdoc passes in TopLevel objects from the code_objects.rb tree (all files)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rdoc/generator/docapi.rb', line 44

def generate(files)                             
  # Each object passed in is a file, process it
  files.each { |file| process_file(file) }

  h = ::RDoc::Markup::ToHtml.new
  
  yaml = YAML.dump({
    "methods" => @output[:methods].map{|method|
      next if method.visibility == :private
      {
        "name" => method.call_seq || method.name,
        "comment" => method.comment,
        "html_comment" => method.comment.nil? ? "" : h.convert(method.comment.gsub(/^#+ ?/, ''))
      }
    }.compact
  })
  
  puts yaml unless @options.quiet
  File.open("index.yaml", "w+") do |f|
     f << yaml
   end
end