build_rss (Gem::Indexer)

    # File lib/rubygems/indexer.rb, line 298
      def build_rss(index)
        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\"?>\n<rss version=\"2.0\">\n<channel>\n<title>\#{rss_title}</title>\n<link>http://\#{rss_host}</link>\n<description>Recently released gems from http://\#{rss_host}</description>\n<generator>RubyGems v\#{Gem::RubyGemsVersion}</generator>\n<docs>http://cyber.law.harvard.edu/rss/rss.html</docs>\n"

            today = Gem::Specification::TODAY
            yesterday = today - 86400

            index = index.select do |_, spec|
              spec_date = spec.date

              case spec_date
              when Date
                Time.parse(spec_date.to_s) >= yesterday
              when Time
                spec_date >= yesterday
              end
            end

            index = index.select do |_, spec|
              spec_date = spec.date

              case spec_date
              when Date
                Time.parse(spec_date.to_s) <= today
              when Time
                spec_date <= today
              end
            end

            index.sort_by { |_, spec| [-spec.date.to_i, spec] }.each do |_, spec|
              gem_path = CGI.escapeHTML "http://#{@rss_gems_host}/gems/#{spec.full_name}.gem"
              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>\n<title>\#{CGI.escapeHTML spec.full_name}</title>\n<description>\n&lt;pre&gt;\#{CGI.escapeHTML description.chomp}&lt;/pre&gt;\n</description>\n<author>\#{CGI.escapeHTML authors}</author>\n<guid>\#{CGI.escapeHTML spec.full_name}</guid>\n<enclosure url=\\\"\#{gem_path}\\\"\nlength=\\\"\#{size}\\\" type=\\\"application/octet-stream\\\" />\n<pubDate>\#{spec.date.rfc2822}</pubDate>\n"

              item << "<link>\#{CGI.escapeHTML spec.homepage}</link>\n" if spec.homepage

              item << "</item>\n"

              io.puts item
            end

            io.puts "</channel>\n</rss>\n"
          end
        end

        @files << @rss_index
      end