more importer tests
This commit is contained in:
parent
0984b48b24
commit
8c48248a72
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
compass (0.12.0.alpha.0.71494ce)
|
compass (0.12.0.alpha.0.0984b48)
|
||||||
chunky_png (~> 1.2)
|
chunky_png (~> 1.2)
|
||||||
fssm (>= 0.2.7)
|
fssm (>= 0.2.7)
|
||||||
sass (~> 3.1)
|
sass (~> 3.1)
|
||||||
|
@ -17,7 +17,16 @@ module Compass
|
|||||||
|
|
||||||
# The Full path to the image
|
# The Full path to the image
|
||||||
def file
|
def file
|
||||||
File.join(Compass.configuration.images_path, relative_file)
|
@file ||= find_file
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_file
|
||||||
|
Compass.configuration.sprite_load_path.each do |path|
|
||||||
|
f = File.join(path, relative_file)
|
||||||
|
if File.exists?(f)
|
||||||
|
return f
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Width of the image
|
# Width of the image
|
||||||
@ -25,6 +34,10 @@ module Compass
|
|||||||
dimensions.first
|
dimensions.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def size
|
||||||
|
@size ||= File.size(file)
|
||||||
|
end
|
||||||
|
|
||||||
# Height of the image
|
# Height of the image
|
||||||
def height
|
def height
|
||||||
dimensions.last
|
dimensions.last
|
||||||
|
@ -16,7 +16,7 @@ module Compass
|
|||||||
calculate_horizontal_positions
|
calculate_horizontal_positions
|
||||||
calculate_width
|
calculate_width
|
||||||
else
|
else
|
||||||
@images.sort! {|a,b| File.size(b.file) <=> File.size(a.file)} #put small images first
|
@images.sort! {|a,b| b.size <=> b.size} #put small images first
|
||||||
calculate_width
|
calculate_width
|
||||||
calulate_vertical_postions
|
calulate_vertical_postions
|
||||||
calculate_height
|
calculate_height
|
||||||
|
@ -23,7 +23,9 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.relative_name(sprite)
|
def self.relative_name(sprite)
|
||||||
|
sprite = File.expand_path(sprite)
|
||||||
Compass.configuration.sprite_load_path.each do |path|
|
Compass.configuration.sprite_load_path.each do |path|
|
||||||
|
path = File.expand_path(path)
|
||||||
if sprite.include?(path)
|
if sprite.include?(path)
|
||||||
return sprite.gsub("#{path}/", "")
|
return sprite.gsub("#{path}/", "")
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
let(:sprite_filename) { 'squares/ten-by-ten.png' }
|
let(:sprite_filename) { 'squares/ten-by-ten.png' }
|
||||||
let(:sprite_path) { File.join(@images_src_path, sprite_filename) }
|
let(:sprite_path) { File.join(@images_tmp_path, sprite_filename) }
|
||||||
let(:sprite_name) { File.basename(sprite_filename, '.png') }
|
let(:sprite_name) { File.basename(sprite_filename, '.png') }
|
||||||
|
|
||||||
|
|
||||||
@ -91,4 +91,24 @@ class SpritesImageTest < Test::Unit::TestCase
|
|||||||
assert_equal 0, img.offset
|
assert_equal 0, img.offset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
test 'gets name for sprite in search path' 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_load_path = [@images_tmp_path, other_folder]
|
||||||
|
Compass.add_configuration(config, "sprite_config")
|
||||||
|
image = Compass::SassExtensions::Sprites::Image.new(sprite_map_test(options), "foo/my.png", options)
|
||||||
|
assert_equal File.join(other_folder, 'foo/my.png'), image.file
|
||||||
|
assert_equal 0, image.size
|
||||||
|
FileUtils.rm_rf other_folder
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -121,5 +121,22 @@ class SpriteMapTest < Test::Unit::TestCase
|
|||||||
assert_equal sizes.max, File.size(@base.images.last.file)
|
assert_equal sizes.max, File.size(@base.images.last.file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should get correct relative_name" 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_load_path = [@images_tmp_path, other_folder]
|
||||||
|
Compass.add_configuration(config, "sprite_config")
|
||||||
|
assert_equal 'foo/my.png', Compass::SassExtensions::Sprites::SpriteMap.relative_name(File.join(other_folder, 'foo/my.png'))
|
||||||
|
FileUtils.rm_rf other_folder
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user