aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-04-08 18:11:08 -0700
committerXavier Noria <fxn@hashref.com>2010-04-08 18:13:23 -0700
commitfd7202a75653570693c6fe423faad96019fe0ea1 (patch)
tree05874235b96fcc4fd46bd8394bbc63ee2c49dc9d /actionpack
parent99d54599215c2a8cea7e57f609e8e578043d71b2 (diff)
downloadrails-fd7202a75653570693c6fe423faad96019fe0ea1.tar.gz
rails-fd7202a75653570693c6fe423faad96019fe0ea1.tar.bz2
rails-fd7202a75653570693c6fe423faad96019fe0ea1.zip
adds #favicon_link_tag back, rdoc explains why it is useful, and how to get a link for Mobile Safari with it
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb34
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb12
2 files changed, 46 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index e4ec17467e..85401ad561 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -501,6 +501,40 @@ module ActionView
end
end
+ # Web browsers cache favicons. If you just throw a <tt>favicon.ico</tt> into the document
+ # root of your application and it changes later, clients that have it in their cache
+ # won't see the update. Using this helper prevents that because it appends an asset ID:
+ #
+ # <%= favicon_link_tag %>
+ #
+ # generates
+ #
+ # <link href="/favicon.ico?4649789979" rel="shortcut icon" type="image/vnd.microsoft.icon" />
+ #
+ # You may specify a different file in the first argument:
+ #
+ # <%= favicon_link_tag 'favicon.ico' %>
+ #
+ # That's passed to +image_path+ as is, so it gives
+ #
+ # <link href="/images/favicon.ico?4649789979" rel="shortcut icon" type="image/vnd.microsoft.icon" />
+ #
+ # The helper accepts an additional options hash where you can override "rel" and "type".
+ #
+ # For example, Mobile Safari looks for a different LINK tag, pointing to an image that
+ # will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
+ # The following call would generate such a tag:
+ #
+ # <%= favicon_link_tag 'mb-icon.png', :rel => 'apple-touch-icon', :type => 'image/png' %>
+ #
+ def favicon_link_tag(source='/favicon.ico', options={})
+ tag('link', {
+ :rel => 'shortcut icon',
+ :type => 'image/vnd.microsoft.icon',
+ :href => image_path(source)
+ }.merge(options.symbolize_keys))
+ end
+
# Computes the path to an image asset in the public images directory.
# Full paths from the document root will be passed through.
# Used internally by +image_tag+ to build the image path.
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 223a430f92..124bf734ac 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -157,6 +157,14 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
}
+ FaviconLinkToTag = {
+ %(favicon_link_tag) => %(<link href="/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />),
+ %(favicon_link_tag 'favicon.ico') => %(<link href="/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />),
+ %(favicon_link_tag 'favicon.ico', :rel => 'foo') => %(<link href="/images/favicon.ico" rel="foo" type="image/vnd.microsoft.icon" />),
+ %(favicon_link_tag 'favicon.ico', :rel => 'foo', :type => 'bar') => %(<link href="/images/favicon.ico" rel="foo" type="bar" />),
+ %(favicon_link_tag 'mb-icon.png', :rel => 'apple-touch-icon', :type => 'image/png') => %(<link href="/images/mb-icon.png" rel="apple-touch-icon" type="image/png" />)
+ }
+
VideoPathToTag = {
%(video_path("xml")) => %(/videos/xml),
%(video_path("xml.ogg")) => %(/videos/xml.ogg),
@@ -331,6 +339,10 @@ class AssetTagHelperTest < ActionView::TestCase
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
+ def test_favicon_link_tag
+ FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
+ end
+
def test_image_tag_windows_behaviour
old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1"
# This simulates the behaviour of File#exist? on windows when testing a file ending in "."