From 5d373d61b51ff1529e3c588feb1952d822887f8b Mon Sep 17 00:00:00 2001 From: Eaden McKee Date: Fri, 12 Mar 2010 14:13:10 +1300 Subject: [PATCH] simplify alt tag generation for images --- .../lib/action_view/helpers/asset_tag_helper.rb | 4 ++-- actionpack/test/template/asset_tag_helper_test.rb | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index de3d61e..0c488b6 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -11,7 +11,7 @@ module ActionView # the assets exist before linking to them: # # image_tag("rails.png") - # # => Rails src= + # # => Rails # stylesheet_link_tag("application") # # => # @@ -523,7 +523,7 @@ module ActionView options.symbolize_keys! src = options[:src] = path_to_image(source) - options[:alt] ||= File.basename(src, '.*').split('.').first.to_s.capitalize + options[:alt] ||= File.basename(src, '.*').capitalize if size = options.delete(:size) options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$} diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 50c3ab0..fe25524 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -141,13 +141,16 @@ class AssetTagHelperTest < ActionView::TestCase ImageLinkToTag = { %(image_tag("xml.png")) => %(Xml), - %(image_tag("..jpg")) => %(), + %(image_tag("..jpg")) => %(.), %(image_tag("rss.gif", :alt => "rss syndication")) => %(rss syndication), %(image_tag("gold.png", :size => "45x70")) => %(Gold), %(image_tag("gold.png", "size" => "45x70")) => %(Gold), %(image_tag("error.png", "size" => "45")) => %(Error), %(image_tag("error.png", "size" => "45 x 70")) => %(Error), %(image_tag("error.png", "size" => "x")) => %(Error), + %(image_tag("google.com.png")) => %(Google.com), + %(image_tag("slash..png")) => %(Slash.), + %(image_tag(".pdf.png")) => %(.pdf), %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(Rails), %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(Mouse), %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(Mouse) -- 1.7.0.1