Skip to content

Instantly share code, notes, and snippets.

@reborg
Forked from colszowka/gist:63948
Created March 2, 2009 14:33
Show Gist options
  • Save reborg/72763 to your computer and use it in GitHub Desktop.
Save reborg/72763 to your computer and use it in GitHub Desktop.
#
# Will find the rdoc paths of your local gems and generate a html index frameset which will let you select
# the desired gem's rdoc from a dropdown navigation...
#
# Specify your local gems installation's doc directory and the desired html output path, open the generated index.html
# in the output path in your favorite browser and add a boomark.
# You might want to add the script into your path for easy access or put it in a cron job.
#
# Tested on Ubuntu 8.10, but really should work anywhere with proper gem install path set
# Working on Mac Os with custom Ruby install in /usr/local
#
# Reborg's changes:
# => just wanted a white page with all gem links on it, no dropdown or fancy style
# => published in ~/Sites and available from http://<localhost>.local/~<user>/local_gems.html on Mac
#
# Written by Christoph Olszowka, http://blog.olszowka.de, http://blog.olszowka.de/2009/02/13/rdoc-index-for-your-gems/
# Forked by Reborg, http://reborg.net, 20090302
#
#!/usr/bin/ruby
require 'fileutils'
# Path to your gems installations documentation directory
GemsDocPath = '/usr/local/lib/ruby/gems/1.8/doc'
# Path for your html output
OutputPath = File.expand_path('~/Sites')
# Create output path if non-existent
FileUtils.mkdir_p OutputPath
# Basic class for holding the gem name and rdoc_path and url generation for links
class GemDoc
attr_accessor :name, :rdoc_path
def initialize(name, rdoc_path)
@name = name
@rdoc_path = rdoc_path
end
def url
"file://#{rdoc_path}"
end
end
# Setup the gemdocs array
gemdocs = Array.new
# Iterate over all gems found in GemsDocPath
Dir[File.join(GemsDocPath, '*')].sort.each do |gem_doc_dir|
# Check if the gem has rdoc, add it to the list of documented gems
if File.directory? gem_doc_dir and File.exist?(gem_rdoc_path = File.join(gem_doc_dir, 'rdoc', 'index.html'))
gemdocs << GemDoc.new(File.basename(gem_doc_dir), gem_rdoc_path)
end
end
File.open(File.join(OutputPath, "local_gems.html"), "w+") do |html|
html.puts '<html><head></head><body>
<div>Updated: ' + Time.now.to_s + '</div>'
gemdocs.sort_by {|gem| gem.name.downcase }.each do |gem|
html.puts "<div><a href=\"#{gem.url}\">#{gem.name}</a></div>"
end
html.puts '</body></html>'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment