compass-colors 0.3.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :build:
3
3
  :major: 0
4
- :minor: 3
5
- :patch: 1
4
+ :minor: 9
5
+ :patch: 0
@@ -11,102 +11,55 @@ module Sass::Script::Functions
11
11
  end
12
12
  end
13
13
  end
14
- # Takes a color object and amount by which to lighten it (0 to 100).
15
- def lighten(color, amount)
16
- hsl = Compass::Colors::HSL.from_color(color)
17
- hsl.l += amount.value / 100.0
18
- hsl.to_color
19
- end
20
14
 
21
15
  # Takes a color object and percent by which to lighten it (0 to 100).
22
16
  def lighten_percent(color, amount)
23
- hsl = Compass::Colors::HSL.from_color(color)
24
- hsl.l += (1 - hsl.l) * (amount.value / 100.0)
25
- hsl.to_color
26
- end
27
-
28
- # Takes a color object and amount by which to darken it (0 to 100).
29
- def darken(color, amount)
30
- hsl = Compass::Colors::HSL.from_color(color)
31
- hsl.l -= amount.value / 100.0
32
- hsl.to_color
17
+ Compass::Util.compass_warn("lighten-percent() is deprecated. Please use the scale-color() function provided by sass.")
18
+ if unitless(amount).to_bool
19
+ Compass::Util.compass_warn("Sass's scale-color() function requires a percent instead of a unitless number for the amount.")
20
+ amount = Sass::Script::Number.new(amount.value, ['%'], [])
21
+ end
22
+ scale_color(color, "lightness" => amount)
33
23
  end
34
24
 
35
25
  # Takes a color object and percent by which to darken it (0 to 100).
36
26
  def darken_percent(color, amount)
37
- hsl = Compass::Colors::HSL.from_color(color)
38
- hsl.l *= 1.0 - (amount.value / 100.0)
39
- hsl.to_color
40
- end
41
-
42
- # Saturate (make a color "richer") a color by the given amount (0 to 100)
43
- def saturate(color, amount)
44
- hsl = Compass::Colors::HSL.from_color(color)
45
- hsl.s += amount.value / 100.0
46
- hsl.to_color
27
+ Compass::Util.compass_warn("darken-percent() is deprecated. Please use the scale-color() function provided by sass.")
28
+ if unitless(amount).to_bool
29
+ Compass::Util.compass_warn("Sass's scale-color() function requires a percent instead of a unitless number for the amount.")
30
+ amount = Sass::Script::Number.new(-amount.value, ['%'], [])
31
+ else
32
+ amount = amount.times(Sass::Script::Number.new(-1))
33
+ end
34
+ scale_color(color, "lightness" => amount)
47
35
  end
48
36
 
49
37
  # Saturate (make a color "richer") a color by the given percent (0 to 100)
50
38
  def saturate_percent(color, amount)
51
- hsl = Compass::Colors::HSL.from_color(color)
52
- hsl.s += (1 - hsl.s) * (amount.value / 100.0)
53
- hsl.to_color
54
- end
55
-
56
- # Desaturate (make a color "grayer") a color by the given amount (0 to 100)
57
- def desaturate(color, amount)
58
- hsl = Compass::Colors::HSL.from_color(color)
59
- hsl.s -= amount.value / 100.0
60
- hsl.to_color
39
+ Compass::Util.compass_warn("saturate-percent() is deprecated. Please use the scale-color() function provided by sass.")
40
+ if unitless(amount).to_bool
41
+ Compass::Util.compass_warn("Sass's scale-color() function requires a percent instead of a unitless number for the amount.")
42
+ amount = Sass::Script::Number.new(amount.value, ['%'], [])
43
+ end
44
+ scale_color(color, "saturation" => amount)
61
45
  end
62
46
 
63
47
  # Desaturate (make a color "grayer") a color by the given percent (0 to 100)
64
48
  def desaturate_percent(color, amount)
65
- hsl = Compass::Colors::HSL.from_color(color)
66
- hsl.s *= (1.0 - (amount.value / 100.0))
67
- hsl.to_color
68
- end
69
-
70
- # Return the hue of a color as a number between 0 and 360
71
- def hue(color)
72
- Sass::Script::Number.new(Compass::Colors::HSL.from_color(color).h.round)
73
- end
74
-
75
- # Return the saturation of a color as a number between 0 and 100
76
- def saturation(color)
77
- Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).s * 100).round)
49
+ Compass::Util.compass_warn("desaturate-percent() is deprecated. Please use the scale-color() function provided by sass.")
50
+ if unitless(amount).to_bool
51
+ Compass::Util.compass_warn("Sass's scale-color() function requires a percent instead of a unitless number for the amount.")
52
+ amount = Sass::Script::Number.new(-amount.value, ['%'], [])
53
+ else
54
+ amount = amount.times(Sass::Script::Number.new(-1))
55
+ end
56
+ scale_color(color, "saturation" => amount)
78
57
  end
79
58
 
80
59
  # Return the luminosity of a color as a number between 0 and 100
81
60
  def luminosity(color)
82
- Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).l * 100).round)
83
- end
84
- alias lightness luminosity
85
-
86
- # Mixes two colors by some amount (0 to 100). Defaults to 50.
87
- def mix(color1, color2, amount = nil)
88
- percent = amount ? amount.value.round / 100.0 : 0.5
89
- new_colors = Colors.rgb_value(color1).zip(Colors.rgb_value(color2)).map{|c1, c2| (c1 * percent) + (c2 * (1 - percent))}
90
- Sass::Script::Color.new(new_colors)
91
- end
92
-
93
- # Returns the grayscale equivalent color for the given color
94
- def grayscale(color)
95
- hsl = Compass::Colors::HSL.from_color(color)
96
- g = (hsl.l * 255).round
97
- Sass::Script::Color.new([g, g, g])
98
- end
99
-
100
- # adjust the hue of a color by the given number of degrees.
101
- def adjust_hue(color, degrees)
102
- hsl = Compass::Colors::HSL.from_color(color)
103
- degrees = degrees.value.to_f.round if degrees.is_a?(Sass::Script::Literal)
104
- hsl.h += degrees
105
- hsl.to_color
106
- end
107
-
108
- def complement(color)
109
- adjust_hue color, 180
61
+ Compass::Util.compass_warn("luminosity($color) is deprecated. Please use the lightness($color) provided by sass.")
62
+ lightness(color)
110
63
  end
111
64
 
112
65
  end
@@ -25,7 +25,7 @@ module BeApproximatelyTheSameColorAsMatcher
25
25
  if value.nil?
26
26
  'nil'
27
27
  end
28
-
28
+ value.options = {}
29
29
  # join arrays
30
30
  if value.class == Array
31
31
  return value.join(", ")
@@ -1,22 +1,83 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
 
3
3
  require File.join(File.dirname(__FILE__), 'approximate_color_matching')
4
+ require 'sass'
5
+ require 'stringio'
6
+
7
+ module Capturing
8
+ def capture_stderr
9
+ $stderr, real_stderr = StringIO.new, $stderr
10
+ yield
11
+ $stderr.string
12
+ ensure
13
+ $stderr = real_stderr
14
+ end
15
+ end
4
16
 
5
17
  Spec::Runner.configure do |config|
6
18
  config.include(BeApproximatelyTheSameColorAsMatcher)
19
+ config.include(Capturing)
7
20
  end
8
21
 
9
22
  require 'compass-colors'
10
23
 
11
24
  describe "sass extensions" do
25
+
26
+ it "should deprecate luminosity" do
27
+ warning = capture_stderr do
28
+ invoke(:luminosity, color(255,0,0))
29
+ end
30
+ warning.strip.should == "luminosity($color) is deprecated. Please use the lightness($color) provided by sass."
31
+ end
32
+
33
+ it "should deprecate desaturate-percent" do
34
+ warning = capture_stderr do
35
+ desaturated = invoke(:desaturate_percent, color(255,0,0), number(25))
36
+ desaturated.should be_approximately_the_same_color_as(color(223,32,32))
37
+ end
38
+ warning.should == %q<desaturate-percent() is deprecated. Please use the scale-color() function provided by sass.
39
+ Sass's scale-color() function requires a percent instead of a unitless number for the amount.
40
+ >
41
+ end
42
+
43
+ it "should deprecate saturate-percent" do
44
+ warning = capture_stderr do
45
+ desaturated = invoke(:saturate_percent, color(127,32,32), number(25))
46
+ desaturated.should be_approximately_the_same_color_as(color(135,24,24))
47
+ end
48
+ warning.should == %q<saturate-percent() is deprecated. Please use the scale-color() function provided by sass.
49
+ Sass's scale-color() function requires a percent instead of a unitless number for the amount.
50
+ >
51
+ end
52
+
53
+ it "should desaturate-percents" do
54
+ capture_stderr do
55
+ desaturated = invoke(:desaturate_percent, color(255,0,0), number(25, '%'))
56
+ desaturated.should be_approximately_the_same_color_as(color(223,32,32))
57
+ end
58
+ end
59
+
60
+ it "should saturate colors" do
61
+ color = invoke(:saturate, color(127,32,32), number(25))
62
+ color.should be_approximately_the_same_color_as(color(147,12,12))
63
+ end
64
+
65
+ it "should desaturate colors" do
66
+ color = invoke(:desaturate, color(255,0,0), number(25))
67
+ color.should be_approximately_the_same_color_as(color(223,32,32))
68
+ end
69
+
12
70
  it "should lighten red into pink" do
13
71
  pink = invoke(:lighten, color(255,0,0), number(25))
14
72
  pink.should be_approximately_the_same_color_as(color(255,127,127))
15
73
  end
16
74
 
17
75
  it "should lighten red into pink (percentage)" do
18
- pink = invoke(:lighten_percent, color(255,0,0), number(50))
19
- pink.should be_approximately_the_same_color_as(color(255,127,127))
76
+ warning = capture_stderr do
77
+ pink = invoke(:lighten_percent, color(255,0,0), number(50))
78
+ pink.should be_approximately_the_same_color_as(color(255,127,127))
79
+ end
80
+ warning.should == "lighten-percent() is deprecated. Please use the scale-color() function provided by sass.\nSass's scale-color() function requires a percent instead of a unitless number for the amount.\n"
20
81
  end
21
82
 
22
83
  it "should darken red into maroon" do
@@ -25,8 +86,11 @@ describe "sass extensions" do
25
86
  end
26
87
 
27
88
  it "should darken red into maroon (percentage)" do
28
- maroon = invoke(:darken_percent, color(255,0,0), number(50))
29
- maroon.should be_approximately_the_same_color_as(color(127,0,0))
89
+ warning = capture_stderr do
90
+ maroon = invoke(:darken_percent, color(255,0,0), number(50))
91
+ maroon.should be_approximately_the_same_color_as(color(127,0,0))
92
+ end
93
+ warning.should == "darken-percent() is deprecated. Please use the scale-color() function provided by sass.\nSass's scale-color() function requires a percent instead of a unitless number for the amount.\n"
30
94
  end
31
95
 
32
96
  it "should darken white into gray and back again" do
@@ -40,6 +104,16 @@ describe "sass extensions" do
40
104
  saturated.should be_approximately_the_same_color_as(color(0, 127, 127))
41
105
  end
42
106
 
107
+ it "should mix colors" do
108
+ mixed = invoke(:mix, color(127, 127, 0), color(0, 127, 127), number(50))
109
+ mixed.should be_approximately_the_same_color_as(color(63, 127, 63))
110
+ end
111
+
112
+ it "should adjust hues" do
113
+ mixed = invoke(:adjust_hue, color(127, 0, 0), number(120, "deg"))
114
+ mixed.should be_approximately_the_same_color_as(color(0, 127, 0))
115
+ end
116
+
43
117
  def invoke(name, *args)
44
118
  Sass::Script::Functions::EvaluationContext.new({}).send(name, *args)
45
119
  end
@@ -48,7 +122,7 @@ describe "sass extensions" do
48
122
  Sass::Script::Color.new([r,g,b])
49
123
  end
50
124
 
51
- def number(num)
52
- Sass::Script::Number.new(num)
125
+ def number(num, units = nil)
126
+ Sass::Script::Number.new(num, Array(units))
53
127
  end
54
128
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compass-colors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ prerelease:
5
+ version: 0.9.0
5
6
  platform: ruby
6
7
  authors:
7
8
  - Chris Eppstein
@@ -9,19 +10,20 @@ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-11-19 00:00:00 -08:00
13
+ date: 2011-04-16 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: compass
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
24
  version: 0.8.7
24
- version:
25
+ type: :runtime
26
+ version_requirements: *id001
25
27
  description: Sass Extensions and color theme templates to make working with colors easier and more maintainable.
26
28
  email: chris@eppsteins.net
27
29
  executables: []
@@ -59,26 +61,26 @@ homepage: http://compass-style.org
59
61
  licenses: []
60
62
 
61
63
  post_install_message:
62
- rdoc_options:
63
- - --charset=UTF-8
64
+ rdoc_options: []
65
+
64
66
  require_paths:
65
67
  - lib
66
68
  required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
67
70
  requirements:
68
71
  - - ">="
69
72
  - !ruby/object:Gem::Version
70
73
  version: "0"
71
- version:
72
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
73
76
  requirements:
74
77
  - - ">="
75
78
  - !ruby/object:Gem::Version
76
79
  version: "0"
77
- version:
78
80
  requirements: []
79
81
 
80
82
  rubyforge_project:
81
- rubygems_version: 1.3.5
83
+ rubygems_version: 1.5.3
82
84
  signing_key:
83
85
  specification_version: 3
84
86
  summary: Color Support for Compass & Sass