Publishing Your Documentation

Credit: Stefan Lang


You want to automatically update your projects web site on RubyForge (or some other site) with generated documentation or custom pages.


As seen in Recipe 19.2, Rake provides a RDocTask for generating RDoc documentation:


	html_dir = doc/html
	library = MyLib
doc) do |t|
	 t.rdoc_files.include(README, lib/**/*.rb)
	 t.main = README
	 t.title = "#{library} API documentation"
	 t.rdoc_dir = html_dir

To upload your generated documentation to RubyForge, use this task along with the upload-docs task defined below. The Unix scp command-line tool does the actual work of uploading:

	# Define your RubyForge username and your projects Unix name here:
	rubyforge_user = user
	rubyforge_project = project
	rubyforge_path = "/var/www/gforge-projects/#{rubyforge_project}/"
	desc Upload documentation to RubyForge.
	task upload-docs => [
doc] do
	 sh "scp -r #{html_dir}/* " +


Set off the publishing process by invoking rake upload-docs. The upload-docs task has the rdoc task as a prerequisite, so the HTML pages under doc/html/ will be created if necessary.

Then scp prompts for your RubyForge account password. Enter it, and all files under doc/html/ and its subdirectories will be uploaded to RubyForge. The docs will become available under, where "project" is the Unix name of your project. Now your users can read your RDoc online without having to generate it themselves. Your documentation will also show up in web search results.

Rakes sh method starts an instance of the OSs standard shell. This feature is used to run the scp command-line tool. This means that this recipe will only work if scp is installed on your system.

The scp command copies all the files that the RDoc placed under doc/html/, to the root of your projects web site on the RubyForge server. In effect, the main page of the API documentation will appear as your projects homepage. Some RubyForge projects don have a custom homepage, so this is a good place to put the RDoc. If you want a custom homepage, just copy the RDoc into a different directory by changing rubyforge_path:

	rubyforge_path = "/var/www/gforge-projects/#{rubyforge_project}/rdoc/"

Youll have to manually create the rdoc directory before you can use the scp shortcut. After that, the generated RDoc will show up at, and you can link to it from your custom homepage with a relative link to rdoc/.

You can make Rake upload your custom homepage as well, of course. Just add an upload-site task that uploads your custom homepage and other web content. Make upload-site and upload-docs prerequisites of an overarching publish task:

	website_dir = site
	desc Update project website to RubyForge.
	task upload-site do
	 sh "scp -r #{website_dir}/* " +

	desc Update API docs and project website to RubyForge.
	task publish => [upload-docs, upload-site]

Now you can run rake publish to update the generated API documentation, and upload it together with the rest of the web site to RubyForge. The publish task can be just one more prerequisite for an overarching release task.

Of course, you can use this same technique if you e using a web host other than RubyForge: just change the destination host of the scp command.

See Also

  • Recipe 17.11, "Documenting Your Application," covers writing RDoc documentation
  • Recipe 19.2, "Automatically Generating Documentation"



Date and Time



Files and Directories

Code Blocks and Iteration

Objects and Classes8

Modules and Namespaces

Reflection and Metaprogramming


Graphics and Other File Formats

Databases and Persistence

Internet Services

Web Development Ruby on Rails

Web Services and Distributed Programming

Testing, Debugging, Optimizing, and Documenting

Packaging and Distributing Software

Automating Tasks with Rake

Multitasking and Multithreading

User Interface

Extending Ruby with Other Languages

System Administration

Ruby Cookbook
Ruby Cookbook (Cookbooks (OReilly))
ISBN: 0596523696
EAN: 2147483647
Year: N/A
Pages: 399 © 2008-2020.
If you may any questions please contact us: