added error messages to help lemonade users
This commit is contained in:
parent
47cec8151c
commit
109687c7d0
@ -8,7 +8,7 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
last_spacing = 0
|
last_spacing = 0
|
||||||
width = 0
|
width = 0
|
||||||
height = 0
|
height = 0
|
||||||
images = Compass::Sprites.sprites(name)
|
images = Compass::Sprites.sprites(path, name)
|
||||||
|
|
||||||
# Calculation
|
# Calculation
|
||||||
images.each do |image|
|
images.each do |image|
|
||||||
@ -50,7 +50,8 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
sprite_url(uri)
|
sprite_url(uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sprite_image(uri, x_shift = SASS_NULL, y_shift = SASS_NULL)
|
def sprite_image(uri, x_shift = SASS_NULL, y_shift = SASS_NULL, depricated_1 = nil, depricated_2 = nil)
|
||||||
|
check_spacing_deprecation uri, depricated_1, depricated_2
|
||||||
url = sprite_url(uri)
|
url = sprite_url(uri)
|
||||||
position = sprite_position(uri, x_shift, y_shift)
|
position = sprite_position(uri, x_shift, y_shift)
|
||||||
Sass::Script::String.new("#{url} #{position}")
|
Sass::Script::String.new("#{url} #{position}")
|
||||||
@ -61,10 +62,11 @@ module Compass::SassExtensions::Functions::Sprites
|
|||||||
image_url(Sass::Script::String.new("#{path}.png"))
|
image_url(Sass::Script::String.new("#{path}.png"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def sprite_position(uri, x_shift = SASS_NULL, y_shift = SASS_NULL)
|
def sprite_position(uri, x_shift = SASS_NULL, y_shift = SASS_NULL, depricated_1 = nil, depricated_2 = nil)
|
||||||
name = File.dirname(uri.value)
|
check_spacing_deprecation uri, depricated_1, depricated_2
|
||||||
|
path, name = Compass::Sprites.path_and_name(uri.value)
|
||||||
image_name = File.basename(uri.value, '.png')
|
image_name = File.basename(uri.value, '.png')
|
||||||
image = Compass::Sprites.sprites(name).detect{ |image| image[:name] == image_name }
|
image = Compass::Sprites.sprites(path, name).detect{ |image| image[:name] == image_name }
|
||||||
if x_shift.unit_str == "%"
|
if x_shift.unit_str == "%"
|
||||||
x = x_shift.to_s
|
x = x_shift.to_s
|
||||||
else
|
else
|
||||||
@ -85,4 +87,14 @@ private
|
|||||||
0
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_spacing_deprecation(uri, spacing_before, spacing_after)
|
||||||
|
if spacing_before or spacing_after
|
||||||
|
path, name, image_name = Compass::Sprites.path_and_name(uri.value)
|
||||||
|
message = %Q(Spacing parameter is deprecated. ) +
|
||||||
|
%Q(Please add `$#{name}-#{image_name}-spacing: #{spacing_before};` ) +
|
||||||
|
%Q(before the `@import "#{path}/*.png";` statement.)
|
||||||
|
raise Compass::Error, message
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module Compass
|
module Compass
|
||||||
class Sprites < Sass::Importers::Base
|
class Sprites < Sass::Importers::Base
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
attr_accessor :path
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def reset
|
def reset
|
||||||
@ -13,19 +14,27 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sprites(name)
|
def sprites(path, name, create = false)
|
||||||
@@sprites = {} if @@sprites.nil?
|
@@sprites = {} if @@sprites.nil?
|
||||||
@@sprites[name] ||= []
|
index = "#{path}/#{name}"
|
||||||
|
images = @@sprites[index]
|
||||||
|
if images
|
||||||
|
images
|
||||||
|
elsif create
|
||||||
|
images = @@sprites[index] = []
|
||||||
|
else
|
||||||
|
raise Compass::Error, %Q(`@import` statement missing. Please add `@import "#{path}/*.png";`.)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def images
|
def images
|
||||||
Compass::Sprites.sprites(self.name)
|
Compass::Sprites.sprites(self.path, self.name, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(uri, options)
|
def find(uri, options)
|
||||||
if uri =~ /\.png$/
|
if uri =~ /\.png$/
|
||||||
path, self.name = Compass::Sprites.path_and_name(uri)
|
self.path, self.name = Compass::Sprites.path_and_name(uri)
|
||||||
glob = File.join(Compass.configuration.images_path, uri)
|
glob = File.join(Compass.configuration.images_path, uri)
|
||||||
Dir.glob(glob).sort.each do |file|
|
Dir.glob(glob).sort.each do |file|
|
||||||
width, height = Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size
|
width, height = Compass::SassExtensions::Functions::ImageSize::ImageProperties.new(file).size
|
||||||
|
@ -396,4 +396,38 @@ describe Compass::Sprites do
|
|||||||
CSS
|
CSS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should raise deprication errors for lemonade's spacing syntax" do
|
||||||
|
proc do
|
||||||
|
render <<-SCSS
|
||||||
|
@import "squares/*.png";
|
||||||
|
|
||||||
|
.squares {
|
||||||
|
background: sprite-image("squares/20x20.png", 0, 0, 11px) no-repeat;
|
||||||
|
}
|
||||||
|
SCSS
|
||||||
|
end.should raise_error Compass::Error,
|
||||||
|
%q(Spacing parameter is deprecated. Please add `$squares-20x20-spacing: 11px;` before the `@import "squares/*.png";` statement.)
|
||||||
|
proc do
|
||||||
|
render <<-SCSS
|
||||||
|
@import "squares/*.png";
|
||||||
|
|
||||||
|
.squares {
|
||||||
|
background: sprite-position("squares/20x20.png", 0, 0, 11px) no-repeat;
|
||||||
|
}
|
||||||
|
SCSS
|
||||||
|
end.should raise_error Compass::Error,
|
||||||
|
%q(Spacing parameter is deprecated. Please add `$squares-20x20-spacing: 11px;` before the `@import "squares/*.png";` statement.)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should raise an error if @import is missing" do
|
||||||
|
proc do
|
||||||
|
render <<-SCSS
|
||||||
|
.squares {
|
||||||
|
background: sprite-image("squares/20x20.png") no-repeat;
|
||||||
|
}
|
||||||
|
SCSS
|
||||||
|
end.should raise_error Compass::Error,
|
||||||
|
%q(`@import` statement missing. Please add `@import "squares/*.png";`.)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user