Skip to content

Instantly share code, notes, and snippets.

@nonlinear
Forked from jakebellacera/sass_retinize.rb
Created July 25, 2013 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonlinear/6082918 to your computer and use it in GitHub Desktop.
Save nonlinear/6082918 to your computer and use it in GitHub Desktop.
module Sass::Script::Functions
# Appends "_2x" to the end of a filename before the extension
# e.g. foobar.jpg => foobar_2x.jpg
def retinize(string)
assert_type string, :String
Sass::Script::String.new string.value.gsub(/\.(\w+)$/, '_2x.\\1')
end
declare :retinize, :args => [:string]
end
// DRY retina media queries
@mixin media-retina {
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
@content;
}
}
@mixin retina-bg-image($image, $size) {
background-image: src($image);
background-size: $size;
@include media-retina {
background-image: src(retinize($image));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment