method
build_rss
v1_9_3_392 -
Show latest stable
- Class:
Gem::Indexer
build_rss()public
Builds an RSS feed for past two days gem releases according to the gem’s date.
# File lib/rubygems/indexer.rb, line 245
def build_rss
if @rss_host.nil? or @rss_gems_host.nil? then
if Gem.configuration.really_verbose then
alert_warning "no --rss-host or --rss-gems-host, RSS generation disabled"
end
return
end
require 'cgi'
require 'rubygems/text'
extend Gem::Text
Gem.time 'Generated rss' do
open @rss_index, 'wb' do |io|
rss_host = CGI.escapeHTML @rss_host
rss_title = CGI.escapeHTML(@rss_title || 'gems')
io.puts <?xml version="1.0"?><rss version="2.0"> <channel> <title>#{rss_title}</title> <link>http://#{rss_host}</link> <description>Recently released gems from http://#{rss_host}</description> <generator>RubyGems v#{Gem::VERSION}</generator> <docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
today = Gem::Specification::TODAY
yesterday = today - 86400
index = Gem::Specification.select do |spec|
spec_date = spec.date
# TODO: remove this and make YAML based specs properly normalized
spec_date = Time.parse(spec_date.to_s) if Date === spec_date
spec_date >= yesterday && spec_date <= today
end
index.sort_by { |spec| [-spec.date.to_i, spec] }.each do |spec|
file_name = File.basename spec.cache_file
gem_path = CGI.escapeHTML "http://#{@rss_gems_host}/gems/#{file_name}"
size = File.stat(spec.loaded_from).size # rescue next
description = spec.description || spec.summary || ''
authors = Array spec.authors
emails = Array spec.email
authors = emails.zip(authors).map do |email, author|
email += " (#{author})" if author and not author.empty?
end.join ', '
description = description.split(/\n\n+/).map do |chunk|
format_text chunk, 78
end
description = description.join "\n\n"
item = ''
item << <item> <title>#{CGI.escapeHTML spec.full_name}</title> <description><pre>#{CGI.escapeHTML description.chomp}</pre> </description> <author>#{CGI.escapeHTML authors}</author> <guid>#{CGI.escapeHTML spec.full_name}</guid> <enclosure url=\"#{gem_path}\" length=\"#{size}\" type=\"application/octet-stream\" /> <pubDate>#{spec.date.rfc2822}</pubDate>
item << <link>#{CGI.escapeHTML spec.homepage}</link> if spec.homepage
item << </item>
io.puts item
end
io.puts </channel></rss>
end
end
@files << @rss_index
end Related methods
- Instance methods
- abbreviate
- build_indicies
- build_legacy_indicies
- build_marshal_gemspecs
- build_modern_index
- build_modern_indicies
- build_rss
- collect_specs
- compact_specs
- compress
- compress_indicies
- gem_file_list
- generate_index
- gzip
- install_indicies
- make_temp_directories
- map_gems_to_specs
- paranoid
- sanitize
- sanitize_string
- update_index
- update_specs_index
- Class methods
- new