Created
February 2, 2012 10:36
-
-
Save ngs/1722819 to your computer and use it in GitHub Desktop.
a patch to fix compass raising error when using 'transparent' keyword for gradiention: 'Expected a color. Got: transparent'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## If you are using under a rails project, | |
## I recommend to put this script onto config/initializer instead of applying the patch | |
module Compass::SassExtensions::Functions::GradientSupport | |
class ColorStop < Sass::Script::Literal | |
def initialize(color, stop = nil) | |
self.options = {} | |
if color.is_a?(Sass::Script::String) && color.value == 'transparent' | |
color = Sass::Script::Color.new([0,0,0,0]) | |
color.options = {} | |
end | |
unless Sass::Script::Color === color || Sass::Script::Funcall === color | |
raise Sass::SyntaxError, "Expected a color. Got: #{color}" | |
end | |
if stop && !stop.is_a?(Sass::Script::Number) | |
raise Sass::SyntaxError, "Expected a number. Got: #{stop}" | |
end | |
self.color, self.stop = color, stop | |
end | |
end | |
module Functions | |
def color_stops(*args) | |
Sass::Script::List.new(args.map do |arg| | |
case arg | |
when ColorStop | |
arg | |
when Sass::Script::Color | |
ColorStop.new(arg) | |
when Sass::Script::List | |
ColorStop.new(*arg.value) | |
when Sass::Script::String | |
ColorStop.new(arg) | |
else | |
raise Sass::SyntaxError, "Not a valid color stop: #{arg.class.name}: #{arg}" | |
end | |
end, :comma) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- gradient_support_org.rb 2012-02-02 19:30:18.000000000 +0900 | |
+++ gradient_support.rb 2012-02-02 19:31:28.000000000 +0900 | |
@@ -8,6 +8,11 @@ | |
[color, stop].compact | |
end | |
def initialize(color, stop = nil) | |
+ self.options = {} | |
+ if color.is_a?(Sass::Script::String) && color.value == 'transparent' | |
+ color = Sass::Script::Color.new([0,0,0,0]) | |
+ color.options = {} | |
+ end | |
unless Sass::Script::Color === color || Sass::Script::Funcall === color | |
raise Sass::SyntaxError, "Expected a color. Got: #{color}" | |
end | |
@@ -141,7 +146,7 @@ | |
end | |
def initialize(position_or_angle, color_stops) | |
- unless color_stops.value.size >= 2 | |
+ unless color_stops.value && color_stops.value.size >= 2 | |
raise Sass::SyntaxError, "At least two color stops are required for a linear-gradient" | |
end | |
self.position_or_angle = position_or_angle | |
@@ -234,6 +239,8 @@ | |
ColorStop.new(arg) | |
when Sass::Script::List | |
ColorStop.new(*arg.value) | |
+ when Sass::Script::String | |
+ ColorStop.new(arg) | |
else | |
raise Sass::SyntaxError, "Not a valid color stop: #{arg.class.name}: #{arg}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment