Created
February 13, 2009 15:19
-
-
Save colszowka/63948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 | |
# | |
# See http://blog.olszowka.de/2009/02/13/rdoc-index-for-your-gems/ for more info and even a nice screenshot! | |
# | |
# Disclaimer: No beautiful code, fancy templating stuff or even valid HTML in here, it's just intended to work :) | |
# | |
# Written by Christoph Olszowka, http://blog.olszowka.de | |
# | |
#!/usr/bin/ruby | |
require 'fileutils' | |
# Path to your gems installations documentation directory | |
GemsDocPath = '/usr/lib/ruby/gems/1.8/doc' | |
# Path for your html output | |
OutputPath = '/home/colszowka/rdoc' | |
# 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, "dropdown.html"), "w+") do |html| | |
html.puts '<html><head></head><body style="background-color: black; color: white;"><form><div style="float:right">Updated: ' + Time.now.to_s + '</div> | |
<select name="list" size="1" onChange="parent.rdoc.location.href=this.form.list.options[this.form.list.selectedIndex].value"> | |
<option selected value=""> Select gem </option>' | |
gemdocs.sort_by {|gem| gem.name.downcase }.each do |gem| | |
html.puts "<option value=\"#{gem.url}\">#{gem.name}</option>" | |
end | |
html.puts '</select> | |
</form></body></html>' | |
end | |
File.open(File.join(OutputPath, "index.html"), "w+") do |html| | |
html.puts '<html><head><title>Local Gem RDoc Index</title></head><frameset rows="50,*" border="none"> | |
<frame src="dropdown.html" name="nav"> | |
<frame src="http://guides.rails.info/" name="rdoc"></frameset></html>' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment