views:

45

answers:

3

I have several ruby and rails projects hosted in GitHub.

I wonder how I could create API documentation for these automatically?

Examples:

http://rake.rubyforge.org/

http://rspec.rubyforge.org/rspec/1.3.0/

Are there tutorials for creating this API docs in Ruby?

+2  A: 

http://rdoc.info ca help you creating documentation directly from your github repository, go to http://rdoc.info/projects/new to add your project.

jigfox
But how can I get the layout like the two examples I posted? I feel those are having a good standard layout.
never_had_a_name
And is it possible to generate these kind of docs automatically? http://www.ruby-whois.org/api/
never_had_a_name
+2  A: 

Both examples are generated using RDoc. The first one is the standard RDoc template, the second one is generated with Hanna.

You can easily generate the documentation using the RDoc command line tool or by creating a Rake task. For instance, this documentation is generated with the following task

begin
  require "hanna/rdoctask"
rescue LoadError
  require "rake/rdoctask"
end

# Generate documentation
Rake::RDocTask.new do |rd|
  rd.main = "README.rdoc"
  rd.rdoc_files.include("*.rdoc", "lib/**/*.rb")
  rd.rdoc_dir = "rdoc"
end

See the Rakefile for more details.

Simone Carletti
Is there a way to upload the docs generated to rubyforge automatically?
never_had_a_name
Yes, there is. Many libraries such as Echoe e Jeweler provide a rake task to upload the content to RubyForge. Otherwise, simply use a rsync command to do that. This is exactly what I do in my libraries (see the Rakefile).
Simone Carletti
+2  A: 

Github provides service hooks on a per-repository basis (that is, you can enable it for this or that repo, but not these other two over here). One of the hooks is tied into rdoc.info, which uses Yard to produce spiffy documentation. (Yard itself is similar to rdoc. If you know rdoc, you won't have any trouble picking up Yard.) Example: Yard's own docs.

In your repo, go to Admin -> Service Hooks and poke around. (See the note on this page for information about how to customize what files are scanned for documentation within a repository.)

Telemachus
Why doesn't Rdoc.info uses rdoc to generate documentation instead?
never_had_a_name
@ajsie If you are already using `rdoc`, Rdoc.info will work fine. `yard` is a superset of `rdoc`, I believe. They're not incompatible. The reason that Rdoc.info uses `yard` is that one of the site creators is also the creator of `yard` and the people who build Rdoc.info probably believe `yard` is more powerful than `rdoc`.
Telemachus
Note also that if you connect to Rdoc.info, then docs are automatically regenerated whenever you push to Github (via the service hook).
Telemachus
But if I use rdoc to generate documentation from all files, how to i upload it to rdoc.info? I just create account and upload it manually?
never_had_a_name
@ajsie You don't need to do all of that. Simply write the rdoc in your files as normal. Every time you commit, the hook will scan your files and update whatever documentation it finds and place the docs up on rdoc.info. That's part of the beauty of it: no manual step is needed to make or update the docs.
Telemachus