提交 7e1c04d8 编写于 作者: M Michael Koziarski

Allow users to declare other namespaces when using the atom feed helpers....

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


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 772ad952
*SVN*
* Allow users to declare other namespaces when using the atom feed helpers. #10304 [david.calavera]
* Introduce send_file :x_sendfile => true to send an X-Sendfile response header. [Jeremy Kemper]
* Fixed ActionView::Helpers::ActiveRecordHelper::form for when protect_from_forgery is used #10739 [jeremyevans]
......
......@@ -42,13 +42,36 @@ module AtomFeedHelper
# end
# end
#
# The options are for atom_feed are:
# The options for atom_feed are:
#
# * <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.
# * <tt>:language</tt>: Defaults to "en-US".
# * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host.
# * <tt>:url</tt>: The URL for this feed. Defaults to the current URL.
#
# Other namespaces can be added to the root element:
#
# app/views/posts/index.atom.builder:
# atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
# 'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
# feed.title("My great blog!")
# feed.updated((@posts.first.created_at))
# feed.tag!(openSearch:totalResults, 10)
#
# for post in @posts
# feed.entry(post) do |entry|
# entry.title(post.title)
# entry.content(post.body, :type => 'html')
# entry.tag!('app:edited', Time.now)
#
# entry.author do |author|
# author.name("DHH")
# end
# end
# end
# end
#
#
# atom_feed yields an AtomFeedBuilder instance.
def atom_feed(options = {}, &block)
if options[:schema_date].blank?
......@@ -60,7 +83,10 @@ def atom_feed(options = {}, &block)
xml = options[:xml] || eval("xml", block.binding)
xml.instruct!
xml.feed "xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' do
feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'}
feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)}
xml.feed(feed_opts) do
xml.id("tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}")
xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port))
xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url)
......
......@@ -55,6 +55,25 @@ class ScrollsController < ActionController::Base
end
end
EOT
FEEDS["feed_with_atomPub_namespace"] = <<-EOT
atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
for scroll in @scrolls
feed.entry(scroll) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
entry.tag!('app:edited', Time.now)
entry.author do |author|
author.name("DHH")
end
end
end
end
EOT
def index
@scrolls = [
Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
......@@ -139,6 +158,15 @@ def test_feed_should_allow_nested_xml_blocks
end
end
def test_feed_should_include_atomPub_namespace
with_restful_routing(:scrolls) do
get :index, :id => "feed_with_atomPub_namespace"
assert_match %r{xml:lang="en-US"}, @response.body
assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body
assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body
end
end
private
def with_restful_routing(resources)
with_routing do |set|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册