Skip to content
Browse files

Backwards compatibility with versions of sass that don't have an rgb …

…accessor.
  • Loading branch information...
1 parent 945afce commit a2c721d13a11ba5df26d40e13c7038dde5ecb1c7 @chriseppstein committed Nov 19, 2009
Showing with 15 additions and 4 deletions.
  1. +2 −1 lib/compass-colors/hsl.rb
  2. +11 −1 lib/compass-colors/sass_extensions.rb
  3. +2 −2 spec/sass_extensions_spec.rb
View
3 lib/compass-colors/hsl.rb
@@ -8,7 +8,8 @@ class HSL
attr_reader :s, :l
def self.from_color(color)
- from_rgb(*color.rgb)
+ rgb = color.respond_to?(:rgb) ? color.rgb : color.value
+ from_rgb(*rgb)
end
def self.from_rgb(r, g, b)
View
12 lib/compass-colors/sass_extensions.rb
@@ -1,6 +1,16 @@
require 'sass'
module Sass::Script::Functions
+ module Colors
+ extend self
+ def rgb_value(color)
+ if color.respond_to?(:rgb)
+ color.rgb
+ else
+ color.value
+ end
+ end
+ end
# Takes a color object and amount by which to lighten it (0 to 100).
def lighten(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
@@ -76,7 +86,7 @@ def luminosity(color)
# Mixes two colors by some amount (0 to 100). Defaults to 50.
def mix(color1, color2, amount = nil)
percent = amount ? amount.value.round / 100.0 : 0.5
- new_colors = color1.rgb.zip(color2.rgb).map{|c1, c2| (c1 * percent) + (c2 * (1 - percent))}
+ new_colors = Colors.rgb_value(color1).zip(Colors.rgb_value(color2)).map{|c1, c2| (c1 * percent) + (c2 * (1 - percent))}
Sass::Script::Color.new(new_colors)
end
View
4 spec/sass_extensions_spec.rb
@@ -15,7 +15,7 @@
end
it "should lighten red into pink (percentage)" do
- pink = invoke(:percent_lighten, color(255,0,0), number(50))
+ pink = invoke(:lighten_percent, color(255,0,0), number(50))
pink.should be_approximately_the_same_color_as(color(255,127,127))
end
@@ -25,7 +25,7 @@
end
it "should darken red into maroon (percentage)" do
- maroon = invoke(:percent_darken, color(255,0,0), number(50))
+ maroon = invoke(:darken_percent, color(255,0,0), number(50))
maroon.should be_approximately_the_same_color_as(color(127,0,0))
end

0 comments on commit a2c721d

Please sign in to comment.
Something went wrong with that request. Please try again.