Module: Compass::Core::SassExtensions::Functions::Colors

Included in:
Sass::Script::Functions
Defined in:
lib/compass/core/sass_extensions/functions/colors.rb

Instance Method Summary collapse

Instance Method Details

#adjust_lightness(color, amount) ⇒ Object

a genericized version of lighten/darken so that negative values can be used.



4
5
6
7
8
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 4

def adjust_lightness(color, amount)
  assert_type color, :Color
  assert_type amount, :Number
  color.with(:lightness => Sass::Util.restrict(color.lightness + amount.value, 0..100))
end

#adjust_saturation(color, amount) ⇒ Object

a genericized version of saturation/desaturate so that negative values can be used.



20
21
22
23
24
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 20

def adjust_saturation(color, amount)
  assert_type color, :Color
  assert_type amount, :Number
  color.with(:saturation => Sass::Util.restrict(color.saturation + amount.value, 0..100))
end

#ie_hex_str(color) ⇒ Object

returns an IE hex string for a color with an alpha channel suitable for passing to IE filters.



51
52
53
54
55
56
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 51

def ie_hex_str(color)
  assert_type color, :Color
  alpha = (color.alpha * 255).round
  alphastr = alpha.to_s(16).rjust(2, '0')
  identifier("##{alphastr}#{color.send(:hex_str)[1..-1]}".upcase)
end

#scale_lightness(color, amount) ⇒ Object

Scales a color’s lightness by some percentage. If the amount is negative, the color is scaled darker, if positive, it is scaled lighter. This will never return a pure light or dark color unless the amount is 100%.



13
14
15
16
17
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 13

def scale_lightness(color, amount)
  assert_type color, :Color
  assert_type amount, :Number
  color.with(:lightness => scale_color_value(color.lightness, amount.value))
end

#scale_saturation(color, amount) ⇒ Object

Scales a color’s saturation by some percentage. If the amount is negative, the color is desaturated, if positive, it is saturated. This will never return a pure saturated or desaturated color unless the amount is 100%.



29
30
31
32
33
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 29

def scale_saturation(color, amount)
  assert_type color, :Color
  assert_type amount, :Number
  color.with(:saturation => scale_color_value(color.saturation, amount.value))
end

#shade(color, percentage) ⇒ Object



35
36
37
38
39
40
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 35

def shade(color, percentage)
  assert_type color, :Color
  assert_type percentage, :Number
  black = rgb_color(0, 0, 0)
  mix(black, color, percentage)
end

#tint(color, percentage) ⇒ Object



42
43
44
45
46
47
# File 'lib/compass/core/sass_extensions/functions/colors.rb', line 42

def tint(color, percentage)
  assert_type color, :Color
  assert_type percentage, :Number
  white = rgb_color(255, 255, 255)
  mix(white, color, percentage)
end