updated importer to validate that sprites are png files
This commit is contained in:
parent
7ff9ff15d0
commit
ab5d6e51d9
@ -3,6 +3,7 @@ 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)
|
||||
klass = Compass::SpriteImporter.new
|
||||
@ -89,6 +90,14 @@ 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)
|
||||
@ -96,6 +105,7 @@ module Compass
|
||||
|
||||
# Returns a Sass::Engine for this sprite object
|
||||
def sass_engine
|
||||
validate_sprites!
|
||||
Sass::Engine.new(content_for_images, sass_options)
|
||||
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 |
@ -46,4 +46,21 @@ class ImporterTest < Test::Unit::TestCase
|
||||
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