2010-10-14 22:16:49 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
|
|
require "compass/sprites"
|
2010-10-17 17:38:32 +00:00
|
|
|
require 'digest/md5'
|
2010-10-14 22:16:49 +00:00
|
|
|
|
|
|
|
describe Compass::Sprites do
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:16:49 +00:00
|
|
|
before :each do
|
2010-10-17 14:18:04 +00:00
|
|
|
@images_src_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images')
|
|
|
|
@images_tmp_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images-tmp')
|
|
|
|
FileUtils.cp_r @images_src_path, @images_tmp_path
|
2011-02-20 18:16:11 +00:00
|
|
|
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
2010-10-14 22:16:49 +00:00
|
|
|
Compass.configure_sass_plugin!
|
|
|
|
end
|
|
|
|
|
2010-10-17 14:18:04 +00:00
|
|
|
after :each do
|
|
|
|
FileUtils.rm_r @images_tmp_path
|
|
|
|
end
|
|
|
|
|
2010-12-06 01:50:25 +00:00
|
|
|
def map_location(file)
|
|
|
|
Dir.glob(File.join(@images_tmp_path, file)).first
|
|
|
|
end
|
|
|
|
|
2010-10-17 14:18:04 +00:00
|
|
|
def image_size(file)
|
2010-12-06 01:50:25 +00:00
|
|
|
IO.read(map_location(file))[0x10..0x18].unpack('NN')
|
2010-10-17 14:18:04 +00:00
|
|
|
end
|
2010-10-17 17:38:32 +00:00
|
|
|
|
|
|
|
def image_md5(file)
|
|
|
|
md5 = Digest::MD5.new
|
2010-12-06 01:50:25 +00:00
|
|
|
md5.update IO.read(map_location(file))
|
2010-10-17 17:38:32 +00:00
|
|
|
md5.hexdigest
|
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:16:49 +00:00
|
|
|
def render(scss)
|
|
|
|
scss = %Q(@import "compass"; #{scss})
|
|
|
|
options = Compass.sass_engine_options
|
2010-10-14 22:41:41 +00:00
|
|
|
options[:line_comments] = false
|
|
|
|
options[:style] = :expanded
|
2010-10-14 22:16:49 +00:00
|
|
|
options[:syntax] = :scss
|
|
|
|
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-02-17 07:30:11 +00:00
|
|
|
#Callbacks
|
|
|
|
describe 'callbacks' do
|
|
|
|
it "should fire on_sprite_saved" do
|
|
|
|
saved = false
|
|
|
|
path = nil
|
|
|
|
Compass.configuration.on_sprite_saved {|filepath| path = filepath; saved = true }
|
|
|
|
render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
saved.should eq true
|
|
|
|
path.should be_kind_of String
|
|
|
|
end
|
|
|
|
it "should fire on_sprite_generated" do
|
|
|
|
saved = false
|
|
|
|
sprite_data = nil
|
|
|
|
Compass.configuration.on_sprite_generated {|data| sprite_data = data; saved = true }
|
|
|
|
render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
sprite_data.should be_kind_of ChunkyPNG::Image
|
|
|
|
saved.should eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DEFAULT USAGE:
|
2010-10-14 22:16:49 +00:00
|
|
|
it "should generate sprite classes" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-161c60ad78.png') no-repeat;
|
2010-10-14 23:24:14 +00:00
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-14 23:24:14 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-14 23:24:14 +00:00
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2011-01-20 22:10:35 +00:00
|
|
|
image_md5('squares-*.png').should == 'fcc93d7b279c2ad6898fbca49cbd01e1'
|
2010-10-14 22:16:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should generate sprite classes with dimensions" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-sprite-dimensions: true;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-161c60ad78.png') no-repeat;
|
2010-10-14 23:24:14 +00:00
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-14 22:16:49 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
height: 10px;
|
2010-10-14 23:24:14 +00:00
|
|
|
width: 10px;
|
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-14 22:16:49 +00:00
|
|
|
background-position: 0 -10px;
|
|
|
|
height: 20px;
|
2010-10-14 23:24:14 +00:00
|
|
|
width: 20px;
|
|
|
|
}
|
2010-10-14 22:16:49 +00:00
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2010-10-14 22:16:49 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:41:41 +00:00
|
|
|
it "should provide sprite mixin" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
@import "squares/*.png";
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:41:41 +00:00
|
|
|
.cubicle {
|
2010-11-30 04:27:07 +00:00
|
|
|
@include squares-sprite("ten-by-ten");
|
2010-10-14 22:41:41 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:41:41 +00:00
|
|
|
.large-cube {
|
2010-11-30 04:27:07 +00:00
|
|
|
@include squares-sprite("twenty-by-twenty", true);
|
2010-10-14 22:41:41 +00:00
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
|
|
|
.squares-sprite, .cubicle, .large-cube {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-161c60ad78.png') no-repeat;
|
2010-10-14 23:24:14 +00:00
|
|
|
}
|
2010-10-14 22:41:41 +00:00
|
|
|
|
|
|
|
.cubicle {
|
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.large-cube {
|
|
|
|
background-position: 0 -10px;
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2010-10-14 22:49:23 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:27:59 +00:00
|
|
|
# CUSTOMIZATIONS:
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:49:23 +00:00
|
|
|
it "should be possible to change the base class" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-sprite-base-class: ".circles";
|
|
|
|
@import "squares/*.png";
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
|
|
|
.circles {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-161c60ad78.png') no-repeat;
|
2010-10-14 23:24:14 +00:00
|
|
|
}
|
2010-10-14 22:49:23 +00:00
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2010-10-14 22:41:41 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:27:59 +00:00
|
|
|
it "should calculate the spacing between images but not before first image" do
|
|
|
|
css = render <<-SCSS
|
2010-11-30 04:27:07 +00:00
|
|
|
$squares-ten-by-ten-spacing: 33px;
|
2010-10-17 13:27:59 +00:00
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-89450808af.png') no-repeat;
|
2010-10-17 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 -43px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 63]
|
2010-10-17 13:27:59 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:27:59 +00:00
|
|
|
it "should calculate the spacing between images" do
|
|
|
|
css = render <<-SCSS
|
2010-11-30 04:27:07 +00:00
|
|
|
$squares-twenty-by-twenty-spacing: 33px;
|
2010-10-17 13:27:59 +00:00
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-673837183a.png') no-repeat;
|
2010-10-17 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 -43px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 63]
|
2010-10-17 13:27:59 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:27:59 +00:00
|
|
|
it "should calculate the maximum spacing between images" do
|
|
|
|
css = render <<-SCSS
|
2010-11-30 04:27:07 +00:00
|
|
|
$squares-ten-by-ten-spacing: 44px;
|
|
|
|
$squares-twenty-by-twenty-spacing: 33px;
|
2010-10-17 13:27:59 +00:00
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-1cd84c9068.png') no-repeat;
|
2010-10-17 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 -54px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 74]
|
2010-10-17 13:27:59 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:27:59 +00:00
|
|
|
it "should calculate the maximum spacing between images in reversed order" do
|
|
|
|
css = render <<-SCSS
|
2010-11-30 04:27:07 +00:00
|
|
|
$squares-ten-by-ten-spacing: 33px;
|
|
|
|
$squares-twenty-by-twenty-spacing: 44px;
|
2010-10-17 13:27:59 +00:00
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-f25b7090ca.png') no-repeat;
|
2010-10-17 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 13:27:59 +00:00
|
|
|
background-position: 0 -54px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 74]
|
2010-10-17 13:27:59 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 13:44:29 +00:00
|
|
|
it "should calculate the default spacing between images" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-spacing: 22px;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-d66bf24bab.png') no-repeat;
|
2010-10-17 13:44:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 13:44:29 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 13:44:29 +00:00
|
|
|
background-position: 0 -32px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 52]
|
2010-10-17 13:44:29 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
it "should use position adjustments in functions" do
|
|
|
|
css = render <<-SCSS
|
2010-12-01 07:09:31 +00:00
|
|
|
$squares: sprite-map("squares/*.png", $position: 100%);
|
2010-12-01 00:55:53 +00:00
|
|
|
.squares-sprite {
|
2010-12-01 07:09:31 +00:00
|
|
|
background: $squares no-repeat;
|
2010-12-01 00:55:53 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-percentage {
|
2010-12-01 07:09:31 +00:00
|
|
|
background-position: sprite-position($squares, ten-by-ten, 100%);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-px-1 {
|
2010-12-01 07:09:31 +00:00
|
|
|
background-position: sprite-position($squares, ten-by-ten, 4px);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-px-2 {
|
2010-12-01 07:09:31 +00:00
|
|
|
background-position: sprite-position($squares, twenty-by-twenty, -3px, 2px);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
|
|
|
.squares-sprite {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-8e490168dd.png') no-repeat;
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
background-position: 100% 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
2010-12-20 01:51:40 +00:00
|
|
|
background-position: -6px 0;
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
background-position: -3px -8px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2011-01-20 22:10:35 +00:00
|
|
|
image_md5('squares-*.png').should == '652b67f5e9092520d6f26caae7e18012'
|
2010-10-17 17:38:32 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
it "should use position adjustments in mixins" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-position: 100%;
|
|
|
|
@import "squares/*.png";
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-percentage {
|
2010-12-01 00:55:53 +00:00
|
|
|
@include squares-sprite("ten-by-ten", $offset-x: 100%);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-px-1 {
|
2010-12-01 00:55:53 +00:00
|
|
|
@include squares-sprite("ten-by-ten", $offset-x: 4px);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 17:38:32 +00:00
|
|
|
.adjusted-px-2 {
|
2010-12-01 00:55:53 +00:00
|
|
|
@include squares-sprite("twenty-by-twenty", $offset-x: -3px, $offset-y: 2px);
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
|
|
|
.squares-sprite, .adjusted-percentage, .adjusted-px-1, .adjusted-px-2 {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-8e490168dd.png') no-repeat;
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-percentage {
|
|
|
|
background-position: 100% 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-1 {
|
2010-12-20 01:51:40 +00:00
|
|
|
background-position: -6px 0;
|
2010-10-17 17:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.adjusted-px-2 {
|
|
|
|
background-position: -3px -8px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2011-01-20 22:10:35 +00:00
|
|
|
image_md5('squares-*.png').should == '652b67f5e9092520d6f26caae7e18012'
|
2010-10-17 17:38:32 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 21:06:54 +00:00
|
|
|
it "should repeat the image" do
|
|
|
|
css = render <<-SCSS
|
|
|
|
$squares-repeat: repeat;
|
|
|
|
@import "squares/*.png";
|
|
|
|
@include all-squares-sprites;
|
|
|
|
SCSS
|
|
|
|
css.should == <<-CSS
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-a5550fd132.png') no-repeat;
|
2010-10-17 21:06:54 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-ten-by-ten {
|
2010-10-17 21:06:54 +00:00
|
|
|
background-position: 0 0;
|
|
|
|
}
|
|
|
|
|
2010-11-30 04:27:07 +00:00
|
|
|
.squares-twenty-by-twenty {
|
2010-10-17 21:06:54 +00:00
|
|
|
background-position: 0 -10px;
|
|
|
|
}
|
|
|
|
CSS
|
2010-12-06 01:50:25 +00:00
|
|
|
image_size('squares-*.png').should == [20, 30]
|
2011-01-20 22:10:35 +00:00
|
|
|
image_md5('squares-*.png').should == '94abae8440f1b58617f52920b70aaed2'
|
2010-10-17 21:06:54 +00:00
|
|
|
end
|
2010-12-19 02:39:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
css.should == <<-CSS
|
|
|
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
|
|
|
background: url('/squares-89a274044e.png') no-repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
.squares-ten-by-ten {
|
2010-12-20 01:51:40 +00:00
|
|
|
background-position: -10px 0;
|
2010-12-19 02:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.squares-twenty-by-twenty {
|
2010-12-20 01:51:40 +00:00
|
|
|
background-position: -10px -10px;
|
2010-12-19 02:39:35 +00:00
|
|
|
}
|
|
|
|
CSS
|
|
|
|
image_size('squares-*.png').should == [30, 30]
|
2011-01-20 22:10:35 +00:00
|
|
|
image_md5('squares-*.png').should == '2fb19ef9c83018c93c6f147af3a56cb2'
|
2010-12-19 02:39:35 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-12-01 00:55:53 +00:00
|
|
|
it "should provide a nice errors for lemonade's old users" do
|
2010-10-17 22:50:04 +00:00
|
|
|
proc do
|
|
|
|
render <<-SCSS
|
|
|
|
.squares {
|
2010-12-01 00:55:53 +00:00
|
|
|
background: sprite-url("squares/*.png") no-repeat;
|
2010-10-17 22:50:04 +00:00
|
|
|
}
|
|
|
|
SCSS
|
2010-12-01 00:55:53 +00:00
|
|
|
end.should raise_error Sass::SyntaxError,
|
2010-12-01 07:09:31 +00:00
|
|
|
%q(The first argument to sprite-url() must be a sprite map. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
2010-10-17 22:50:04 +00:00
|
|
|
proc do
|
|
|
|
render <<-SCSS
|
|
|
|
.squares {
|
2010-12-01 00:55:53 +00:00
|
|
|
background: sprite-image("squares/twenty-by-twenty.png") no-repeat;
|
2010-10-17 22:50:04 +00:00
|
|
|
}
|
|
|
|
SCSS
|
2010-12-01 00:55:53 +00:00
|
|
|
end.should raise_error Sass::SyntaxError,
|
2010-12-01 07:09:31 +00:00
|
|
|
%q(The sprite-image() function has been replaced by sprite(). See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
2010-10-17 22:50:04 +00:00
|
|
|
proc do
|
|
|
|
render <<-SCSS
|
2010-12-01 00:55:53 +00:00
|
|
|
@import "squares/*.png";
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-17 22:50:04 +00:00
|
|
|
.squares {
|
2010-12-01 00:55:53 +00:00
|
|
|
background: sprite-position("squares/twenty-by-twenty.png") no-repeat;
|
2010-10-17 22:50:04 +00:00
|
|
|
}
|
|
|
|
SCSS
|
2010-12-01 00:55:53 +00:00
|
|
|
end.should raise_error Sass::SyntaxError,
|
2010-12-01 07:09:31 +00:00
|
|
|
%q(The first argument to sprite-position() must be a sprite map. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
2010-12-01 00:55:53 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-12-01 00:55:53 +00:00
|
|
|
it "should work even if @import is missing" do
|
|
|
|
actual_css = render <<-SCSS
|
|
|
|
.squares {
|
2010-12-01 07:09:31 +00:00
|
|
|
background: sprite(sprite-map("squares/*.png"), twenty-by-twenty) no-repeat;
|
2010-12-01 00:55:53 +00:00
|
|
|
}
|
|
|
|
SCSS
|
|
|
|
actual_css.should == <<-CSS
|
|
|
|
.squares {
|
2010-12-06 01:50:25 +00:00
|
|
|
background: url('/squares-145869726f.png') 0 -10px no-repeat;
|
2010-12-01 00:55:53 +00:00
|
|
|
}
|
|
|
|
CSS
|
2010-10-17 22:50:04 +00:00
|
|
|
end
|
2011-02-17 07:30:11 +00:00
|
|
|
|
2010-10-14 22:16:49 +00:00
|
|
|
end
|