sprite_seach_path implimentation and test case

This commit is contained in:
Scott Davis 2011-07-26 16:21:59 -04:00
parent 9966421f58
commit 9c472b3c36
3 changed files with 27 additions and 1 deletions

View File

@ -66,7 +66,11 @@ module Compass
# Returns the Glob of image files for the uri # Returns the Glob of image files for the uri
def self.files(uri) def self.files(uri)
Dir[File.join(Compass.configuration.images_path, uri)].sort Compass.configuration.sprite_search_path.each do |folder|
files = Dir[File.join(folder, uri)].sort
next if files.empty?
return files
end
end end
# Returns an Array of image names without the file extension # Returns an Array of image names without the file extension

View File

@ -18,6 +18,27 @@ class ImporterTest < Test::Unit::TestCase
{:foo => 'bar'} {:foo => 'bar'}
end end
test "should use search path to find sprites" do
Compass.reset_configuration!
uri = 'foo/*.png'
other_folder = File.join(@images_tmp_path, '../other-temp')
FileUtils.mkdir_p other_folder
FileUtils.mkdir_p File.join(other_folder, 'foo')
%w(my bar).each do |file|
FileUtils.touch(File.join(other_folder, "foo/#{file}.png"))
end
config = Compass::Configuration::Data.new('config')
config.images_path = @images_tmp_path
config.sprite_search_path = [@images_tmp_path, other_folder]
Compass.add_configuration(config, "sprite_config")
importer = Compass::SpriteImporter.new
assert_equal 2, Compass.configuration.sprite_search_path.compact.size
assert Compass.configuration.sprite_search_path.include?(other_folder)
assert_equal ["bar", "my"], Compass::SpriteImporter.sprite_names(uri)
FileUtils.rm_rf other_folder
end
test "name should return the sprite name" do test "name should return the sprite name" do
assert_equal 'selectors', Compass::SpriteImporter.sprite_name(URI) assert_equal 'selectors', Compass::SpriteImporter.sprite_name(URI)
end end

View File

@ -10,6 +10,7 @@ class SpriteMapTest < Test::Unit::TestCase
FileUtils.cp_r @images_src_path, @images_tmp_path FileUtils.cp_r @images_src_path, @images_tmp_path
config = Compass::Configuration::Data.new('config') config = Compass::Configuration::Data.new('config')
config.images_path = @images_tmp_path config.images_path = @images_tmp_path
config.sprite_search_path = [@images_tmp_path]
Compass.add_configuration(config) Compass.add_configuration(config)
Compass.configure_sass_plugin! Compass.configure_sass_plugin!
@options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')} @options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')}