Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions cli/lib/compass/sass_extensions/functions/sprites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO, use_per
declare :sprite_position, [:map, :sprite, :offset_x, :offset_y]
declare :sprite_position, [:map, :sprite, :offset_x, :offset_y, :use_percentages]

def convert_sprite_name(sprite)
case sprite
when Sass::Script::Value::Color
rgb = if reversed_color_names.keys.first.size == 3
sprite.rgb
else
# Sass 3.3 includes the alpha channel
sprite.rgba
end
identifier(reversed_color_names[rgb])
when Sass::Script::Value::Bool
identifier(sprite.to_s)
else
sprite
end
end
declare :convert_sprite_name, [:sprite]

protected

def get_sprite_file(map, sprite=nil)
Expand All @@ -265,23 +283,6 @@ def reversed_color_names
end
end

def convert_sprite_name(sprite)
case sprite
when Sass::Script::Value::Color
rgb = if reversed_color_names.keys.first.size == 3
sprite.rgb
else
# Sass 3.3 includes the alpha channel
sprite.rgba
end
identifier(reversed_color_names[rgb])
when Sass::Script::Value::Bool
identifier(sprite.to_s)
else
sprite
end
end

def verify_map(map, error = "sprite")
unless map.is_a?(Compass::SassExtensions::Sprites::SpriteMap)
missing_sprite!(error)
Expand Down
26 changes: 24 additions & 2 deletions cli/test/integrations/sprites_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def image_md5(file)
md5.hexdigest
end

def render(scss)
def render(scss, opts = {})
options = Compass.sass_engine_options
options[:line_comments] = false
options[:style] = :expanded
options[:syntax] = :scss
options[:compass] ||= {}
options[:compass][:logger] ||= Compass::NullLogger.new
css = Sass::Engine.new(scss, options).render
css = Sass::Engine.new(scss, options.merge(opts)).render
# reformat to fit result of heredoc:
" #{css.gsub('@charset "UTF-8";', '').gsub(/\n/, "\n ").strip}\n"
end
Expand Down Expand Up @@ -1003,6 +1003,28 @@ def clean(string)
assert_correct clean(other_css), clean(css)
end

it "should be able to compress the sprite stylesheet correctly" do
css = render <<-SCSS, :style => :compressed
@import "colors/*.png";
@include all-colors-sprites;
SCSS
other_css = <<-CSS
.colors-sprite, .colors-blue, .colors-yellow {
background-image: url('/images-tmp/colors-s58671cb5bb.png');
background-repeat: no-repeat
}

.colors-blue {
background-position: 0 0
}

.colors-yellow {
background-position: 0 -10px
}
CSS
assert_correct clean(other_css), clean(css)
end

it "should have a sprite_name function that returns the names of the sprites in a sass list" do
css = render <<-SCSS
@import "colors/*.png";
Expand Down
1 change: 1 addition & 0 deletions core/stylesheets/compass/utilities/sprites/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ $default-sprite-separator: "-" !default;
$use-percentages: false,
$separator: $default-sprite-separator) {
@each $sprite-name in $sprite-names {
$sprite-name: convert_sprite_name($sprite-name);
@if sprite_does_not_have_parent($map, $sprite-name) {
$full-sprite-name: "#{$prefix}#{$separator}#{$sprite-name}";
@if sprite_has_valid_selector($full-sprite-name) {
Expand Down