mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Port in compass-colors' adjust_hue function.
This commit is contained in:
parent
2878d8b895
commit
67b6c576f3
3 changed files with 38 additions and 0 deletions
|
@ -44,6 +44,9 @@ as on colors constructed with the {Sass::Script::Functions#hsl hsl} function.
|
|||
and {Sass::Script::Functions#desaturate desaturate}
|
||||
functions adjust the saturation of a color.
|
||||
|
||||
* The {Sass::Script::Functions#adjust_hue adjust-hue}
|
||||
function adjusts the hue of a color.
|
||||
|
||||
* The {Sass::Script::Functions#hue hue},
|
||||
{Sass::Script::Functions#saturation saturation},
|
||||
and {Sass::Script::Functions#lightness lightness}
|
||||
|
|
|
@ -410,6 +410,25 @@ module Sass::Script
|
|||
adjust(color, amount, :saturation, 0..100, :-, "%")
|
||||
end
|
||||
|
||||
# Changes the hue of a color while retaining the lightness and saturation.
|
||||
# Takes a color and a number of degrees (usually between -360 and 360),
|
||||
# and returns a color with the hue rotated by that value.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# adjust-hue(hsl(120, 30%, 90%), 60deg) => hsl(180, 30%, 90%)
|
||||
# adjust-hue(hsl(120, 30%, 90%), 060deg) => hsl(60, 30%, 90%)
|
||||
# adjust-hue(#811, 45deg) => #886a11
|
||||
#
|
||||
# @param color [Color]
|
||||
# @param amount [Number]
|
||||
# @raise [ArgumentError] If `color` isn't a color, or `number` isn't a number
|
||||
def adjust_hue(color, degrees)
|
||||
assert_type color, :Color
|
||||
assert_type degrees, :Number
|
||||
color.with(:hue => color.hue + degrees.value)
|
||||
end
|
||||
|
||||
# Converts a decimal number to a percentage.
|
||||
# For example:
|
||||
#
|
||||
|
|
|
@ -366,6 +366,22 @@ class SassFunctionTest < Test::Unit::TestCase
|
|||
assert_error_message("\"foo\" is not a number for `desaturate'", "desaturate(#fff, \"foo\")")
|
||||
end
|
||||
|
||||
def test_adjust_hue
|
||||
assert_equal("#deeded", evaluate("adjust-hue(hsl(120, 30, 90), 60deg)"))
|
||||
assert_equal("#ededde", evaluate("adjust-hue(hsl(120, 30, 90), -60deg)"))
|
||||
assert_equal("#886a11", evaluate("adjust-hue(#811, 45deg)"))
|
||||
assert_equal("black", evaluate("adjust-hue(#000, 45deg)"))
|
||||
assert_equal("white", evaluate("adjust-hue(#fff, 45deg)"))
|
||||
assert_equal("#88aa88", evaluate("adjust-hue(#8a8, 360deg)"))
|
||||
assert_equal("#88aa88", evaluate("adjust-hue(#8a8, 0deg)"))
|
||||
assert_equal("rgba(136, 106, 17, 0.5)", evaluate("adjust-hue(rgba(136, 17, 17, 0.5), 45deg)"))
|
||||
end
|
||||
|
||||
def test_adjust_hue_tests_types
|
||||
assert_error_message("\"foo\" is not a color for `adjust-hue'", "adjust-hue(\"foo\", 10%)")
|
||||
assert_error_message("\"foo\" is not a number for `adjust-hue'", "adjust-hue(#fff, \"foo\")")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def evaluate(value)
|
||||
|
|
Loading…
Add table
Reference in a new issue