Merge branch 'master' of github.com:chriseppstein/compass into better_sprite_packing
Conflicts: Gemfile.lock
This commit is contained in:
commit
ba2b608f73
@ -1,4 +1,7 @@
|
|||||||
rvm:
|
rvm:
|
||||||
|
- 1.8.7
|
||||||
- 1.9.2
|
- 1.9.2
|
||||||
- jruby
|
- jruby
|
||||||
|
- rbx
|
||||||
- ree
|
- ree
|
||||||
|
script: "bundle exec rake test"
|
||||||
|
78
Gemfile.lock
78
Gemfile.lock
@ -1,13 +1,13 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: git://github.com/johnbintz/fakefs.git
|
remote: git://github.com/johnbintz/fakefs.git
|
||||||
revision: 005ddaaeb2b2881391c31ac9846a55ce5a42c206
|
revision: 7363b6f13bfcd9f583bbf7cd1e0d65c2dc656db7
|
||||||
specs:
|
specs:
|
||||||
fakefs (0.3.1)
|
fakefs (0.3.1)
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
compass (0.11.1.cc26b98)
|
compass (0.11.1.387bf36)
|
||||||
chunky_png (~> 1.1)
|
chunky_png (~> 1.1)
|
||||||
fssm (>= 0.2.7)
|
fssm (>= 0.2.7)
|
||||||
sass (~> 3.1)
|
sass (~> 3.1)
|
||||||
@ -17,12 +17,12 @@ GEM
|
|||||||
specs:
|
specs:
|
||||||
ZenTest (4.5.0)
|
ZenTest (4.5.0)
|
||||||
abstract (1.0.0)
|
abstract (1.0.0)
|
||||||
actionmailer (3.0.7)
|
actionmailer (3.0.9.rc3)
|
||||||
actionpack (= 3.0.7)
|
actionpack (= 3.0.9.rc3)
|
||||||
mail (~> 2.2.15)
|
mail (~> 2.2.19)
|
||||||
actionpack (3.0.7)
|
actionpack (3.0.9.rc3)
|
||||||
activemodel (= 3.0.7)
|
activemodel (= 3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
builder (~> 2.1.2)
|
builder (~> 2.1.2)
|
||||||
erubis (~> 2.6.6)
|
erubis (~> 2.6.6)
|
||||||
i18n (~> 0.5.0)
|
i18n (~> 0.5.0)
|
||||||
@ -30,21 +30,21 @@ GEM
|
|||||||
rack-mount (~> 0.6.14)
|
rack-mount (~> 0.6.14)
|
||||||
rack-test (~> 0.5.7)
|
rack-test (~> 0.5.7)
|
||||||
tzinfo (~> 0.3.23)
|
tzinfo (~> 0.3.23)
|
||||||
activemodel (3.0.7)
|
activemodel (3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
builder (~> 2.1.2)
|
builder (~> 2.1.2)
|
||||||
i18n (~> 0.5.0)
|
i18n (~> 0.5.0)
|
||||||
activerecord (3.0.7)
|
activerecord (3.0.9.rc3)
|
||||||
activemodel (= 3.0.7)
|
activemodel (= 3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
arel (~> 2.0.2)
|
arel (~> 2.0.10)
|
||||||
tzinfo (~> 0.3.23)
|
tzinfo (~> 0.3.23)
|
||||||
activeresource (3.0.7)
|
activeresource (3.0.9.rc3)
|
||||||
activemodel (= 3.0.7)
|
activemodel (= 3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
activesupport (3.0.7)
|
activesupport (3.0.9.rc3)
|
||||||
addressable (2.2.5)
|
addressable (2.2.6)
|
||||||
arel (2.0.9)
|
arel (2.0.10)
|
||||||
autotest (4.4.6)
|
autotest (4.4.6)
|
||||||
ZenTest (>= 4.4.1)
|
ZenTest (>= 4.4.1)
|
||||||
autotest-fsevent (0.2.5)
|
autotest-fsevent (0.2.5)
|
||||||
@ -61,7 +61,7 @@ GEM
|
|||||||
term-ansicolor (~> 1.0.5)
|
term-ansicolor (~> 1.0.5)
|
||||||
diff-lcs (1.1.2)
|
diff-lcs (1.1.2)
|
||||||
em-dir-watcher (0.9.4)
|
em-dir-watcher (0.9.4)
|
||||||
em-websocket (0.2.1)
|
em-websocket (0.3.0)
|
||||||
addressable (>= 2.1.1)
|
addressable (>= 2.1.1)
|
||||||
eventmachine (>= 0.12.9)
|
eventmachine (>= 0.12.9)
|
||||||
erubis (2.6.6)
|
erubis (2.6.6)
|
||||||
@ -71,14 +71,14 @@ GEM
|
|||||||
gherkin (2.2.9)
|
gherkin (2.2.9)
|
||||||
json (~> 1.4.6)
|
json (~> 1.4.6)
|
||||||
term-ansicolor (~> 1.0.5)
|
term-ansicolor (~> 1.0.5)
|
||||||
haml (3.1.1)
|
haml (3.1.2)
|
||||||
i18n (0.5.0)
|
i18n (0.5.0)
|
||||||
json (1.4.6)
|
json (1.4.6)
|
||||||
livereload (1.6)
|
livereload (1.6)
|
||||||
em-dir-watcher (>= 0.1)
|
em-dir-watcher (>= 0.1)
|
||||||
em-websocket (>= 0.1.2)
|
em-websocket (>= 0.1.2)
|
||||||
ruby-json (>= 1.1.2)
|
ruby-json (>= 1.1.2)
|
||||||
mail (2.2.17)
|
mail (2.2.19)
|
||||||
activesupport (>= 2.3.6)
|
activesupport (>= 2.3.6)
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
@ -86,27 +86,29 @@ GEM
|
|||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
mocha (0.9.12)
|
mocha (0.9.12)
|
||||||
polyglot (0.3.1)
|
polyglot (0.3.1)
|
||||||
rack (1.2.2)
|
rack (1.2.3)
|
||||||
rack-mount (0.6.14)
|
rack-mount (0.6.14)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
rack-test (0.5.7)
|
rack-test (0.5.7)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rails (3.0.7)
|
rails (3.0.9.rc3)
|
||||||
actionmailer (= 3.0.7)
|
actionmailer (= 3.0.9.rc3)
|
||||||
actionpack (= 3.0.7)
|
actionpack (= 3.0.9.rc3)
|
||||||
activerecord (= 3.0.7)
|
activerecord (= 3.0.9.rc3)
|
||||||
activeresource (= 3.0.7)
|
activeresource (= 3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
bundler (~> 1.0)
|
bundler (~> 1.0)
|
||||||
railties (= 3.0.7)
|
railties (= 3.0.9.rc3)
|
||||||
railties (3.0.7)
|
railties (3.0.9.rc3)
|
||||||
actionpack (= 3.0.7)
|
actionpack (= 3.0.9.rc3)
|
||||||
activesupport (= 3.0.7)
|
activesupport (= 3.0.9.rc3)
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
|
rdoc (~> 3.4)
|
||||||
thor (~> 0.14.4)
|
thor (~> 0.14.4)
|
||||||
rake (0.8.7)
|
rake (0.9.2)
|
||||||
rb-fsevent (0.4.0)
|
rb-fsevent (0.4.0)
|
||||||
rcov (0.9.9)
|
rcov (0.9.9)
|
||||||
|
rdoc (3.6.1)
|
||||||
rspec (2.0.1)
|
rspec (2.0.1)
|
||||||
rspec-core (~> 2.0.1)
|
rspec-core (~> 2.0.1)
|
||||||
rspec-expectations (~> 2.0.1)
|
rspec-expectations (~> 2.0.1)
|
||||||
@ -118,16 +120,16 @@ GEM
|
|||||||
rspec-core (~> 2.0.1)
|
rspec-core (~> 2.0.1)
|
||||||
rspec-expectations (~> 2.0.1)
|
rspec-expectations (~> 2.0.1)
|
||||||
ruby-json (1.1.2)
|
ruby-json (1.1.2)
|
||||||
ruby-prof (0.10.5)
|
ruby-prof (0.10.7)
|
||||||
rubyzip (0.9.4)
|
rubyzip (0.9.4)
|
||||||
sass (3.1.1)
|
sass (3.1.2)
|
||||||
sys-uname (0.8.5)
|
sys-uname (0.8.5)
|
||||||
term-ansicolor (1.0.5)
|
term-ansicolor (1.0.5)
|
||||||
thor (0.14.6)
|
thor (0.14.6)
|
||||||
timecop (0.3.5)
|
timecop (0.3.5)
|
||||||
treetop (1.4.9)
|
treetop (1.4.9)
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
tzinfo (0.3.26)
|
tzinfo (0.3.27)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
@charset "utf-8";
|
||||||
@import "typography";
|
@import "typography";
|
||||||
|
|
||||||
$alternate-text-font : "Warnock Pro", "Goudy Old Style", "Palatino", "Book Antiqua", Georgia, serif !default;
|
$alternate-text-font : "Warnock Pro", "Goudy Old Style", "Palatino", "Book Antiqua", Georgia, serif !default;
|
||||||
|
@ -12,7 +12,10 @@
|
|||||||
//
|
//
|
||||||
// If you need to generate other formats check out the Font Squirrel
|
// If you need to generate other formats check out the Font Squirrel
|
||||||
// [font generator](http://www.fontsquirrel.com/fontface/generator)
|
// [font generator](http://www.fontsquirrel.com/fontface/generator)
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// +font-face("this name", font-files("this.woff", "woff", "this.otf", "opentype"), "this.eot")
|
||||||
@mixin font-face(
|
@mixin font-face(
|
||||||
$name,
|
$name,
|
||||||
$font-files,
|
$font-files,
|
||||||
@ -28,16 +31,3 @@
|
|||||||
src: $font-files;
|
src: $font-files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXAMPLE
|
|
||||||
// +font-face("this name", font-files("this.woff", "woff", "this.otf", "opentype"), "this.eot")
|
|
||||||
//
|
|
||||||
// will generate:
|
|
||||||
//
|
|
||||||
// @font-face {
|
|
||||||
// font-family: 'this name';
|
|
||||||
// src: url('fonts/this.eot');
|
|
||||||
// src: local("☺"),
|
|
||||||
// url('fonts/this.otf') format('woff'),
|
|
||||||
// url('fonts/this.woff') format('opentype');
|
|
||||||
// }
|
|
||||||
|
@ -3,13 +3,12 @@ module Compass
|
|||||||
attr_accessor :uri, :options
|
attr_accessor :uri, :options
|
||||||
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
|
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
|
||||||
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
||||||
|
VALID_EXTENSIONS = ['.png']
|
||||||
|
|
||||||
def self.load(uri, options)
|
def self.load(uri, options)
|
||||||
Compass.quick_cache "Sprite_map:#{uri}#{options.inspect}", 5 do
|
klass = Compass::SpriteImporter.new
|
||||||
klass = Compass::SpriteImporter.new
|
klass.uri, klass.options = uri, options
|
||||||
klass.uri, klass.options = uri, options
|
klass
|
||||||
klass
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(options ={})
|
def initialize(options ={})
|
||||||
@ -43,7 +42,12 @@ module Compass
|
|||||||
other.class == self.class
|
other.class == self.class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mtime(uri, options)
|
||||||
|
@uri, @options = uri, options
|
||||||
|
files.sort.inject(Time.at(0)) do |max_time, file|
|
||||||
|
(t = File.mtime(file)) > max_time ? t : max_time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def key(uri, options={})
|
def key(uri, options={})
|
||||||
@uri, @options = uri, options
|
@uri, @options = uri, options
|
||||||
@ -51,12 +55,10 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.path_and_name(uri)
|
def self.path_and_name(uri)
|
||||||
Compass.quick_cache "Sprite_map_name:#{uri}", 5 do
|
if uri =~ SPRITE_IMPORTER_REGEX
|
||||||
if uri =~ SPRITE_IMPORTER_REGEX
|
[$1, $3]
|
||||||
[$1, $3]
|
else
|
||||||
else
|
raise Compass::Error "invalid sprite path"
|
||||||
[nil, nil]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -74,12 +76,12 @@ module Compass
|
|||||||
|
|
||||||
# Returns the Glob of image files for this sprite
|
# Returns the Glob of image files for this sprite
|
||||||
def files
|
def files
|
||||||
@files ||= Dir[File.join(Compass.configuration.images_path, uri)].sort
|
Dir[File.join(Compass.configuration.images_path, uri)].sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an Array of image names without the file extension
|
# Returns an Array of image names without the file extension
|
||||||
def sprite_names
|
def sprite_names
|
||||||
@sprite_names ||= files.collect do |file|
|
files.collect do |file|
|
||||||
filename = File.basename(file, '.png')
|
filename = File.basename(file, '.png')
|
||||||
unless VAILD_FILE_NAME =~ filename
|
unless VAILD_FILE_NAME =~ filename
|
||||||
raise Compass::Error, "Sprite file names must be legal css identifiers. Please rename #{File.basename(file)}"
|
raise Compass::Error, "Sprite file names must be legal css identifiers. Please rename #{File.basename(file)}"
|
||||||
@ -88,13 +90,22 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_sprites!
|
||||||
|
files.each do |file|
|
||||||
|
unless VALID_EXTENSIONS.include? File.extname(file)
|
||||||
|
raise Compass::Error, "Invalid sprite extension only: #{VALID_EXTENSIONS.join(',')} images are allowed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the sass options for this sprite
|
# Returns the sass options for this sprite
|
||||||
def sass_options
|
def sass_options
|
||||||
@sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self)
|
options.merge(:filename => name, :syntax => :scss, :importer => self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a Sass::Engine for this sprite object
|
# Returns a Sass::Engine for this sprite object
|
||||||
def sass_engine
|
def sass_engine
|
||||||
|
validate_sprites!
|
||||||
Sass::Engine.new(content_for_images, sass_options)
|
Sass::Engine.new(content_for_images, sass_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
BIN
test/fixtures/sprites/public/images/bad_extensions/ten-by-ten.gif
vendored
Normal file
BIN
test/fixtures/sprites/public/images/bad_extensions/ten-by-ten.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
test/fixtures/sprites/public/images/bad_extensions/twenty-by-twenty.jpg
vendored
Normal file
BIN
test/fixtures/sprites/public/images/bad_extensions/twenty-by-twenty.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
@ -57,7 +57,7 @@ class CompassTest < Test::Unit::TestCase
|
|||||||
assert_no_errors css_file, :blueprint
|
assert_no_errors css_file, :blueprint
|
||||||
end
|
end
|
||||||
each_sass_file do |sass_file|
|
each_sass_file do |sass_file|
|
||||||
assert_renders_correctly sass_file
|
assert_renders_correctly sass_file, :ignore_charset => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
66
test/units/sprites/importer_test.rb
Normal file
66
test/units/sprites/importer_test.rb
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
require 'timecop'
|
||||||
|
class ImporterTest < Test::Unit::TestCase
|
||||||
|
URI = "selectors/*.png"
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images')
|
||||||
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
||||||
|
Compass.add_configuration(file, "sprite_config")
|
||||||
|
@importer = Compass::SpriteImporter.new(:uri => URI, :options => options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def options
|
||||||
|
{:foo => 'bar'}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "load should return an instance of SpriteImporter" do
|
||||||
|
assert Compass::SpriteImporter.load(URI, options).is_a?(Compass::SpriteImporter)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "name should return the sprite name" do
|
||||||
|
assert_equal 'selectors', @importer.name
|
||||||
|
end
|
||||||
|
|
||||||
|
test "path should return the sprite path" do
|
||||||
|
assert_equal 'selectors', @importer.path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return all the sprite names" do
|
||||||
|
assert_equal ["ten-by-ten", "ten-by-ten_active", "ten-by-ten_hover", "ten-by-ten_target"], @importer.sprite_names
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should have correct mtime" do
|
||||||
|
thirtydays = Time.now.to_i + (60*60*24*30)
|
||||||
|
file = Dir[File.join(@images_src_path, URI)].sort.first
|
||||||
|
File.utime(thirtydays, thirtydays, file)
|
||||||
|
assert_equal thirtydays, File.mtime(file).to_i
|
||||||
|
assert_equal thirtydays, @importer.mtime(URI, {}).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should return sass engine on find" do
|
||||||
|
assert @importer.find(URI, {}).is_a?(Sass::Engine)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sass options should contain options" do
|
||||||
|
assert_equal 'bar', @importer.sass_options[:foo]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should fail givin bad sprite extensions" do
|
||||||
|
@images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images')
|
||||||
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
||||||
|
Compass.add_configuration(file, "sprite_config")
|
||||||
|
importer = Compass::SpriteImporter.new(:uri => 'bad_extensions/*.jpg', :options => options)
|
||||||
|
begin
|
||||||
|
importer.sass_engine
|
||||||
|
assert false, "Somthing happened an invalid sprite file made it past validation"
|
||||||
|
rescue Compass::Error => e
|
||||||
|
assert e.message.include?('.png')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def taredown
|
||||||
|
Compass.reset_configuration!
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user