test files for horizontal sprites

This commit is contained in:
Scott Davis 2011-06-25 01:28:01 -04:00
parent 18c79f51a2
commit 43868ecabd
4 changed files with 66 additions and 4 deletions

View File

@ -104,8 +104,9 @@ $#{name}-spacing: 0 !default;
$#{name}-repeat: no-repeat !default; $#{name}-repeat: no-repeat !default;
$#{name}-prefix: '' !default; $#{name}-prefix: '' !default;
$#{name}-clean-up: true !default; $#{name}-clean-up: true !default;
$#{name}-layout:vertical !default;
#{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $cleanup: $#{name}-clean-up);" : generate_overrides(uri, name) } #{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\", $layout: $#{name}-layout, $cleanup: $#{name}-clean-up);" : generate_overrides(uri, name) }
// All sprites should extend this class // All sprites should extend this class
// The #{name}-sprite mixin will do so for you. // The #{name}-sprite mixin will do so for you.
@ -160,7 +161,7 @@ $#{name}-#{sprite_name}-repeat: $#{name}-repeat !default;
SCSS SCSS
end.join end.join
content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$cleanup: $#{name}-clean-up,\n" content += "\n$#{name}-sprites: sprite-map(\"#{uri}\", \n$layout: $#{name}-layout, \n$cleanup: $#{name}-clean-up,\n"
content += sprites.map do |sprite_name| content += sprites.map do |sprite_name|
%Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position, %Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position,
$#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing, $#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,

View File

@ -604,4 +604,32 @@ class SpritesTest < Test::Unit::TestCase
CSS CSS
end end
it "should calculate corret sprite demsions when givin spacing via issue#253" do
css = render <<-SCSS
$squares-layout:horizontal;
@import "squares/*.png";
.foo {
@include sprite-background-position($squares-sprites, "twenty-by-twenty");
}
.bar {
@include sprite-background-position($squares-sprites, "ten-by-ten");
}
SCSS
assert_equal [30, 20], image_size('squares-s*.png')
other_css = <<-CSS
.squares-sprite {
background: url('/squares-s161c60ad78.png') no-repeat;
}
.foo {
background-position: -10px 0;
}
.bar {
background-position: 0 0;
}
CSS
assert_correct css.gsub("\n", '').gsub(' ', ''), other_css.gsub("\n", '').gsub(' ', '')
end
end end

View File

@ -26,6 +26,7 @@ class SpritesImageTest < Test::Unit::TestCase
options.stubs(:get_var).with("#{sprite_name}-repeat").returns(::OpenStruct.new(:value => @repeat)) options.stubs(:get_var).with("#{sprite_name}-repeat").returns(::OpenStruct.new(:value => @repeat))
options.stubs(:get_var).with("#{sprite_name}-spacing").returns(::OpenStruct.new(:value => @spacing)) options.stubs(:get_var).with("#{sprite_name}-spacing").returns(::OpenStruct.new(:value => @spacing))
options.stubs(:get_var).with("#{sprite_name}-position").returns(::OpenStruct.new(:value => @position)) options.stubs(:get_var).with("#{sprite_name}-position").returns(::OpenStruct.new(:value => @position))
options.stubs(:get_var).with("layout").returns(::OpenStruct.new(:value => 'vertical'))
options options
end end

View File

@ -12,7 +12,7 @@ class SpriteMapTest < Test::Unit::TestCase
config.images_path = @images_tmp_path config.images_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)} @options = {'cleanup' => Sass::Script::Bool.new(true), 'layout' => Sass::Script::String.new('vertical')}
@base = sprite_map_test(@options) @base = sprite_map_test(@options)
end end
@ -84,4 +84,36 @@ class SpriteMapTest < Test::Unit::TestCase
assert !File.exists?(file), "Sprite file did not get removed" assert !File.exists?(file), "Sprite file did not get removed"
end end
it "should have a vertical layout" do
assert_equal [0, 10, 20, 30], @base.images.map(&:top)
assert_equal [0, 0, 0, 0], @base.images.map(&:left)
end
# Horizontal tests
def horizontal
opts = @options.merge("layout" => Sass::Script::String.new('horizontal'))
sprite_map_test(opts)
end
it "should have a horizontal layout" do
base = horizontal
assert_equal 10, base.height
assert_equal 40, base.width
end
it "should layout images horizontaly" do
base = horizontal
assert_equal [0, 10, 20, 30], base.images.map(&:left)
assert_equal [0, 0, 0, 0], base.images.map(&:top)
end
it "should generate a horrizontal sprite" do
base = horizontal
base.generate
assert File.exists?(base.filename)
FileUtils.rm base.filename
end
end end