Skip to content

Instantly share code, notes, and snippets.

@torounit
Last active August 29, 2015 14:01
Show Gist options
  • Save torounit/207c5bccf284540a4813 to your computer and use it in GitHub Desktop.
Save torounit/207c5bccf284540a4813 to your computer and use it in GitHub Desktop.
Middlemanのimage_tagの拡張。srcsetでRetina用の画像を追加。
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
@dallasbpeters
Copy link

any chance you could explain how to use this a bit more? Looks like an interesting way to use srcset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment