From 458574c1ff2f26380d0961c700eaf9db0dea3ff0 Mon Sep 17 00:00:00 2001 From: darobin Date: Tue, 2 Nov 2010 10:33:48 +0100 Subject: [PATCH] adding language option to Atom entry, which is needed for multilingual feeds --- .../lib/action_view/helpers/atom_feed_helper.rb | 4 +++- actionpack/test/template/atom_feed_helper_test.rb | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index db9d7a0..f032364 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -176,8 +176,10 @@ module ActionView # * :updated: Time of update. Defaults to the updated_at attribute on the record if one such exists. # * :url: The URL for this entry. Defaults to the polymorphic_url for the record. # * :id: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}" + # * :language: The language for this entry (for multilingual feeds). Defaults to none (the language of the feed takes precedence in Atom). def entry(record, options = {}) - @xml.entry do + entry_opts = options[:language] ? { "xml:lang" => options[:language] } : {} + @xml.entry entry_opts do @xml.id(options[:id] || "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}") if options[:published] || (record.respond_to?(:created_at) && record.created_at) diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 36102bb..8c28268 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -34,7 +34,7 @@ class ScrollsController < ActionController::Base feed.updated((@scrolls.first.created_at)) for scroll in @scrolls - feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry| + feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id), :language => "fr") do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -239,6 +239,14 @@ class AtomFeedTest < ActionController::TestCase end end + def test_entry_with_language_option + with_restful_routing(:scrolls) do + get :index, :id => "entry_options" + + assert_select "entry[xml:lang=fr]" + end + end + def test_self_url_should_default_to_current_request_url with_restful_routing(:scrolls) do get :index, :id => "defaults" -- 1.5.6.1