closes #320 and refactored the rspec tests
This commit is contained in:
parent
4a5c968739
commit
96f1e4dc96
@ -7,7 +7,7 @@ GIT
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
compass (0.11.beta.5.7571d4a)
|
compass (0.11.beta.5.4a5c968)
|
||||||
chunky_png (~> 1.1.0)
|
chunky_png (~> 1.1.0)
|
||||||
sass (>= 3.1.0.alpha.249)
|
sass (>= 3.1.0.alpha.249)
|
||||||
|
|
||||||
|
@ -38,14 +38,11 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
sprites = Compass::Sprites.new
|
|
||||||
relative_uri = options[:uri].gsub(/^#{Compass.configuration.images_dir}\//, '')
|
relative_uri = options[:uri].gsub(/^#{Compass.configuration.images_dir}\//, '')
|
||||||
sprite_images = Compass::Sprites.discover_sprites(relative_uri)
|
sprites = Compass::SpriteMap.new(relative_uri, Compass.sass_engine_options)
|
||||||
image_names = sprite_images.map{|i| File.basename(i, '.png')}
|
|
||||||
sprites.path, sprites.name = Compass::Sprites.path_and_name(relative_uri)
|
|
||||||
options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}")
|
options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}")
|
||||||
options[:skip_overrides] ||= false
|
options[:skip_overrides] ||= false
|
||||||
contents = sprites.content_for_images(relative_uri, sprites.name, image_names, options[:skip_overrides])
|
contents = sprites.content_for_images(options[:skip_overrides])
|
||||||
if options[:output_file][-4..-1] != "scss"
|
if options[:output_file][-4..-1] != "scss"
|
||||||
contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass
|
contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.discover_sprites(uri)
|
def self.discover_sprites(uri)
|
||||||
self.load_map(uri, options).files
|
self.load_map(uri, {}).files
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sprite_name(file)
|
def self.sprite_name(file)
|
||||||
|
@ -37,13 +37,19 @@ describe Compass::Commands::Sprite do
|
|||||||
end
|
end
|
||||||
after :each do
|
after :each do
|
||||||
clean_up_sprites
|
clean_up_sprites
|
||||||
FileUtils.rm_r @test_dir if File.exists?(@test_dir)
|
if File.exists?(@test_dir)
|
||||||
|
::FileUtils.rm_r @test_dir
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create sprite file" do
|
it "should create sprite file" do
|
||||||
puts run_compass_with_options(['sprite', "-f", "stylesheet.scss", "'#{@images_tmp_path}/*.png'"]).inspect
|
run_compass_with_options(['sprite', "-f", "stylesheet.scss", "'#{@images_tmp_path}/*.png'"]).to_i.should == 0
|
||||||
File.exists?(File.join(test_dir, 'stylesheet.scss')).should be_true
|
File.exists?(File.join(test_dir, 'stylesheet.scss')).should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should fail gracfuly when giving bad arguments" do
|
||||||
|
pending
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
@ -16,8 +16,22 @@ module CompassGlobalInclude
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module CompassSpriteHelpers
|
||||||
|
def create_sprite_temp
|
||||||
|
::FileUtils.cp_r @images_src_path, @images_tmp_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_up_sprites
|
||||||
|
::FileUtils.rm_r @images_tmp_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include(CompassGlobalInclude)
|
config.include(CompassGlobalInclude)
|
||||||
|
config.include(CompassSpriteHelpers)
|
||||||
|
config.before :each do
|
||||||
|
@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')
|
||||||
|
end
|
||||||
config.mock_with :mocha
|
config.mock_with :mocha
|
||||||
end
|
end
|
@ -4,16 +4,14 @@ require 'digest/md5'
|
|||||||
describe Compass::Sprites do
|
describe Compass::Sprites do
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
@images_src_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images')
|
create_sprite_temp
|
||||||
@images_tmp_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images-tmp')
|
|
||||||
::FileUtils.cp_r @images_src_path, @images_tmp_path
|
|
||||||
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
|
||||||
Compass.add_configuration(file, "sprite_config")
|
Compass.add_configuration(file, "sprite_config")
|
||||||
Compass.configure_sass_plugin!
|
Compass.configure_sass_plugin!
|
||||||
end
|
end
|
||||||
|
|
||||||
after :each do
|
after :each do
|
||||||
FileUtils.rm_r @images_tmp_path
|
clean_up_sprites
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_location(file)
|
def map_location(file)
|
||||||
@ -75,7 +73,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-161c60ad78.png') no-repeat;
|
background: url('/images/squares-161c60ad78.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -98,7 +96,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-161c60ad78.png') no-repeat;
|
background: url('/images/squares-161c60ad78.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -130,7 +128,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .cubicle, .large-cube {
|
.squares-sprite, .cubicle, .large-cube {
|
||||||
background: url('/squares-161c60ad78.png') no-repeat;
|
background: url('/images/squares-161c60ad78.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cubicle {
|
.cubicle {
|
||||||
@ -155,7 +153,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.circles {
|
.circles {
|
||||||
background: url('/squares-161c60ad78.png') no-repeat;
|
background: url('/images/squares-161c60ad78.png') no-repeat;
|
||||||
}
|
}
|
||||||
CSS
|
CSS
|
||||||
image_size('squares-*.png').should == [20, 30]
|
image_size('squares-*.png').should == [20, 30]
|
||||||
@ -169,7 +167,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-89450808af.png') no-repeat;
|
background: url('/images/squares-89450808af.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -191,7 +189,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-673837183a.png') no-repeat;
|
background: url('/images/squares-673837183a.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -214,7 +212,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-1cd84c9068.png') no-repeat;
|
background: url('/images/squares-1cd84c9068.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -237,7 +235,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-f25b7090ca.png') no-repeat;
|
background: url('/images/squares-f25b7090ca.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -259,7 +257,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-d66bf24bab.png') no-repeat;
|
background: url('/images/squares-d66bf24bab.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -294,7 +292,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite {
|
.squares-sprite {
|
||||||
background: url('/squares-8e490168dd.png') no-repeat;
|
background: url('/images/squares-8e490168dd.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-percentage {
|
.adjusted-percentage {
|
||||||
@ -332,7 +330,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .adjusted-percentage, .adjusted-px-1, .adjusted-px-2 {
|
.squares-sprite, .adjusted-percentage, .adjusted-px-1, .adjusted-px-2 {
|
||||||
background: url('/squares-8e490168dd.png') no-repeat;
|
background: url('/images/squares-8e490168dd.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adjusted-percentage {
|
.adjusted-percentage {
|
||||||
@ -359,7 +357,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-a5550fd132.png') no-repeat;
|
background: url('/images/squares-a5550fd132.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -383,7 +381,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
|
||||||
background: url('/squares-89a274044e.png') no-repeat;
|
background: url('/images/squares-89a274044e.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.squares-ten-by-ten {
|
.squares-ten-by-ten {
|
||||||
@ -435,7 +433,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
actual_css.should == <<-CSS
|
actual_css.should == <<-CSS
|
||||||
.squares {
|
.squares {
|
||||||
background: url('/squares-145869726f.png') 0 -10px no-repeat;
|
background: url('/images/squares-145869726f.png') 0 -10px no-repeat;
|
||||||
}
|
}
|
||||||
CSS
|
CSS
|
||||||
end
|
end
|
||||||
@ -454,7 +452,7 @@ describe Compass::Sprites do
|
|||||||
image_size('squares-*.png').should == [20, 40]
|
image_size('squares-*.png').should == [20, 40]
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.squares-sprite {
|
.squares-sprite {
|
||||||
background: url('/squares-e3c68372d9.png') no-repeat;
|
background: url('/images/squares-e3c68372d9.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.foo {
|
.foo {
|
||||||
@ -474,7 +472,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.selectors-sprite, .selectors-ten-by-ten {
|
.selectors-sprite, .selectors-ten-by-ten {
|
||||||
background: url('/selectors-edfef809e2.png') no-repeat;
|
background: url('/images/selectors-edfef809e2.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
.selectors-ten-by-ten {
|
.selectors-ten-by-ten {
|
||||||
@ -501,7 +499,7 @@ describe Compass::Sprites do
|
|||||||
SCSS
|
SCSS
|
||||||
css.should == <<-CSS
|
css.should == <<-CSS
|
||||||
.selectors-sprite, a {
|
.selectors-sprite, a {
|
||||||
background: url('/selectors-edfef809e2.png') no-repeat;
|
background: url('/images/selectors-edfef809e2.png') no-repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
Loading…
Reference in New Issue
Block a user