chriseppstein-compass-colors 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/example/config.rb +2 -0
- data/lib/compass-colors/sass_extensions.rb +4 -4
- data/spec/sass_extensions_spec.rb +5 -5
- metadata +1 -1
data/VERSION.yml
CHANGED
data/example/config.rb
CHANGED
@@ -5,28 +5,28 @@ module Sass::Script::Functions
|
|
5
5
|
# Takes a color object and amount by which to lighten it (0 to 100).
|
6
6
|
def lighten(color, amount)
|
7
7
|
hsl = Compass::Colors::HSL.from_color(color)
|
8
|
-
hsl.l
|
8
|
+
hsl.l += (1 - hsl.l) * (amount.value / 100.0)
|
9
9
|
hsl.to_color
|
10
10
|
end
|
11
11
|
|
12
12
|
# Takes a color object and amount by which to darken it (0 to 100).
|
13
13
|
def darken(color, amount)
|
14
14
|
hsl = Compass::Colors::HSL.from_color(color)
|
15
|
-
hsl.l *= (
|
15
|
+
hsl.l *= 1.0 - (amount.value / 100.0)
|
16
16
|
hsl.to_color
|
17
17
|
end
|
18
18
|
|
19
19
|
# Saturate (make a color "richer") a color by the given amount (0 to 100)
|
20
20
|
def saturate(color, amount)
|
21
21
|
hsl = Compass::Colors::HSL.from_color(color)
|
22
|
-
hsl.s
|
22
|
+
hsl.s += (1 - hsl.s) * (amount.value / 100.0)
|
23
23
|
hsl.to_color
|
24
24
|
end
|
25
25
|
|
26
26
|
# Desaturate (make a color "grayer") a color by the given amount (0 to 100)
|
27
27
|
def desaturate(color, amount)
|
28
28
|
hsl = Compass::Colors::HSL.from_color(color)
|
29
|
-
hsl.s *= (-amount.value / 100.0)
|
29
|
+
hsl.s *= (1.0 - (amount.value / 100.0))
|
30
30
|
hsl.to_color
|
31
31
|
end
|
32
32
|
|
@@ -11,18 +11,18 @@ require 'compass-colors'
|
|
11
11
|
describe "sass extensions" do
|
12
12
|
it "should lighten red into pink" do
|
13
13
|
pink = invoke(:lighten, color(255,0,0), number(50))
|
14
|
-
pink.
|
14
|
+
pink.should be_approximately_the_same_color_as(color(255,127,127))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should darken red into maroon" do
|
18
18
|
maroon = invoke(:darken, color(255,0,0), number(50))
|
19
|
-
maroon.
|
19
|
+
maroon.should be_approximately_the_same_color_as(color(127,0,0))
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should darken
|
23
|
-
darker = invoke(:darken, color(
|
22
|
+
it "should darken white into gray and back again" do
|
23
|
+
darker = invoke(:darken, color(0xff, 0xff, 0xff), number(50))
|
24
24
|
lighter_again = invoke(:lighten, darker, number(100))
|
25
|
-
color(
|
25
|
+
color(0xff, 0xff, 0xff).should be_approximately_the_same_color_as(lighter_again)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "shouldn't saturate fully saturated colors" do
|