Last active
August 29, 2015 14:01
-
-
Save torounit/207c5bccf284540a4813 to your computer and use it in GitHub Desktop.
Middlemanのimage_tagの拡張。srcsetでRetina用の画像を追加。
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
helpers do | |
def image_tag(path,params = {}) | |
if !params.key?(:srcset) | |
basename = File.basename(path, '.*') | |
ext = File.extname(path) | |
real_path = path.sub(basename + ext,basename + "@2x" + ext ) | |
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/') | |
full_path = File.join(source_dir, real_path) | |
if File.exist?(full_path) | |
params[:srcset] = image_path(real_path) + " 2x" | |
end | |
end | |
super(path,params) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any chance you could explain how to use this a bit more? Looks like an interesting way to use
srcset