Merge pull request #23288 from bdewater/sprockets3-sha2-alt

Fix img alt attribute generation when using Sprockets >= 3.0
This commit is contained in:
Rafael França 2016-01-27 14:09:09 -05:00 committed by Rafael Mendonça França
parent e8eda76893
commit 98a01c6f01
3 changed files with 7 additions and 1 deletions

View File

@ -1,3 +1,8 @@
* Fix stripping the digest from the automatically generated img tag alt
attribute when assets are handled by Sprockets >=3.0.
*Bart de Water*
* Generate `week_field` input values using a 1-based index and not a 0-based index
as per the W3 spec: http://www.w3.org/TR/html-markup/datatypes.html#form.data.week

View File

@ -229,7 +229,7 @@ module ActionView
# image_alt('underscored_file_name.png')
# # => Underscored file name
def image_alt(src)
File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
File.basename(src, '.*').sub(/-[[:xdigit:]]{32,64}\z/, '').tr('-_', ' ').capitalize
end
# Returns an html video tag for the +sources+. If +sources+ is a string,

View File

@ -448,6 +448,7 @@ class AssetTagHelperTest < ActionView::TestCase
[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 'Rails', image_alt("#{prefix}rails-f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b.png")
assert_equal 'Long file name with hyphens', image_alt("#{prefix}long-file-name-with-hyphens.png")
assert_equal 'Long file name with underscores', image_alt("#{prefix}long_file_name_with_underscores.png")
end