Skip to content

Instantly share code, notes, and snippets.

@mrinterweb
Created October 1, 2009 08:03
Show Gist options
  • Save mrinterweb/198819 to your computer and use it in GitHub Desktop.
Save mrinterweb/198819 to your computer and use it in GitHub Desktop.
sdoc all your installed gems
# with the help of the sdoc gem, this will generate the sdocs for all
# of your most recent gems.
# Caution! This will take a long time to run if you have a lot of gems installed.
# set an absolute path to the directory you would like your docs generated.
docs_path = "/Users/sean/tmp/docs/"
gems_output = `gem list --local`
gem_list = gems_output.gsub(/^([^ ]+).*\)/, '\1').split(/\n/)
latest_gem_dirs = gems_output.gsub(/^([^ ]+) \(([0-9\.]+).*\)/, '\1-\2').split(/\n/)
# Grepping against the following example string:
# Installed at (2.3.4): /Library/Ruby/Gems/1.8
dir = `gem list --local -d #{gem_list[0]}`.grep(/Installed at/)[0].gsub(/^.*: (.*)\n$/, '\1')
Dir.chdir(File.join(dir,'gems'))
latest_gem_dirs.each do |g|
doc_dir = "#{docs_path}#{g}"
# if you want to regenerate the documentation for a gem remove it's documentation directory
unless Dir.new(docs_path).include?(g)
puts `sdoc -o #{doc_dir} #{g}`
end
end
Dir.chdir(docs_path)
if Dir.new(Dir.pwd).include?('_all')
`rm -rf _all`
end
`sdoc-merge -o _all --title "Docs for all your gems: generated #{Time.now}" #{latest_gem_dirs.join(' ')}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment