Changeset 8529
- Timestamp:
- 01/02/08 19:45:53 (4 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb (modified) (6 diffs)
- trunk/actionpack/test/template/atom_feed_helper_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8527 r8529 1 1 *SVN* 2 3 * Fix atom_feed_helper to comply with the atom spec. Closes #10672 [xaviershay] 4 5 * The tags created do not contain a date (http://feedvalidator.org/docs/error/InvalidTAG.html) 6 * IDs are not guaranteed unique 7 * A default self link was not provided, contrary to the documentation 8 * NOTE: This changes tags for existing atom entries, but at least they validate now. 2 9 3 10 * Correct indentation in tests. Closes #10671 [l.guidi] trunk/actionpack/lib/action_view/helpers/atom_feed_helper.rb
r7529 r8529 27 27 # 28 28 # app/views/posts/index.atom.builder: 29 # atom_feed do |feed|29 # atom_feed(:tag_uri => "2008") do |feed| 30 30 # feed.title("My great blog!") 31 31 # feed.updated((@posts.first.created_at)) … … 45 45 # The options are for atom_feed are: 46 46 # 47 # * <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. 47 48 # * <tt>:language</tt>: Defaults to "en-US". 48 49 # * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host. … … 51 52 # atom_feed yields a AtomFeedBuilder instance. 52 53 def atom_feed(options = {}, &block) 54 if options[:schema_date].blank? 55 logger.warn("You must provide the :schema_date option to atom_feed for your feed to be valid. A good default is the year you first created this feed.") unless logger.nil? 56 else 57 options[:schema_date] = options[:schema_date].strftime("%Y-%m-%d") if options[:schema_date].respond_to?(:strftime) 58 end 59 53 60 xml = options[:xml] || eval("xml", block.binding) 54 61 xml.instruct! 55 62 56 63 xml.feed "xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' do 57 xml.id("tag:#{request.host} :#{request.request_uri.split(".")[0].gsub("/", "")}")64 xml.id("tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}") 58 65 xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port)) 59 60 if options[:url] 61 xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url) 62 end 63 64 yield AtomFeedBuilder.new(xml, self) 66 xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url) 67 68 yield AtomFeedBuilder.new(xml, self, options) 65 69 end 66 70 end … … 68 72 69 73 class AtomFeedBuilder 70 def initialize(xml, view )71 @xml, @view = xml, view74 def initialize(xml, view, feed_options = {}) 75 @xml, @view, @feed_options = xml, view, feed_options 72 76 end 73 77 … … 86 90 def entry(record, options = {}) 87 91 @xml.entry do 88 @xml.id("tag:#{@view.request.host _with_port}:#{record.class}#{record.id}")92 @xml.id("tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}") 89 93 90 94 if options[:published] || (record.respond_to?(:created_at) && record.created_at) … … 103 107 104 108 private 105 def method_missing(method, *arguments )106 @xml.__send__(method, *arguments )109 def method_missing(method, *arguments, &block) 110 @xml.__send__(method, *arguments, &block) 107 111 end 108 112 end trunk/actionpack/test/template/atom_feed_helper_test.rb
r7533 r8529 6 6 FEEDS = {} 7 7 FEEDS["defaults"] = <<-EOT 8 atom_feed do |feed|8 atom_feed(:schema_date => '2008') do |feed| 9 9 feed.title("My great blog!") 10 10 feed.updated((@scrolls.first.created_at)) … … 39 39 end 40 40 EOT 41 FEEDS["xml_block"] = <<-EOT 42 atom_feed do |feed| 43 feed.title("My great blog!") 44 feed.updated((@scrolls.first.created_at)) 41 45 46 feed.author do |author| 47 author.name("DHH") 48 end 49 50 for scroll in @scrolls 51 feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry| 52 entry.title(scroll.title) 53 entry.content(scroll.body, :type => 'html') 54 end 55 end 56 end 57 EOT 42 58 def index 43 59 @scrolls = [ … … 47 63 48 64 render :inline => FEEDS[params[:id]], :type => :builder 65 end 66 67 protected 68 69 def rescue_action(e) 70 raise(e) 49 71 end 50 72 end … … 89 111 end 90 112 113 def test_self_url_should_default_to_current_request_url 114 with_restful_routing(:scrolls) do 115 get :index, :id => "defaults" 116 assert_select "link[rel=self][href=http://www.nextangle.com/scrolls?id=defaults]" 117 end 118 end 119 120 def test_feed_id_should_be_a_valid_tag 121 with_restful_routing(:scrolls) do 122 get :index, :id => "defaults" 123 assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults" 124 end 125 end 126 127 def test_entry_id_should_be_a_valid_tag 128 with_restful_routing(:scrolls) do 129 get :index, :id => "defaults" 130 assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1" 131 assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2" 132 end 133 end 134 135 def test_feed_should_allow_nested_xml_blocks 136 with_restful_routing(:scrolls) do 137 get :index, :id => "xml_block" 138 assert_select "author name", :text => "DHH" 139 end 140 end 91 141 92 142 private