From 753ad37df743d7d39d1cec65df25aefec1ba5f87 Mon Sep 17 00:00:00 2001 From: Scott Davis <jetviper21@gmail.com> Date: Tue, 10 May 2011 22:44:10 -0400 Subject: [PATCH] Fixed problem with globs only going one directoy deep from now on imports like foo/*.png will get mapped to foo/**/*.png Please enter the commit message for your changes. Lines starting --- .../sass_extensions/sprites/sprite_map.rb | 17 ++++++++++++++--- lib/compass/sass_extensions/sprites/sprites.rb | 2 +- test/integrations/sprites_test.rb | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/compass/sass_extensions/sprites/sprite_map.rb b/lib/compass/sass_extensions/sprites/sprite_map.rb index 7e19fdf5..10f860e1 100644 --- a/lib/compass/sass_extensions/sprites/sprite_map.rb +++ b/lib/compass/sass_extensions/sprites/sprite_map.rb @@ -25,7 +25,7 @@ module Compass # Returns the Glob of image files for this sprite def files - @files ||= Dir[File.join(Compass.configuration.images_path, uri)].sort + @files ||= Dir[File.join(Compass.configuration.images_path, uri).gsub('/*', '/**/*')].sort end # Returns an Array of image names without the file extension @@ -50,7 +50,18 @@ module Compass end def ensure_path_and_name! - @path, @name = Compass::Sprites.path_and_name(uri) + @path ||= get_path + @name ||= get_name + end + + def get_name + _, name = Compass::Sprites.path_and_name(uri) + name + end + + def get_path + path, _ = Compass::Sprites.path_and_name(uri) + path end def key(uri, options) @@ -130,7 +141,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default; SCSS end.join - content += "\n$#{name}-sprites: sprite-map(\"#{uri}\",\n$cleanup: $#{name}-clean-up,\n" + content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$cleanup: $#{name}-clean-up,\n" content += sprite_names.map do |sprite_name| %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, diff --git a/lib/compass/sass_extensions/sprites/sprites.rb b/lib/compass/sass_extensions/sprites/sprites.rb index c0c5dc21..7696d3bd 100644 --- a/lib/compass/sass_extensions/sprites/sprites.rb +++ b/lib/compass/sass_extensions/sprites/sprites.rb @@ -7,7 +7,7 @@ module Compass [$1, $3, $4] end end - + def self.discover_sprites(uri) self.load_map(uri, {}).files end diff --git a/test/integrations/sprites_test.rb b/test/integrations/sprites_test.rb index 3f482e62..ea077625 100644 --- a/test/integrations/sprites_test.rb +++ b/test/integrations/sprites_test.rb @@ -587,5 +587,21 @@ class SpritesTest < Test::Unit::TestCase SCSS assert !css.empty? end + + it "should generate a sprite from nested folders" do + css = render <<-SCSS + @import "nested/*.png"; + @include all-nested-sprites; + SCSS + assert_correct css, <<-CSS + .nested-sprite, .nested-ten-by-ten { + background: url('/nested-55a8935544.png') no-repeat; + } + + .nested-ten-by-ten { + background-position: 0 0; + } + CSS + end end \ No newline at end of file