2011-04-28 04:00:54 +00:00
|
|
|
require 'test_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'compass'
|
|
|
|
require 'compass/logger'
|
|
|
|
require 'sass/plugin'
|
|
|
|
|
|
|
|
|
|
|
|
class SpritesTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
Compass.reset_configuration!
|
2011-05-10 22:02:32 +00:00
|
|
|
@images_src_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images')
|
|
|
|
@images_tmp_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images-tmp')
|
2011-08-21 00:22:50 +00:00
|
|
|
@generated_images_tmp_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'generated-images-tmp')
|
2011-04-28 04:00:54 +00:00
|
|
|
::FileUtils.cp_r @images_src_path, @images_tmp_path
|
|
|
|
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
|
|
|
Compass.configure_sass_plugin!
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Compass.reset_configuration!
|
|
|
|
::FileUtils.rm_r @images_tmp_path
|
2011-08-21 00:22:50 +00:00
|
|
|
::FileUtils.rm_rf @generated_images_tmp_path
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def map_location(file)
|
2011-05-10 23:20:38 +00:00
|
|
|
map_files(file).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def map_files(glob)
|
|
|
|
Dir.glob(File.join(@images_tmp_path, glob))
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def image_size(file)
|
|
|
|
IO.read(map_location(file))[0x10..0x18].unpack('NN')
|
|
|
|
end
|
|
|
|
|
|
|
|
def image_md5(file)
|
|
|
|
md5 = Digest::MD5.new
|
|
|
|
md5.update IO.read(map_location(file))
|
|
|
|
md5.hexdigest
|
|
|
|
end
|
|
|
|
|
|
|
|
def render(scss)
|
|
|
|
scss = %Q(@import "compass"; #{scss})
|
|
|
|
options = Compass.sass_engine_options
|
|
|
|
options[:line_comments] = false
|
|
|
|
options[:style] = :expanded
|
|
|
|
options[:syntax] = :scss
|
2011-09-19 16:03:17 +00:00
|
|
|
options[:compass] ||= {}
|
|
|
|
options[:compass][:logger] ||= Compass::NullLogger.new
|
2011-04-28 04:00:54 +00:00
|
|
|
css = Sass::Engine.new(scss, options).render
|
|
|
|
# reformat to fit result of heredoc:
|
|
|
|
" #{css.gsub('@charset "UTF-8";', '').gsub(/\n/, "\n ").strip}\n"
|
|
|
|
end
|
|
|
|
|
2011-11-04 14:51:34 +00:00
|
|
|
def clean(string)
|
|
|
|
string.gsub("\n", '').gsub(' ', '')
|
|
|
|
end
|
|
|
|
|
2011-04-28 04:00:54 +00:00
|
|
|
it "should generate sprite classes" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sbbc18e2129.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-06-12 05:37:44 +00:00
|
|
|
assert_equal image_md5('squares-s*.png'), '7349a0f4e88ea80abddcf6ac2486abe3'
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
2011-08-21 00:22:50 +00:00
|
|
|
it "should output and serve sprite files using the generated images directory" do
|
|
|
|
Compass.reset_configuration!
|
|
|
|
file = StringIO.new(<<-CONFIG)
|
|
|
|
images_path = #{@images_tmp_path.inspect}
|
|
|
|
generated_images_path = #{@generated_images_tmp_path.inspect}
|
|
|
|
http_generated_images_path = "/images/generated"
|
|
|
|
CONFIG
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
|
|
|
Compass.configure_sass_plugin!
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_not_nil Dir.glob("#{@generated_images_tmp_path}/squares-s*.png").first
|
|
|
|
assert_correct <<-CSS, css
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/images/generated/squares-sbbc18e2129.png') no-repeat;
|
2011-08-21 00:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2011-04-28 04:00:54 +00:00
|
|
|
it "should generate sprite classes with dimensions" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-sprite-dimensions: true;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sbbc18e2129.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
height: 10px;
|
|
|
|
width: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should provide sprite mixin" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
|
|
|
|
.cubicle {
|
|
|
|
@include squares-sprite("ten-by-ten");
|
|
|
|
}
|
|
|
|
|
|
|
|
.large-cube {
|
|
|
|
@include squares-sprite("twenty-by-twenty", true);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .cubicle, .large-cube {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sbbc18e2129.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.cubicle {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.large-cube {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# CUSTOMIZATIONS:
|
|
|
|
|
|
|
|
it "should be possible to change the base class" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-sprite-base-class: ".circles";
|
|
|
|
@import "squares/*.png";
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.circles {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sbbc18e2129.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate the spacing between images but not before first image" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-ten-by-ten-spacing: 33px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-s563a5e0855.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -43px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 63]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate the spacing between images" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-twenty-by-twenty-spacing: 33px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-s4ea353fa6d.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -43px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 63]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate the maximum spacing between images" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-ten-by-ten-spacing: 44px;
|
|
|
|
$squares-twenty-by-twenty-spacing: 33px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sf4771cb124.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -54px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 74]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate the maximum spacing between images in reversed order" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-ten-by-ten-spacing: 33px;
|
|
|
|
$squares-twenty-by-twenty-spacing: 44px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sc82d6f3cf4.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -54px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 74]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate the default spacing between images" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-spacing: 22px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-s2f4aa65dcf.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -32px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 52]
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use position adjustments in functions" do
|
|
|
|
css = render <<-SCSS
|
2011-05-11 01:04:57 +00:00
|
|
|
$squares: sprite-map("squares/*.png", $position: 100%);
|
2011-04-28 04:00:54 +00:00
|
|
|
.squares-sprite {
|
|
|
|
background: $squares no-repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
background-position: sprite-position($squares, ten-by-ten, 100%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
|
|
|
background-position: sprite-position($squares, ten-by-ten, 4px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
background-position: sprite-position($squares, twenty-by-twenty, -3px, 2px);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sce5dc30797.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
background-position: 100% 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
|
|
|
background-position: -6px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
background-position: -3px -8px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-06-12 05:37:44 +00:00
|
|
|
assert_equal image_md5('squares-s*.png'), '9cc7ce48cfaf304381c2d08adefd2fb6'
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should use position adjustments in mixins" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-position: 100%;
|
|
|
|
@import "squares/*.png";
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
@include squares-sprite("ten-by-ten", $offset-x: 100%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
|
|
|
@include squares-sprite("ten-by-ten", $offset-x: 4px);
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
@include squares-sprite("twenty-by-twenty", $offset-x: -3px, $offset-y: 2px);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .adjusted-percentage, .adjusted-px-1, .adjusted-px-2 {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sce5dc30797.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
background-position: 100% 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
|
|
|
background-position: -6px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
background-position: -3px -8px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-06-12 05:37:44 +00:00
|
|
|
assert_equal image_md5('squares-s*.png'), '9cc7ce48cfaf304381c2d08adefd2fb6'
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should repeat the image" do
|
|
|
|
css = render <<-SCSS
|
2011-12-10 05:55:16 +00:00
|
|
|
$squares-repeat: repeat-x;
|
2011-04-28 04:00:54 +00:00
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-12-10 17:49:34 +00:00
|
|
|
background: url('/squares-s65c43cd573.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 30]
|
2011-06-12 05:37:44 +00:00
|
|
|
assert_equal image_md5('squares-s*.png'), 'a77a2fd43f04d791722b706aa7c9f1c1'
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should allow the position of a sprite to be specified in absolute pixels" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-ten-by-ten-position: 10px;
|
|
|
|
$squares-twenty-by-twenty-position: 10px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sb9d9a8ca6a.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
|
|
|
background-position: -10px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
|
|
|
background-position: -10px -10px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [30, 30]
|
2011-06-12 05:37:44 +00:00
|
|
|
assert_equal image_md5('squares-s*.png'), '9856ced9e8211b6b28ff782019a0d905'
|
2011-04-28 04:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should provide a nice errors for lemonade's old users" do
|
|
|
|
assert_raise(Sass::SyntaxError) do
|
|
|
|
render <<-SCSS
|
|
|
|
.squares {
|
|
|
|
background: sprite-url("squares/*.png") no-repeat;
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
end
|
|
|
|
assert_raise(Sass::SyntaxError) do
|
|
|
|
css = render <<-SCSS
|
|
|
|
.squares {
|
|
|
|
background: sprite-image("squares/twenty-by-twenty.png") no-repeat;
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
end
|
|
|
|
assert_raise(Sass::SyntaxError) do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
|
|
|
|
.squares {
|
|
|
|
background: sprite-position("squares/twenty-by-twenty.png") no-repeat;
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should work even if @import is missing" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
.squares {
|
2011-05-11 01:04:57 +00:00
|
|
|
background: sprite(sprite-map("squares/*.png"), twenty-by-twenty) no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-sd817b59156.png') 0 -10px no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should calculate corret sprite demsions when givin spacing via issue#253" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-spacing: 10px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
.foo {
|
|
|
|
@include sprite-background-position($squares-sprites, "twenty-by-twenty");
|
|
|
|
}
|
|
|
|
.bar {
|
|
|
|
@include sprite-background-position($squares-sprites, "ten-by-ten");
|
|
|
|
}
|
|
|
|
SCSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal image_size('squares-s*.png'), [20, 40]
|
2011-04-28 04:00:54 +00:00
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.squares-sprite {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-s555875d730.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.foo {
|
|
|
|
background-position: 0 -20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.bar {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
|
2011-07-02 20:27:32 +00:00
|
|
|
it "should render correct sprite with css selectors via issue#248" do
|
2011-04-28 04:00:54 +00:00
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
@include all-selectors-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.selectors-sprite, .selectors-ten-by-ten {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/selectors-s7e84acb3d2.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.selectors-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:hover, .selectors-ten-by-ten.ten-by-ten_hover, .selectors-ten-by-ten.ten-by-ten-hover {
|
|
|
|
background-position: 0 -20px;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:target, .selectors-ten-by-ten.ten-by-ten_target, .selectors-ten-by-ten.ten-by-ten-target {
|
|
|
|
background-position: 0 -30px;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:active, .selectors-ten-by-ten.ten-by-ten_active, .selectors-ten-by-ten.ten-by-ten-active {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-07-02 20:27:32 +00:00
|
|
|
|
|
|
|
it "should honor offsets when rendering selectors via issue#449" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
@include all-selectors-sprites($offset-x: 20px, $offset-y: 20px);
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.selectors-sprite, .selectors-ten-by-ten {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/selectors-s7e84acb3d2.png') no-repeat;
|
2011-07-02 20:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.selectors-ten-by-ten {
|
|
|
|
background-position: 20px 20px;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:hover, .selectors-ten-by-ten.ten-by-ten_hover, .selectors-ten-by-ten.ten-by-ten-hover {
|
|
|
|
background-position: 20px 0;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:target, .selectors-ten-by-ten.ten-by-ten_target, .selectors-ten-by-ten.ten-by-ten-target {
|
|
|
|
background-position: 20px -10px;
|
|
|
|
}
|
|
|
|
.selectors-ten-by-ten:active, .selectors-ten-by-ten.ten-by-ten_active, .selectors-ten-by-ten.ten-by-ten-active {
|
|
|
|
background-position: 20px 10px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-04-28 04:00:54 +00:00
|
|
|
|
2011-07-02 20:27:32 +00:00
|
|
|
it "should render correct sprite with css selectors via magic mixin" do
|
2011-04-28 04:00:54 +00:00
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
a {
|
|
|
|
@include selectors-sprite(ten-by-ten)
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.selectors-sprite, a {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/selectors-s7e84acb3d2.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
a:hover, a.ten-by-ten_hover, a.ten-by-ten-hover {
|
|
|
|
background-position: 0 -20px;
|
|
|
|
}
|
|
|
|
a:target, a.ten-by-ten_target, a.ten-by-ten-target {
|
|
|
|
background-position: 0 -30px;
|
|
|
|
}
|
|
|
|
a:active, a.ten-by-ten_active, a.ten-by-ten-active {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-07-02 20:27:32 +00:00
|
|
|
|
2011-04-28 04:00:54 +00:00
|
|
|
|
|
|
|
it "should not render corret sprite with css selectors via magic mixin" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
a {
|
|
|
|
$disable-magic-sprite-selectors:true;
|
|
|
|
@include selectors-sprite(ten-by-ten)
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.selectors-sprite, a {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/selectors-s7e84acb3d2.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-07-01 01:44:19 +00:00
|
|
|
|
|
|
|
it "should render corret sprite with css selectors via magic mixin with the correct offsets" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
a {
|
|
|
|
@include selectors-sprite(ten-by-ten, false, 5, -5)
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.selectors-sprite, a {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/selectors-s7e84acb3d2.png') no-repeat;
|
2011-07-01 01:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
background-position: 5px -5px;
|
|
|
|
}
|
|
|
|
a:hover, a.ten-by-ten_hover, a.ten-by-ten-hover {
|
|
|
|
background-position: 5px -25px;
|
|
|
|
}
|
|
|
|
a:target, a.ten-by-ten_target, a.ten-by-ten-target {
|
|
|
|
background-position: 5px -35px;
|
|
|
|
}
|
|
|
|
a:active, a.ten-by-ten_active, a.ten-by-ten-active {
|
|
|
|
background-position: 5px -15px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-04-28 04:00:54 +00:00
|
|
|
|
|
|
|
it "should raise error on filenames that are not valid sass syntax" do
|
|
|
|
assert_raise(Compass::Error) do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "prefix/*.png";
|
|
|
|
a {
|
|
|
|
@include squares-sprite(20-by-20);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should generate sprite with bad repeat-x dimensions" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$ko-starbg26x27-repeat: repeat-x;
|
|
|
|
@import "ko/*.png";
|
|
|
|
@include all-ko-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.ko-sprite, .ko-default_background, .ko-starbg26x27 {
|
2011-12-10 17:49:34 +00:00
|
|
|
background: url('/ko-sd46dfbab4f.png') no-repeat;
|
2011-04-28 04:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.ko-default_background {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ko-starbg26x27 {
|
|
|
|
background-position: 0 -128px;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-05-10 23:20:38 +00:00
|
|
|
|
|
|
|
it "should generate a sprite and remove the old file" do
|
2011-06-10 10:11:28 +00:00
|
|
|
FileUtils.touch File.join(@images_tmp_path, "selectors-scc8834Fdd.png")
|
|
|
|
assert_equal 1, map_files('selectors-s*.png').size
|
2011-05-10 23:20:38 +00:00
|
|
|
css = render <<-SCSS
|
|
|
|
@import "selectors/*.png";
|
|
|
|
a {
|
|
|
|
$disable-magic-sprite-selectors:true;
|
|
|
|
@include selectors-sprite(ten-by-ten)
|
|
|
|
}
|
|
|
|
SCSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal 1, map_files('selectors-s*.png').size, "File was not removed"
|
2011-05-10 23:20:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should generate a sprite and NOT remove the old file" do
|
2011-06-10 10:11:28 +00:00
|
|
|
FileUtils.touch File.join(@images_tmp_path, "selectors-scc8834Ftest.png")
|
|
|
|
assert_equal 1, map_files('selectors-s*.png').size
|
2011-05-10 23:20:38 +00:00
|
|
|
css = render <<-SCSS
|
|
|
|
$selectors-clean-up: false;
|
|
|
|
@import "selectors/*.png";
|
|
|
|
a {
|
|
|
|
$disable-magic-sprite-selectors:true;
|
|
|
|
@include selectors-sprite(ten-by-ten)
|
|
|
|
}
|
|
|
|
SCSS
|
2011-06-10 10:11:28 +00:00
|
|
|
assert_equal 2, map_files('selectors-s*.png').size, "File was removed"
|
2011-05-10 23:20:38 +00:00
|
|
|
end
|
2011-05-11 01:51:35 +00:00
|
|
|
|
2011-11-04 13:19:37 +00:00
|
|
|
it "should generate a sprite if the sprite is a bool" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "bool/*.png";
|
|
|
|
a {
|
|
|
|
@include bool-sprite(false);
|
|
|
|
}
|
|
|
|
a {
|
|
|
|
@include bool-sprite(true);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert !css.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-05-11 01:51:35 +00:00
|
|
|
it "should generate a sprite if the sprite is a colorname" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "colors/*.png";
|
|
|
|
a {
|
|
|
|
@include colors-sprite(blue);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
assert !css.empty?
|
|
|
|
end
|
2011-05-11 02:44:10 +00:00
|
|
|
|
|
|
|
it "should generate a sprite from nested folders" do
|
|
|
|
css = render <<-SCSS
|
2011-05-11 06:41:51 +00:00
|
|
|
@import "nested/**/*.png";
|
2011-05-11 02:44:10 +00:00
|
|
|
@include all-nested-sprites;
|
|
|
|
SCSS
|
|
|
|
assert_correct css, <<-CSS
|
|
|
|
.nested-sprite, .nested-ten-by-ten {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/nested-s7b93e0b6bf.png') no-repeat;
|
2011-05-11 02:44:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.nested-ten-by-ten {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
2011-06-25 05:28:01 +00:00
|
|
|
|
2011-06-27 05:21:45 +00:00
|
|
|
it "should create horizontal sprite" do
|
2011-06-25 05:28:01 +00:00
|
|
|
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 {
|
2011-09-19 18:04:35 +00:00
|
|
|
background: url('/squares-s4bd95c5c56.png') no-repeat;
|
2011-06-25 05:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.foo {
|
|
|
|
background-position: -10px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.bar {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
CSS
|
2011-11-04 14:51:34 +00:00
|
|
|
assert_correct clean(css), clean(other_css)
|
2011-06-25 05:28:01 +00:00
|
|
|
end
|
2011-04-28 04:00:54 +00:00
|
|
|
|
2011-10-25 20:14:46 +00:00
|
|
|
it "should allow use of demension functions" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
$h: squares-sprite-height(twenty-by-twenty);
|
|
|
|
$w: squares-sprite-width(twenty-by-twenty);
|
|
|
|
.div {
|
|
|
|
height:$h + 1px;
|
|
|
|
width:$w + 2px;
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
other_css = <<-CSS
|
|
|
|
.squares-sprite {
|
|
|
|
background: url('/squares-sbbc18e2129.png') no-repeat;
|
|
|
|
}
|
|
|
|
.div {
|
|
|
|
height:21px;
|
|
|
|
width:22px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-11-04 14:51:34 +00:00
|
|
|
assert_correct clean(css), clean(other_css)
|
2011-10-25 20:14:46 +00:00
|
|
|
end
|
|
|
|
|
2011-11-04 13:42:35 +00:00
|
|
|
it "should replace text with images and dimensions using sprites" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "colors/*.png";
|
|
|
|
.blue {
|
|
|
|
@include sprite-replace-text($colors-sprites, blue);
|
|
|
|
}
|
|
|
|
.yellow {
|
|
|
|
@include sprite-replace-text-with-dimensions($colors-sprites, yellow);
|
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
other_css = <<-CSS
|
|
|
|
.colors-sprite {
|
|
|
|
background:url('/colors-s58671cb5bb.png') no-repeat;
|
|
|
|
}
|
|
|
|
.blue {
|
|
|
|
text-indent:-119988px;
|
|
|
|
overflow:hidden;
|
|
|
|
text-align:left;
|
|
|
|
background-position:0 0;
|
|
|
|
background-image:url('/colors-s58671cb5bb.png');
|
2011-11-04 14:47:31 +00:00
|
|
|
background-repeat:no-repeat;
|
|
|
|
}
|
|
|
|
|
2011-11-04 13:42:35 +00:00
|
|
|
.yellow {
|
|
|
|
text-indent:-119988px;
|
|
|
|
overflow:hidden;
|
|
|
|
text-align:left;
|
|
|
|
background-position:0 -10px;
|
|
|
|
height:10px;
|
|
|
|
width:10px;
|
|
|
|
background-image:url('/colors-s58671cb5bb.png');
|
|
|
|
background-repeat:no-repeat;
|
|
|
|
}
|
|
|
|
CSS
|
2011-11-04 14:51:34 +00:00
|
|
|
assert_correct clean(css), clean(other_css)
|
2011-11-04 13:42:35 +00:00
|
|
|
end
|
2011-11-04 14:47:31 +00:00
|
|
|
|
|
|
|
it "should inline the sprite file" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$colors-inline:true;
|
|
|
|
@import "colors/*.png";
|
|
|
|
@include all-colors-sprites;
|
|
|
|
SCSS
|
|
|
|
other_css = <<-CSS
|
|
|
|
.colors-sprite, .colors-blue, .colors-yellow {
|
|
|
|
background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAUCAAAAACRhfOKAAAAHElEQVR42mM5wQADLP8JMRlIUIvE/IdgctLTNgCHDhEQVD4ceAAAAABJRU5ErkJggg==');
|
|
|
|
}
|
|
|
|
.colors-blue {
|
|
|
|
background-position:0 0;
|
|
|
|
}.colors-yellow {
|
|
|
|
background-position:0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
2011-11-04 14:51:34 +00:00
|
|
|
assert_correct clean(css), clean(other_css)
|
2011-11-04 14:47:31 +00:00
|
|
|
end
|
2011-10-25 20:14:46 +00:00
|
|
|
|
2011-06-25 05:28:01 +00:00
|
|
|
end
|