This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ImagesHelper | |
# Outputs html img tag with srcset attribute for 2x image based on original | |
# src. Use naming convention ex. having 'image.jpg', 2x image should be named | |
# '[email protected]'. If there's no image.jpg or [email protected] exception will be | |
# thrown by Rails asset pipeline. | |
def retina_image(src, options = {}) | |
src2x = src.gsub(/(^.+)(\.(jpg|png)$)/, '\1@2x\2') | |
image_tag src, options.merge(srcset: "#{image_url(src2x)} 2x") | |
end | |
end |