Skip to content

Instantly share code, notes, and snippets.

@mmwtsn
Created December 12, 2014 20:06
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 mmwtsn/2bbd01230d365ee44f43 to your computer and use it in GitHub Desktop.
Save mmwtsn/2bbd01230d365ee44f43 to your computer and use it in GitHub Desktop.
A comparison of `else` placements in a SCSS mixin.
// Bourbon _retina-images.scss via:
// https://raw.githubusercontent.com/thoughtbot/bourbon/502c2108dea1970ffeb4f91cb95b545d67bddfd0/app/assets/stylesheets/addons/_retina-image.scss
// Current version with @else on a new line
@mixin retina-image($filename, $background-size, $extension: png, $retina-filename: null, $retina-suffix: _2x, $asset-pipeline: $asset-pipeline) {
@if $asset-pipeline {
background-image: image-url("#{$filename}.#{$extension}");
}
@else {
background-image: url("#{$filename}.#{$extension}");
}
@include hidpi {
@if $asset-pipeline {
@if $retina-filename {
background-image: image-url("#{$retina-filename}.#{$extension}");
}
@else {
background-image: image-url("#{$filename}#{$retina-suffix}.#{$extension}");
}
}
@else {
@if $retina-filename {
background-image: url("#{$retina-filename}.#{$extension}");
}
@else {
background-image: url("#{$filename}#{$retina-suffix}.#{$extension}");
}
}
background-size: $background-size;
}
}
// Updated version with SCSS Lint `ElsePlacement`, `same_line` setting respected
@mixin retina-image($filename, $background-size, $extension: png, $retina-filename: null, $retina-suffix: _2x, $asset-pipeline: $asset-pipeline) {
@if $asset-pipeline {
background-image: image-url("#{$filename}.#{$extension}");
} @else {
background-image: url("#{$filename}.#{$extension}");
}
@include hidpi {
@if $asset-pipeline {
@if $retina-filename {
background-image: image-url("#{$retina-filename}.#{$extension}");
} @else {
background-image: image-url("#{$filename}#{$retina-suffix}.#{$extension}");
}
} @else {
@if $retina-filename {
background-image: url("#{$retina-filename}.#{$extension}");
} @else {
background-image: url("#{$filename}#{$retina-suffix}.#{$extension}");
}
}
background-size: $background-size;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment