Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8637

Show
Ignore:
Timestamp:
01/13/08 00:11:39 (9 months ago)
Author:
nzkoz
Message:

Allow users to declare other namespaces when using the atom feed helpers. Closes #10304 [david.calavera]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8628 r8637  
    11*SVN* 
     2 
     3* Allow users to declare other namespaces when using the atom feed helpers. #10304 [david.calavera] 
    24 
    35* Introduce send_file :x_sendfile => true to send an X-Sendfile response header.  [Jeremy Kemper] 
  • trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb

    r8593 r8637  
    4343      #     end 
    4444      # 
    45       # The options are for atom_feed are: 
     45      # The options for atom_feed are: 
    4646      # 
    4747      # * <tt>:schema_date</tt>: Required. The date at which the tag scheme for the feed was first used. A good default is the year you created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. 
     
    4949      # * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host. 
    5050      # * <tt>:url</tt>: The URL for this feed. Defaults to the current URL. 
     51      # 
     52      # Other namespaces can be added to the root element: 
     53      # 
     54      #   app/views/posts/index.atom.builder: 
     55      #     atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app', 
     56      #         'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed| 
     57      #       feed.title("My great blog!") 
     58      #       feed.updated((@posts.first.created_at)) 
     59      #       feed.tag!(openSearch:totalResults, 10) 
     60      # 
     61      #       for post in @posts 
     62      #         feed.entry(post) do |entry| 
     63      #           entry.title(post.title) 
     64      #           entry.content(post.body, :type => 'html') 
     65      #           entry.tag!('app:edited', Time.now) 
     66      # 
     67      #           entry.author do |author| 
     68      #             author.name("DHH") 
     69      #           end 
     70      #         end 
     71      #       end 
     72      #     end 
     73      # 
    5174      # 
    5275      # atom_feed yields an AtomFeedBuilder instance. 
     
    6184        xml.instruct! 
    6285 
    63         xml.feed "xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' do 
     86        feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'} 
     87        feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)} 
     88 
     89        xml.feed(feed_opts) do 
    6490          xml.id("tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}")       
    6591          xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port)) 
  • trunk/actionpack/test/template/atom_feed_helper_test.rb

    r8564 r8637  
    5252              entry.title(scroll.title) 
    5353              entry.content(scroll.body, :type => 'html') 
     54            end 
     55          end 
     56        end 
     57    EOT 
     58    FEEDS["feed_with_atomPub_namespace"] = <<-EOT 
     59        atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app', 
     60                 'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed| 
     61          feed.title("My great blog!") 
     62          feed.updated((@scrolls.first.created_at)) 
     63 
     64          for scroll in @scrolls 
     65            feed.entry(scroll) do |entry| 
     66              entry.title(scroll.title) 
     67              entry.content(scroll.body, :type => 'html') 
     68              entry.tag!('app:edited', Time.now) 
     69 
     70              entry.author do |author| 
     71                author.name("DHH") 
     72              end 
    5473            end 
    5574          end 
     
    140159  end 
    141160 
     161  def test_feed_should_include_atomPub_namespace 
     162    with_restful_routing(:scrolls) do 
     163      get :index, :id => "feed_with_atomPub_namespace" 
     164      assert_match %r{xml:lang="en-US"}, @response.body 
     165      assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body 
     166      assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body 
     167    end 
     168  end 
     169 
    142170  private 
    143171    def with_restful_routing(resources)