Skip to content

Instantly share code, notes, and snippets.

@febeling
Created April 29, 2009 22:23
Show Gist options
  • Save febeling/104104 to your computer and use it in GitHub Desktop.
Save febeling/104104 to your computer and use it in GitHub Desktop.
Create ruby stdlib documentation
require 'rbconfig'
LIBDIR = Config::CONFIG['rubylibdir']
DOCDIR = File.expand_path(Config::CONFIG['ruby_install_name'] + "_rdoc")
BINDIR = Config::CONFIG['bindir']
RUBY = BINDIR + '/'+ Config::CONFIG['ruby_install_name']
TITLE = "Ruby #{RUBY_VERSION} Stdlib Documentation"
/ruby(.*)/.match(Config::CONFIG['ruby_install_name'])
SUFFIX = $1
def packages(libdir)
packages = {}
chdir(libdir) do
topnames = FileList['./*']
topnames.each do |name|
basename = File.basename(name, '.rb')
packages[basename] ||= []
packages[basename] << name
end
end
packages
end
desc "Generate Stdlib rdoc documentation (from installation locations of the ruby running rake itself)"
task :doc do
indexes = []
chdir(LIBDIR) do
packages(LIBDIR).each do |pkg, files|
sh "#{RUBY} #{BINDIR}/rdoc#{SUFFIX} --title '#{TITLE}: #{pkg}' -o #{DOCDIR}/#{pkg} #{files.join(' ')} --inline-source"
indexes << [if pkg == File.basename(Config::CONFIG['archdir'])
then "rbconfig"
else pkg
end,
"#{pkg}/index.html"]
end
write_index_file("#{DOCDIR}/index.html", indexes.sort { |pkg1, pkg2| pkg1[1].downcase <=> pkg2[1].downcase }, TITLE)
end
end
desc "Delete generated documentation (for the running ruby)"
task :clean do
rm_rf DOCDIR
end
def write_index_file(filename, indexes, title)
File.open(filename, "w") do |io|
io.puts <<EOS
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>#{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="#{indexes.first.first}/rdoc-style.css" type="text/css" />
<style>
.copynote { font-size: 90%; color: #777; text-align: center; }
</style>
</head>
<body>
<div id="classHeader">
<table class="header-table">
<tr class="top-aligned-row">
<td class="class-name-in-header">#{title}</td>
</tr>
<tr class="top-aligned-row">
<td>
Overview
<br />
</td>
</tr>
</table>
</div>
<p/>
<h3>List of packages</h3>
<ul>
EOS
indexes.each do |pkg,index|
io.puts %Q(<li><a href='#{index}'>#{pkg}</a></li>)
end
io.puts <<EOS
</ul>
<div>
<p class="copynote">Generated with <a href="http://github.com/febeling/stdlibdoc">stdlibdoc</a></p>
</div>
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>
</body>
</html>
EOS
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment