closes 268 - filenames can not start with numbers the must be legal css identifiers

This commit is contained in:
Scott Davis 2011-03-28 22:39:12 -04:00
parent 7571d4af93
commit 2e8fd055ed
3 changed files with 22 additions and 4 deletions

View File

@ -7,7 +7,7 @@ GIT
PATH PATH
remote: . remote: .
specs: specs:
compass (0.11.beta.4.29656ea) compass (0.11.beta.5.7571d4a)
chunky_png (~> 1.1.0) chunky_png (~> 1.1.0)
sass (>= 3.1.0.alpha.249) sass (>= 3.1.0.alpha.249)

View File

@ -1,7 +1,7 @@
module Compass module Compass
class SpriteMap class SpriteMap
attr_reader :uri, :options attr_reader :uri, :options
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
def find_relative(*args) def find_relative(*args)
nil nil
@ -30,7 +30,13 @@ module Compass
# 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 { |file| File.basename(file, '.png') } @sprite_names ||= 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)}"
end
filename
end
end end
# Returns the sass options for this sprite # Returns the sass options for this sprite

View File

@ -496,7 +496,7 @@ describe Compass::Sprites do
css = render <<-SCSS css = render <<-SCSS
@import "selectors/*.png"; @import "selectors/*.png";
a { a {
@include selectors_sprite(ten-by-ten) @include selectors-sprite(ten-by-ten)
} }
SCSS SCSS
css.should == <<-CSS css.should == <<-CSS
@ -519,4 +519,16 @@ describe Compass::Sprites do
CSS CSS
end end
it "should raise error on filenames that are not valid sass syntax" do
lambda do
render <<-SCSS
$sprite-file-prefix:'foo';
@import "prefix/*.png";
a {
@include squares-sprite(20-by-20)
}
SCSS
end.should raise_error Compass::Error
end
end end