public
Description: add atomPub server capabilities to you rails application
Homepage: http://github.com/calavera/atom_pub_server
Clone URL: git://github.com/calavera/atompub-server.git
atompub-server / lib / atom_feed_helper.rb
100644 31 lines (23 sloc) 0.985 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
module ActionView
  module Helpers #:nodoc
    module AtomFeedHelper #:nodoc
      
      alias_method :__atom_feed, :atom_feed
      
      def atom_feed(options = {}, &block)
        xml = options[:xml] || eval("xml", block.binding)
        xml.instruct!
 
        feed_opts = { "xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' }
 
        options.each do |key, value|
          feed_opts[key] = value if key.match(/^xmlns/)
        end
 
        xml.feed feed_opts do
          xml.id("tag:#{request.host}:#{request.request_uri.split(".")[0].gsub("/", "")}")
          xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port))
 
          if options[:url]
            xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url)
          end
 
          yield AtomFeedBuilder.new(xml, self)
        end
      end
      
    end
  end
end