A better error message if a color stop list is not passed in.
This commit is contained in:
parent
2baaffd013
commit
76c75b1d3d
@ -54,6 +54,7 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
|
|
||||||
# returns color-stop() calls for use in webkit.
|
# returns color-stop() calls for use in webkit.
|
||||||
def grad_color_stops(color_list)
|
def grad_color_stops(color_list)
|
||||||
|
assert_list(color_list)
|
||||||
normalize_stops!(color_list)
|
normalize_stops!(color_list)
|
||||||
max = color_list.values.last.stop
|
max = color_list.values.last.stop
|
||||||
color_stops = color_list.values.map do |pos|
|
color_stops = color_list.values.map do |pos|
|
||||||
@ -67,11 +68,13 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
|
|
||||||
# returns the end position of the gradient from the color stop
|
# returns the end position of the gradient from the color stop
|
||||||
def grad_end_position(color_list, radial = Sass::Script::Bool.new(false))
|
def grad_end_position(color_list, radial = Sass::Script::Bool.new(false))
|
||||||
|
assert_list(color_list)
|
||||||
default = Sass::Script::Number.new(100)
|
default = Sass::Script::Number.new(100)
|
||||||
grad_position(color_list, Sass::Script::Number.new(color_list.values.size), default, radial)
|
grad_position(color_list, Sass::Script::Number.new(color_list.values.size), default, radial)
|
||||||
end
|
end
|
||||||
|
|
||||||
def grad_position(color_list, index, default, radial = Sass::Script::Bool.new(false))
|
def grad_position(color_list, index, default, radial = Sass::Script::Bool.new(false))
|
||||||
|
assert_list(color_list)
|
||||||
stop = color_list.values[index.value - 1].stop
|
stop = color_list.values[index.value - 1].stop
|
||||||
if stop && radial.to_bool
|
if stop && radial.to_bool
|
||||||
orig_stop = stop
|
orig_stop = stop
|
||||||
@ -129,22 +132,24 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
when Sass::Script::Color
|
when Sass::Script::Color
|
||||||
ColorStop.new(arg)
|
ColorStop.new(arg)
|
||||||
when Sass::Script::String
|
when Sass::Script::String
|
||||||
|
# We get a string as the result of concatenation
|
||||||
|
# So we have to reparse the expression
|
||||||
color = stop = nil
|
color = stop = nil
|
||||||
expr = Sass::Script::Parser.parse(arg.value, 0, 0)
|
expr = Sass::Script::Parser.parse(arg.value, 0, 0)
|
||||||
case expr
|
case expr
|
||||||
when Sass::Script::Color
|
when Sass::Script::Color
|
||||||
color = expr
|
color = expr
|
||||||
|
when Sass::Script::Funcall
|
||||||
|
color = expr
|
||||||
when Sass::Script::Operation
|
when Sass::Script::Operation
|
||||||
unless expr.instance_variable_get("@operator") == :concat
|
unless expr.instance_variable_get("@operator") == :concat
|
||||||
|
# This should never happen.
|
||||||
raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
|
raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
|
||||||
end
|
end
|
||||||
color = expr.instance_variable_get("@operand1")
|
color = expr.instance_variable_get("@operand1")
|
||||||
stop = expr.instance_variable_get("@operand2")
|
stop = expr.instance_variable_get("@operand2")
|
||||||
when Sass::Script::Funcall
|
|
||||||
color = expr
|
|
||||||
else
|
else
|
||||||
puts expr.class.name
|
raise Sass::SyntaxError, "Couldn't parse a color stop from: #{arg.value}"
|
||||||
raise Sass::SyntaxError, "Couldn't parse a color stop from:: #{arg.value}"
|
|
||||||
end
|
end
|
||||||
ColorStop.new(color, stop)
|
ColorStop.new(color, stop)
|
||||||
else
|
else
|
||||||
@ -182,5 +187,9 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
def assert_list(value)
|
||||||
|
return if value.is_a?(List)
|
||||||
|
raise ArgumentError.new("#{value.inspect} is not a list of color stops. Expected: color_stops(<color> <number>?, ...)")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user