Permalink
Browse files

the generated ALT attribute for images no longer contains the digest,…

… if any
  • Loading branch information...
1 parent f63f0ba commit a0960ec2d4476763d6975e3df6806cf99f24ead9 @fxn fxn committed Jun 27, 2011
@@ -347,7 +347,7 @@ def image_tag(source, options = {})
src = options[:src] = path_to_image(source)
unless src =~ /^cid:/
- options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
+ options[:alt] = options.fetch(:alt){ image_alt(src) }
end
if size = options.delete(:size)
@@ -362,6 +362,10 @@ def image_tag(source, options = {})
tag("img", options)
end
+ def image_alt(src)
+ File.basename(src, '.*').gsub(/-[[:xdigit:]]{32}\z/, '').capitalize
+ end
+
# Returns an html video tag for the +sources+. If +sources+ is a string,
# a single video tag will be returned. If +sources+ is an array, a video
# tag with nested source tags for each source will be returned. The
@@ -424,6 +424,14 @@ def test_path_to_image_alias_for_image_path
PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
+ def test_image_alt
+ [nil, '/', '/foo/bar/', 'foo/bar/'].each do |prefix|
+ assert_equal 'Rails', image_alt("#{prefix}rails.png")
+ assert_equal 'Rails', image_alt("#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png")
+ assert_equal 'Avatar-0000', image_alt("#{prefix}avatar-0000.png")
+ end
+ end
+
def test_image_tag
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end

0 comments on commit a0960ec

Please sign in to comment.