From 7e07e55f13c37b8424c8b0ffeaa0613f22cfa153 Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Thu, 30 Jun 2011 16:35:22 -0700 Subject: [PATCH 1/2] Pass through offset parameters to the :hover, :target, and :active magic sprite selectors. --- .../stylesheets/compass/utilities/sprites/_base.scss | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss index c346e181..d40740dc 100644 --- a/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss +++ b/frameworks/compass/stylesheets/compass/utilities/sprites/_base.scss @@ -30,18 +30,18 @@ $disable-magic-sprite-selectors:false !default; @include sprite-dimensions($map, $sprite); } @if not $disable-magic-sprite-selectors { - @include sprite-selectors($map, $sprite, $sprite); + @include sprite-selectors($map, $sprite, $sprite, $offset-x, $offset-y); } } // 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, $offset-x: 0, $offset-y: 0) { @each $selector in $sprite-selectors { @if sprite_has_selector($map, $sprite-name, $selector) { &:#{$selector}, &.#{$full-sprite-name}_#{$selector}, &.#{$full-sprite-name}-#{$selector} { - @include sprite-background-position($map, "#{$sprite-name}_#{$selector}"); + @include sprite-background-position($map, "#{$sprite-name}_#{$selector}", $offset-x, $offset-y); } } } From c9145a4aca4096d5c88698872b7002b10c684deb Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Thu, 30 Jun 2011 18:44:19 -0700 Subject: [PATCH 2/2] Add a test for the new sprite offset passing. --- test/integrations/sprites_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 6f6834bd..99a7d63e 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -518,6 +518,33 @@ class SpritesTest < Test::Unit::TestCase } CSS end + + it "should render corret sprite with css selectors via magic mixin with the correct offsets" do + css = render <<-SCSS + @import "selectors/*.png"; + a { + @include selectors-sprite(ten-by-ten, false, 5, -5) + } + SCSS + assert_correct css, <<-CSS + .selectors-sprite, a { + background: url('/selectors-sedfef809e2.png') no-repeat; + } + + a { + background-position: 5px -5px; + } + a:hover, a.ten-by-ten_hover, a.ten-by-ten-hover { + background-position: 5px -25px; + } + a:target, a.ten-by-ten_target, a.ten-by-ten-target { + background-position: 5px -35px; + } + a:active, a.ten-by-ten_active, a.ten-by-ten-active { + background-position: 5px -15px; + } + CSS + end it "should raise error on filenames that are not valid sass syntax" do assert_raise(Compass::Error) do