From 7571d4af9320b85ee9e75307a472570f7d24d2c5 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Mon, 28 Mar 2011 17:08:53 -0400 Subject: [PATCH] refactored sprite selectors --- Gemfile.lock | 2 +- .../compass/utilities/sprites/_base.scss | 8 ++--- spec/sprites_spec.rb | 34 ++++++++++++++++--- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ca441145..ba867187 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT PATH remote: . specs: - compass (0.11.beta.4.b0bfb63) + compass (0.11.beta.4.29656ea) chunky_png (~> 1.1.0) sass (>= 3.1.0.alpha.249) diff --git a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss index e033d85f..177a2c56 100644 --- a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss +++ b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss @@ -22,16 +22,17 @@ @if $dimensions { @include sprite-dimensions($map, $sprite); } + @include sprite-selectors($map, $sprite, $sprite); } // Include the selectors for the `$sprite` given the `$map` and the // `$full-sprite-name` // @private -@mixin sprite_selectors($map, $sprite-name, $full-sprite-name) { +@mixin sprite-selectors($map, $sprite-name, $full-sprite-name) { @each $selector in $sprite-selectors { @if sprite_has_selector($map, $sprite-name, $selector) { - .#{$full-sprite-name}:#{$selector}, .#{$full-sprite-name}_#{$selector}, .#{$full-sprite-name}-#{$selector} { - @include sprite($map, "#{$sprite-name}_#{$selector}"); + &:#{$selector}, &.#{$full-sprite-name}_#{$selector}, &.#{$full-sprite-name}-#{$selector} { + @include sprite-background-position($map, "#{$sprite-name}_#{$selector}"); } } } @@ -51,7 +52,6 @@ @if $base-class { @extend #{$base-class}; } @include sprite($map, $sprite-name, $dimensions); } - @include sprite_selectors($map, $sprite-name, $full-sprite-name); } } } \ No newline at end of file diff --git a/spec/sprites_spec.rb b/spec/sprites_spec.rb index d5aff351..0c30f68b 100644 --- a/spec/sprites_spec.rb +++ b/spec/sprites_spec.rb @@ -480,16 +480,40 @@ describe Compass::Sprites do .selectors-ten-by-ten { background-position: 0 0; } - - .selectors-ten-by-ten:hover, .selectors-ten-by-ten_hover, .selectors-ten-by-ten-hover { + .selectors-ten-by-ten:hover, .selectors-ten-by-ten.ten-by-ten_hover, .selectors-ten-by-ten.ten-by-ten-hover { background-position: 0 -20px; } - - .selectors-ten-by-ten:target, .selectors-ten-by-ten_target, .selectors-ten-by-ten-target { + .selectors-ten-by-ten:target, .selectors-ten-by-ten.ten-by-ten_target, .selectors-ten-by-ten.ten-by-ten-target { background-position: 0 -30px; } + .selectors-ten-by-ten:active, .selectors-ten-by-ten.ten-by-ten_active, .selectors-ten-by-ten.ten-by-ten-active { + background-position: 0 -10px; + } + CSS + end + + it "should render corret sprite with css selectors via magic mixin" do + css = render <<-SCSS + @import "selectors/*.png"; + a { + @include selectors_sprite(ten-by-ten) + } + SCSS + css.should == <<-CSS + .selectors-sprite, a { + background: url('/selectors-edfef809e2.png') no-repeat; + } - .selectors-ten-by-ten:active, .selectors-ten-by-ten_active, .selectors-ten-by-ten-active { + a { + background-position: 0 0; + } + a:hover, a.ten-by-ten_hover, a.ten-by-ten-hover { + background-position: 0 -20px; + } + a:target, a.ten-by-ten_target, a.ten-by-ten-target { + background-position: 0 -30px; + } + a:active, a.ten-by-ten_active, a.ten-by-ten-active { background-position: 0 -10px; } CSS