Merge branch 'master' of github.com:chriseppstein/compass into better_sprite_packing

Conflicts:
	Gemfile.lock
This commit is contained in:
Scott Davis 2011-06-09 21:56:45 -04:00
commit ba2b608f73
9 changed files with 141 additions and 68 deletions

View File

@ -1,4 +1,7 @@
rvm:
- 1.8.7
- 1.9.2
- jruby
- rbx
- ree
script: "bundle exec rake test"

View File

@ -1,13 +1,13 @@
GIT
remote: git://github.com/johnbintz/fakefs.git
revision: 005ddaaeb2b2881391c31ac9846a55ce5a42c206
revision: 7363b6f13bfcd9f583bbf7cd1e0d65c2dc656db7
specs:
fakefs (0.3.1)
PATH
remote: .
specs:
compass (0.11.1.cc26b98)
compass (0.11.1.387bf36)
chunky_png (~> 1.1)
fssm (>= 0.2.7)
sass (~> 3.1)
@ -17,12 +17,12 @@ GEM
specs:
ZenTest (4.5.0)
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (= 3.0.7)
mail (~> 2.2.15)
actionpack (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
actionmailer (3.0.9.rc3)
actionpack (= 3.0.9.rc3)
mail (~> 2.2.19)
actionpack (3.0.9.rc3)
activemodel (= 3.0.9.rc3)
activesupport (= 3.0.9.rc3)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
@ -30,21 +30,21 @@ GEM
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.7)
activesupport (= 3.0.7)
activemodel (3.0.9.rc3)
activesupport (= 3.0.9.rc3)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
arel (~> 2.0.2)
activerecord (3.0.9.rc3)
activemodel (= 3.0.9.rc3)
activesupport (= 3.0.9.rc3)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activeresource (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
addressable (2.2.5)
arel (2.0.9)
activeresource (3.0.9.rc3)
activemodel (= 3.0.9.rc3)
activesupport (= 3.0.9.rc3)
activesupport (3.0.9.rc3)
addressable (2.2.6)
arel (2.0.10)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-fsevent (0.2.5)
@ -61,7 +61,7 @@ GEM
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
em-dir-watcher (0.9.4)
em-websocket (0.2.1)
em-websocket (0.3.0)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
erubis (2.6.6)
@ -71,14 +71,14 @@ GEM
gherkin (2.2.9)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
haml (3.1.1)
haml (3.1.2)
i18n (0.5.0)
json (1.4.6)
livereload (1.6)
em-dir-watcher (>= 0.1)
em-websocket (>= 0.1.2)
ruby-json (>= 1.1.2)
mail (2.2.17)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@ -86,27 +86,29 @@ GEM
mime-types (1.16)
mocha (0.9.12)
polyglot (0.3.1)
rack (1.2.2)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.7)
actionmailer (= 3.0.7)
actionpack (= 3.0.7)
activerecord (= 3.0.7)
activeresource (= 3.0.7)
activesupport (= 3.0.7)
rails (3.0.9.rc3)
actionmailer (= 3.0.9.rc3)
actionpack (= 3.0.9.rc3)
activerecord (= 3.0.9.rc3)
activeresource (= 3.0.9.rc3)
activesupport (= 3.0.9.rc3)
bundler (~> 1.0)
railties (= 3.0.7)
railties (3.0.7)
actionpack (= 3.0.7)
activesupport (= 3.0.7)
railties (= 3.0.9.rc3)
railties (3.0.9.rc3)
actionpack (= 3.0.9.rc3)
activesupport (= 3.0.9.rc3)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.4)
rake (0.8.7)
rake (0.9.2)
rb-fsevent (0.4.0)
rcov (0.9.9)
rdoc (3.6.1)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
@ -118,16 +120,16 @@ GEM
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
ruby-json (1.1.2)
ruby-prof (0.10.5)
ruby-prof (0.10.7)
rubyzip (0.9.4)
sass (3.1.1)
sass (3.1.2)
sys-uname (0.8.5)
term-ansicolor (1.0.5)
thor (0.14.6)
timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.26)
tzinfo (0.3.27)
PLATFORMS
ruby

View File

@ -1,3 +1,4 @@
@charset "utf-8";
@import "typography";
$alternate-text-font : "Warnock Pro", "Goudy Old Style", "Palatino", "Book Antiqua", Georgia, serif !default;

View File

@ -12,7 +12,10 @@
//
// If you need to generate other formats check out the Font Squirrel
// [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(
$name,
$font-files,
@ -28,16 +31,3 @@
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');
// }

View File

@ -3,14 +3,13 @@ module Compass
attr_accessor :uri, :options
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
VALID_EXTENSIONS = ['.png']
def self.load(uri, options)
Compass.quick_cache "Sprite_map:#{uri}#{options.inspect}", 5 do
klass = Compass::SpriteImporter.new
klass.uri, klass.options = uri, options
klass
end
end
def initialize(options ={})
@uri, @options = '', {}
@ -43,7 +42,12 @@ module Compass
other.class == self.class
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={})
@uri, @options = uri, options
@ -51,12 +55,10 @@ module Compass
end
def self.path_and_name(uri)
Compass.quick_cache "Sprite_map_name:#{uri}", 5 do
if uri =~ SPRITE_IMPORTER_REGEX
[$1, $3]
else
[nil, nil]
end
raise Compass::Error "invalid sprite path"
end
end
@ -74,12 +76,12 @@ module Compass
# Returns the Glob of image files for this sprite
def files
@files ||= Dir[File.join(Compass.configuration.images_path, uri)].sort
Dir[File.join(Compass.configuration.images_path, uri)].sort
end
# Returns an Array of image names without the file extension
def sprite_names
@sprite_names ||= files.collect do |file|
files.collect do |file|
filename = File.basename(file, '.png')
unless VAILD_FILE_NAME =~ filename
raise Compass::Error, "Sprite file names must be legal css identifiers. Please rename #{File.basename(file)}"
@ -88,13 +90,22 @@ module Compass
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
def sass_options
@sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self)
options.merge(:filename => name, :syntax => :scss, :importer => self)
end
# Returns a Sass::Engine for this sprite object
def sass_engine
validate_sprites!
Sass::Engine.new(content_for_images, sass_options)
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -57,7 +57,7 @@ class CompassTest < Test::Unit::TestCase
assert_no_errors css_file, :blueprint
end
each_sass_file do |sass_file|
assert_renders_correctly sass_file
assert_renders_correctly sass_file, :ignore_charset => true
end
end
end

View 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