HSL Functions
HSL ($ hue, $ saturation, $ lightness)
Converts
hsl(hue, saturation, lightness)
Triplet into a color. // color, saturation, and brightness
HSLA ($ hue, $ saturation, $ lightness, $ alpha)
Converts
hsla(hue, saturation, lightness, alpha)
Quadruplet into a color. // color phase, saturation, brightness, and transparency
Hue ($ color)
Gets the hue component of a color. // obtain the color of the color.
Saturation ($ color)
Gets the saturation component of a color. // gets the color saturation.
Lightness ($ color)
Gets the lightness component of a color. // gets the brightness of the color.
Adjust-Hue ($ color, $ degrees)
Changes the hue of a color. // adjust the color
Lighten ($ color, $ amount)
Makes a color lighter.
Darken ($ color, $ amount)
Makes a color darker.
Saturate ($ color, $ amount)
Makes a color more saturated.
Desaturate ($ color, $ amount)
Makes a color less saturated.
Grayscale ($ color)
Converts a color to grayscale. // grayscale
Complement ($ color)
Returns the complement of a color. // complementary
Invert ($ color)
Returns the inverse of a color. // reverse
sass:
color: lighten(#8ec63f, 50%)color: darken(#8ec63f, 30%)color: saturate(#8ec63f, 75%)color: desaturate(#8ec63f, 25%)color: adjust-hue(#8ec63f, 30)color: adjust-hue(#8ec63f, -30)color: fade-in(rgba(142, 198, 63, 0), .4)color: fade-out(#8ec63f, .4)
color: invert(#8ec63f)color: complement(#8ec63f)color: mix(#8ec63f, #fff)color: mix(#8ec63f, #fff, 10%)color: grayscale(#8ec63f)
CSS after compilation:
color: white;color: #3b5319;color: #98ff06;color: #89a75e;color: #4ac63f;color: #c6bb3f;color: rgba(142, 198, 63, 0.4);color: rgba(142, 198, 63, 0.6);
color: #7139c0;color: #773fc6;color: #c6e29f;color: #f3f9eb;color: #838383;
Miscellaneous FunctionsNew sass functions can be added by adding Ruby methods to this module. For example:
module Sass::Script::Functions def reverse(string) assert_type string, :String Sass::Script::String.new(string.value.reverse) end declare :reverse, :args => [:string]end
CallingDeclareTells sass the argument names for your
Function. If omitted, the function will still work, but will not be able to accept keyword arguments.DeclareCan
Also allow your function to take arbitrary keyword arguments.
There are a few things to keep in mind when modifying this module. First of all, the arguments passed areSass: Script: literalObjects.
Literal objects are also expected to be returned. This means that Ruby values must be unwrapped and wrapped.
Most literal objects supportValueAccessor for getting
Their Ruby values. Color objects, though, must be accessed usingRGB,Red,Green,
OrBlue.
Second, making Ruby functions accessible from sass introduces the temptation to do things like database access within stylesheets. this is generally a bad idea; Since sass files are by default only compiled once, dynamic code is not a great fit.
If you really, really need to compile sass on each request, first make sure you have adequate caching set up. Then you can useSass: EngineTo
Render the code, usingoptions
Parameterto pass in data thatCan
Be AccessedFrom your sass functions.
Within one of the functions in this module, methodsEvaluationcontextCan
Be used.
CaveatsWhen creating newLiteralObjects within functions, be aware that it's not safe to call# To_s(Or
Other methods that use the string representation) on those objects without first settingThe
# Options attribute.
Give the most complete: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html