module Sass::Script # Methods in this module are accessible from the SassScript context. # For example, you can write # # !color = hsl(120, 100%, 50%) # # and it will call {Sass::Script::Functions#hsl}. # # The following functions are provided: # # \{#hsl} # : Converts an `hsl(hue, saturation, lightness)` triplet into a color. # # \{#percentage} # : Converts a unitless number to a percentage. # # \{#round} # : Rounds a number to the nearest whole number. # # \{#ceil} # : Rounds a number up to the nearest whole number. # # \{#floor} # : Rounds a number down to the nearest whole number. # # \{#abs} # : Returns the absolute value of a number. # # These functions are described in more detail below. # # ## Adding Custom Functions # # New 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 # end # # There are a few things to keep in mind when modifying this module. # First of all, the arguments passed are {Sass::Script::Literal} objects. # Literal objects are also expected to be returned. # This means that Ruby values must be unwrapped and wrapped. # # Most Literal objects support the {Sass::Script::Literal#value value} accessor # for getting their Ruby values. # Color objects, though, must be accessed using {Sass::Script::Color#rgb rgb}, # {Sass::Script::Color#red red}, {Sass::Script::Color#blue green}, or {Sass::Script::Color#blue blue}. # # Second, making Ruby functions accessible from Sass introduces the temptation # to do things like database access within stylesheets. # This temptation must be resisted. # Keep in mind that Sass stylesheets are only compiled once # at a somewhat indeterminate time # and then left as static CSS files. # Any dynamic CSS should be left in `