提交 6ba4c6d4 编写于 作者: D Daniel Gomez de Souza

Use option url: false to allow entries without a link tag

上级 b74c3565
......@@ -28,5 +28,8 @@
*Angelo Capilleri*
* Allow entries without a link tag in AtomFeedHelper.
*Daniel Gomez de Souza*
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/actionview/CHANGELOG.md) for previous changes.
......@@ -174,7 +174,7 @@ def updated(date_or_time = nil)
#
# * <tt>:published</tt>: Time first published. Defaults to the created_at attribute on the record if one such exists.
# * <tt>:updated</tt>: Time of update. Defaults to the updated_at attribute on the record if one such exists.
# * <tt>:url</tt>: The URL for this entry. Defaults to the polymorphic_url for the record.
# * <tt>:url</tt>: The URL for this entry or false or nil for not having a link tag. Defaults to the polymorphic_url for the record.
# * <tt>:id</tt>: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}"
# * <tt>:type</tt>: The TYPE for this entry. Defaults to "text/html".
def entry(record, options = {})
......@@ -191,7 +191,8 @@ def entry(record, options = {})
type = options.fetch(:type, 'text/html')
@xml.link(:rel => 'alternate', :type => type, :href => options[:url] || @view.polymorphic_url(record))
url = options.fetch(:url) { @view.polymorphic_url(record) }
@xml.link(:rel => 'alternate', :type => type, :href => url) if url
yield AtomBuilder.new(@xml)
end
......
......@@ -62,6 +62,23 @@ class ScrollsController < ActionController::Base
end
end
EOT
FEEDS["entry_url_false_option"] = <<-EOT
atom_feed do |feed|
feed.title("My great blog!")
feed.updated((@scrolls.first.created_at))
@scrolls.each do |scroll|
feed.entry(scroll, :url => false) do |entry|
entry.title(scroll.title)
entry.content(scroll.body, :type => 'html')
entry.author do |author|
author.name("DHH")
end
end
end
end
EOT
FEEDS["xml_block"] = <<-EOT
atom_feed do |feed|
feed.title("My great blog!")
......@@ -337,6 +354,13 @@ def test_feed_entry_type_option_specified
end
end
def test_feed_entry_url_false_option_adds_no_link
with_restful_routing(:scrolls) do
get :index, :id => 'entry_url_false_option'
assert_select "entry link", false
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.
先完成此消息的编辑!
想要评论请 注册