Returns true and prepares http response, if rdoc for the requested gem name pattern
was found.
The search is based on the file system content, not on the gems metadata.
This allows additional documentation folders like ‘core’ for the Ruby core documentation - just put it
underneath the main doc folder.
# File lib/rubygems/server.rb, line 756
def show_rdoc_for_pattern(pattern, res)
found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select {|path|
File.exist? File.join(path, 'rdoc/index.html')
}
case found_gems.length
when 0
return false
when 1
new_path = File.basename(found_gems[0])
res.status = 302
res['Location'] = doc_root new_path
return true
else
doc_items = []
found_gems.each do |file_name|
base_name = File.basename(file_name)
doc_items << {
:name => base_name,
:url => doc_root(new_path),
:summary => ''
}
end
template = ERB.new(RDOC_SEARCH_TEMPLATE)
res['content-type'] = 'text/html'
result = template.result binding
res.body = result
return true
end
end