public
Description: Generate an HTML index of your ruby gem rdocs, like a static 'gem --server'
Homepage: http://www.sanityinc.com/articles/generating-an-index-of-your-rubygem-rdocs
Clone URL: git://github.com/purcell/gemdocindex.git
Click here to lend your support to: gemdocindex and make a donation at www.pledgie.com !
gemdocindex / gemdocindex
100755 81 lines (71 sloc) 2.496 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
# Create an HTML index of links to generated RDocs for all locally installed gems
#
# Usage: gemdocindex > gemindex.html
#
# Copyright (c) 2008 Steve Purcell, http://www.sanityinc.com/
#
# Licensed under the same terms as Ruby itself.
#
 
 
require 'rubygems'
require 'rubygems/doc_manager'
require 'rubygems/version'
 
gem_name_to_gem_list_map = {}
Gem::SourceIndex.from_installed_gems.each do |full_gem_name, gem|
  if Gem::DocManager.new(gem).rdoc_installed?
    (gem_name_to_gem_list_map[gem.name] ||= []) << gem
  end
end
 
# Add a gem spec for rubygems itself
rubygems_gem = Gem::Specification.new do |spec|
  spec.name = 'rubygems'
  spec.version = Gem::RubyGemsVersion
  spec.summary = "The rubygems system"
end
def rubygems_gem.installation_path() Gem::default_path end
gem_name_to_gem_list_map['rubygems'] = [rubygems_gem]
 
 
puts <<-end_html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gem RDoc index</title>
<style>
body { background: #fff; margin: 0px }
a { text-decoration: none }
a:hover { text-decoration: underline }
h1, #footer { margin: 0; padding: 0.2em 20px; background: #ddd; color: #000 }
h1 { border-bottom: solid 5px #ccc }
table { margin: 20px; clear: both; border-collapse: collapse }
tr { border-top: solid 1px #ccc }
td.name { width: 15em; }
td .version { padding-right: 0.5em; font-size: smaller; }
#footer { font-size: smaller }
</style>
</head>
<body>
<h1>Gem RDoc index</h1>
<table>
end_html
 
Gem::Specification.module_eval do
  define_method(:rdoc_index_path) do
    File.join(installation_path, "doc", "#{name}-#{version}", "rdoc", "index.html")
  end
end
 
gem_name_to_gem_list_map.keys.sort_by { |n| n.downcase }.each do |gem_name|
  gems_from_newest_to_oldest = gem_name_to_gem_list_map[gem_name].sort_by { |g| g.version }.reverse
  latest = gems_from_newest_to_oldest.first
  puts "<tr><td class=\"name\"><a href=\"file://#{latest.rdoc_index_path}\">#{gem_name}</a></td>"
  puts "<td>"
  for gem in gems_from_newest_to_oldest
    puts "<span class=\"version\"><a href=\"file://#{gem.rdoc_index_path}\">#{gem.version}</a></span>"
  end
  puts "</td></tr>"
end
 
puts <<-end_html
</table>
<div id="footer">
Generated by <a href="http://www.sanityinc.com/">gemdocindex</a>
</div>
</body>
</html>
end_html