mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add :json type to auto_discovery_link_tag
This allows auto_discovery_link_tag to support the JSON Feed standard. See https://jsonfeed.org/version/1 for more information.
This commit is contained in:
parent
055535fd1b
commit
062e5f2b06
5 changed files with 14 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
* Add `:json` type to `auto_discovery_link_tag` to support [JSON Feeds](https://jsonfeed.org/version/1)
|
||||
|
||||
*Mike Gunderloy*
|
||||
|
||||
* Update `distance_of_time_in_words` helper to display better error messages
|
||||
for bad input.
|
||||
|
||||
|
|
|
@ -122,9 +122,9 @@ module ActionView
|
|||
end
|
||||
|
||||
# Returns a link tag that browsers and feed readers can use to auto-detect
|
||||
# an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
|
||||
# <tt>:atom</tt>. Control the link options in url_for format using the
|
||||
# +url_options+. You can modify the LINK tag itself in +tag_options+.
|
||||
# an RSS, Atom, or JSON feed. The +type+ can be <tt>:rss</tt> (default),
|
||||
# <tt>:atom</tt>, or <tt>:json</tt>. Control the link options in url_for format
|
||||
# using the +url_options+. You can modify the LINK tag itself in +tag_options+.
|
||||
#
|
||||
# ==== Options
|
||||
#
|
||||
|
@ -138,6 +138,8 @@ module ActionView
|
|||
# # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
|
||||
# auto_discovery_link_tag(:atom)
|
||||
# # => <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
|
||||
# auto_discovery_link_tag(:json)
|
||||
# # => <link rel="alternate" type="application/json" title="JSON" href="http://www.currenthost.com/controller/action" />
|
||||
# auto_discovery_link_tag(:rss, {action: "feed"})
|
||||
# # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
|
||||
# auto_discovery_link_tag(:rss, {action: "feed"}, {title: "My RSS"})
|
||||
|
@ -147,8 +149,8 @@ module ActionView
|
|||
# auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "Example RSS"})
|
||||
# # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed.rss" />
|
||||
def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
|
||||
if !(type == :rss || type == :atom) && tag_options[:type].blank?
|
||||
raise ArgumentError.new("You should pass :type tag_option key explicitly, because you have passed #{type} type other than :rss or :atom.")
|
||||
if !(type == :rss || type == :atom || type == :json) && tag_options[:type].blank?
|
||||
raise ArgumentError.new("You should pass :type tag_option key explicitly, because you have passed #{type} type other than :rss, :atom, or :json.")
|
||||
end
|
||||
|
||||
tag(
|
||||
|
|
|
@ -53,6 +53,7 @@ class AssetTagHelperTest < ActionView::TestCase
|
|||
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
||||
%(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
||||
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
|
||||
%(auto_discovery_link_tag(:json)) => %(<link href="http://www.example.com" rel="alternate" title="JSON" type="application/json" />),
|
||||
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
||||
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
|
||||
%(auto_discovery_link_tag(:rss, "//localhost/feed")) => %(<link href="//localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
|
||||
|
|
|
@ -419,7 +419,7 @@ image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png
|
|||
|
||||
#### auto_discovery_link_tag
|
||||
|
||||
Returns a link tag that browsers and feed readers can use to auto-detect an RSS or Atom feed.
|
||||
Returns a link tag that browsers and feed readers can use to auto-detect an RSS, Atom, or JSON feed.
|
||||
|
||||
```ruby
|
||||
auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", { title: "RSS Feed" }) # =>
|
||||
|
|
|
@ -768,7 +768,7 @@ WARNING: The asset tag helpers do _not_ verify the existence of the assets at th
|
|||
|
||||
#### Linking to Feeds with the `auto_discovery_link_tag`
|
||||
|
||||
The `auto_discovery_link_tag` helper builds HTML that most browsers and feed readers can use to detect the presence of RSS or Atom feeds. It takes the type of the link (`:rss` or `:atom`), a hash of options that are passed through to url_for, and a hash of options for the tag:
|
||||
The `auto_discovery_link_tag` helper builds HTML that most browsers and feed readers can use to detect the presence of RSS, Atom, or JSON feeds. It takes the type of the link (`:rss`, `:atom`, or `:json`), a hash of options that are passed through to url_for, and a hash of options for the tag:
|
||||
|
||||
```erb
|
||||
<%= auto_discovery_link_tag(:rss, {action: "feed"},
|
||||
|
|
Loading…
Reference in a new issue