I misread the spec, those are ands, not ors
This commit is contained in:
parent
3e01a9e990
commit
721f1370bc
@ -48,13 +48,13 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
|
|
||||||
class RadialGradient < Sass::Script::Literal
|
class RadialGradient < Sass::Script::Literal
|
||||||
attr_accessor :position_or_angle, :shape_or_size, :color_stops
|
attr_accessor :position_and_angle, :shape_and_size, :color_stops
|
||||||
def initialize(position_or_angle, shape_or_size, color_stops)
|
def initialize(position_and_angle, shape_and_size, color_stops)
|
||||||
unless color_stops.values.size >= 2
|
unless color_stops.values.size >= 2
|
||||||
raise Sass::SyntaxError, "At least two color stops are required for a radial-gradient"
|
raise Sass::SyntaxError, "At least two color stops are required for a radial-gradient"
|
||||||
end
|
end
|
||||||
self.position_or_angle = position_or_angle
|
self.position_and_angle = position_and_angle
|
||||||
self.shape_or_size = shape_or_size
|
self.shape_and_size = shape_and_size
|
||||||
self.color_stops = color_stops
|
self.color_stops = color_stops
|
||||||
end
|
end
|
||||||
def inspect
|
def inspect
|
||||||
@ -62,16 +62,16 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
s = "radial-gradient("
|
s = "radial-gradient("
|
||||||
s << position_or_angle.to_s << ", " if position_or_angle
|
s << position_and_angle.to_s << ", " if position_and_angle
|
||||||
s << shape_or_size.to_s << ", " if shape_or_size
|
s << shape_and_size.to_s << ", " if shape_and_size
|
||||||
s << color_stops.to_s
|
s << color_stops.to_s
|
||||||
s << ")"
|
s << ")"
|
||||||
end
|
end
|
||||||
def to_webkit
|
def to_webkit
|
||||||
args = [
|
args = [
|
||||||
grad_point(position_or_angle || Sass::Script::String.new("center center")),
|
grad_point(position_and_angle || Sass::Script::String.new("center center")),
|
||||||
"0",
|
"0",
|
||||||
grad_point(position_or_angle || Sass::Script::String.new("center center")),
|
grad_point(position_and_angle || Sass::Script::String.new("center center")),
|
||||||
grad_end_position(color_stops, Sass::Script::Bool.new(true)),
|
grad_end_position(color_stops, Sass::Script::Bool.new(true)),
|
||||||
grad_color_stops(color_stops)
|
grad_color_stops(color_stops)
|
||||||
]
|
]
|
||||||
@ -83,17 +83,17 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
def to_svg
|
def to_svg
|
||||||
# XXX Add shape support if possible
|
# XXX Add shape support if possible
|
||||||
radial_svg_gradient(color_stops, position_or_angle || Sass::Script::String.new("center center"))
|
radial_svg_gradient(color_stops, position_and_angle || Sass::Script::String.new("center center"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class LinearGradient < Sass::Script::Literal
|
class LinearGradient < Sass::Script::Literal
|
||||||
attr_accessor :color_stops, :position_or_angle
|
attr_accessor :color_stops, :position_and_angle
|
||||||
def initialize(position_or_angle, color_stops)
|
def initialize(position_and_angle, color_stops)
|
||||||
unless color_stops.values.size >= 2
|
unless color_stops.values.size >= 2
|
||||||
raise Sass::SyntaxError, "At least two color stops are required for a linear-gradient"
|
raise Sass::SyntaxError, "At least two color stops are required for a linear-gradient"
|
||||||
end
|
end
|
||||||
self.position_or_angle = position_or_angle
|
self.position_and_angle = position_and_angle
|
||||||
self.color_stops = color_stops
|
self.color_stops = color_stops
|
||||||
end
|
end
|
||||||
def inspect
|
def inspect
|
||||||
@ -101,14 +101,14 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
s = "linear-gradient("
|
s = "linear-gradient("
|
||||||
s << position_or_angle.to_s << ", " if position_or_angle
|
s << position_and_angle.to_s << ", " if position_and_angle
|
||||||
s << color_stops.to_s
|
s << color_stops.to_s
|
||||||
s << ")"
|
s << ")"
|
||||||
end
|
end
|
||||||
def to_webkit
|
def to_webkit
|
||||||
args = []
|
args = []
|
||||||
args << grad_point(position_or_angle || Sass::Script::String.new("top"))
|
args << grad_point(position_and_angle || Sass::Script::String.new("top"))
|
||||||
args << grad_point(opposite_position(position_or_angle || Sass::Script::String.new("top")))
|
args << grad_point(opposite_position(position_and_angle || Sass::Script::String.new("top")))
|
||||||
args << grad_color_stops(color_stops)
|
args << grad_color_stops(color_stops)
|
||||||
Sass::Script::String.new("-webkit-gradient(linear, #{args.join(', ')})")
|
Sass::Script::String.new("-webkit-gradient(linear, #{args.join(', ')})")
|
||||||
end
|
end
|
||||||
@ -116,55 +116,55 @@ module Compass::SassExtensions::Functions::GradientSupport
|
|||||||
Sass::Script::String.new("-moz-#{to_s}")
|
Sass::Script::String.new("-moz-#{to_s}")
|
||||||
end
|
end
|
||||||
def to_svg
|
def to_svg
|
||||||
linear_svg_gradient(color_stops, position_or_angle || Sass::Script::String.new("top"))
|
linear_svg_gradient(color_stops, position_and_angle || Sass::Script::String.new("top"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Functions
|
module Functions
|
||||||
|
|
||||||
def radial_gradient(position_or_angle, shape_or_size, *color_stops)
|
def radial_gradient(position_and_angle, shape_and_size, *color_stops)
|
||||||
# Have to deal with variable length/meaning arguments.
|
# Have to deal with variable length/meaning arguments.
|
||||||
if color_stop?(shape_or_size)
|
if color_stop?(shape_and_size)
|
||||||
color_stops.unshift(shape_or_size)
|
color_stops.unshift(shape_and_size)
|
||||||
shape_or_size = nil
|
shape_and_size = nil
|
||||||
elsif list_of_color_stops?(shape_or_size)
|
elsif list_of_color_stops?(shape_and_size)
|
||||||
# Support legacy use of the color-stops() function
|
# Support legacy use of the color-stops() function
|
||||||
color_stops = shape_or_size.values + color_stops
|
color_stops = shape_and_size.values + color_stops
|
||||||
shape_or_size = nil
|
shape_and_size = nil
|
||||||
end
|
end
|
||||||
shape_or_size = nil if shape_or_size && !shape_or_size.to_bool # nil out explictly passed falses
|
shape_and_size = nil if shape_and_size && !shape_and_size.to_bool # nil out explictly passed falses
|
||||||
# ditto for position_or_angle
|
# ditto for position_and_angle
|
||||||
if color_stop?(position_or_angle)
|
if color_stop?(position_and_angle)
|
||||||
color_stops.unshift(position_or_angle)
|
color_stops.unshift(position_and_angle)
|
||||||
position_or_angle = nil
|
position_and_angle = nil
|
||||||
elsif list_of_color_stops?(position_or_angle)
|
elsif list_of_color_stops?(position_and_angle)
|
||||||
color_stops = position_or_angle.values + color_stops
|
color_stops = position_and_angle.values + color_stops
|
||||||
position_or_angle = nil
|
position_and_angle = nil
|
||||||
end
|
end
|
||||||
position_or_angle = nil if position_or_angle && !position_or_angle.to_bool
|
position_and_angle = nil if position_and_angle && !position_and_angle.to_bool
|
||||||
|
|
||||||
# Support legacy use of the color-stops() function
|
# Support legacy use of the color-stops() function
|
||||||
if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
|
if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
|
||||||
color_stops = color_stops.first.values
|
color_stops = color_stops.first.values
|
||||||
end
|
end
|
||||||
RadialGradient.new(position_or_angle, shape_or_size, send(:color_stops, *color_stops))
|
RadialGradient.new(position_and_angle, shape_and_size, send(:color_stops, *color_stops))
|
||||||
end
|
end
|
||||||
|
|
||||||
def linear_gradient(position_or_angle, *color_stops)
|
def linear_gradient(position_and_angle, *color_stops)
|
||||||
if color_stop?(position_or_angle)
|
if color_stop?(position_and_angle)
|
||||||
color_stops.unshift(position_or_angle)
|
color_stops.unshift(position_and_angle)
|
||||||
position_or_angle = nil
|
position_and_angle = nil
|
||||||
elsif list_of_color_stops?(position_or_angle)
|
elsif list_of_color_stops?(position_and_angle)
|
||||||
color_stops = position_or_angle.values + color_stops
|
color_stops = position_and_angle.values + color_stops
|
||||||
position_or_angle = nil
|
position_and_angle = nil
|
||||||
end
|
end
|
||||||
position_or_angle = nil if position_or_angle && !position_or_angle.to_bool
|
position_and_angle = nil if position_and_angle && !position_and_angle.to_bool
|
||||||
|
|
||||||
# Support legacy use of the color-stops() function
|
# Support legacy use of the color-stops() function
|
||||||
if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
|
if color_stops.size == 1 && list_of_color_stops?(color_stops.first)
|
||||||
color_stops = color_stops.first.values
|
color_stops = color_stops.first.values
|
||||||
end
|
end
|
||||||
LinearGradient.new(position_or_angle, send(:color_stops, *color_stops))
|
LinearGradient.new(position_and_angle, send(:color_stops, *color_stops))
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns color-stop() calls for use in webkit.
|
# returns color-stop() calls for use in webkit.
|
||||||
|
Loading…
Reference in New Issue
Block a user