aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-02-11 04:21:53 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-02-11 04:21:53 -0800
commit759679289e6f22a5e4cfd9015e5102194fb92b29 (patch)
tree9b0b7e173d719d6abb574a675f5c2ac1365a1f98 /actionpack/lib/action_view
parentcdd293cb963b895ff580eb20d10f5d56ecb3d447 (diff)
parentdd9f8bc84740654057ddfc26428a4411f151c957 (diff)
downloadrails-759679289e6f22a5e4cfd9015e5102194fb92b29.tar.gz
rails-759679289e6f22a5e4cfd9015e5102194fb92b29.tar.bz2
rails-759679289e6f22a5e4cfd9015e5102194fb92b29.zip
Merge pull request #9221 from thenickcox/image_alt_attribute
Improve img alt attribute for screen readers
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb20
1 files changed, 17 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 5b3a2cae7c..6387b89a81 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -214,10 +214,24 @@ module ActionView
end
# Returns a string suitable for an html image tag alt attribute.
- # +src+ is meant to be an image file path.
- # It removes the basename of the file path and the digest, if any.
+ # The +src+ argument is meant to be an image file path.
+ # The method removes the basename of the file path and the digest,
+ # if any. It also removes hyphens and underscores from file names and
+ # replaces them with spaces, returning a space-separated, titleized
+ # string.
+ #
+ # ==== Examples
+ #
+ # image_tag('rails.png')
+ # # => <img alt="Rails" src="/assets/rails.png" />
+ #
+ # image_tag('hyphenated-file-name.png')
+ # # => <img alt="Hyphenated file name" src="/assets/hyphenated-file-name.png" />
+ #
+ # image_tag('underscored_file_name.png')
+ # # => <img alt="Underscored file name" src="/assets/underscored_file_name.png" />
def image_alt(src)
- File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').capitalize
+ File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
end
# Returns an html video tag for the +sources+. If +sources+ is a string,