Skip to content

Commit

Permalink
Merge commit 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/sass/script/functions.rb
  • Loading branch information
nex3 committed Jan 14, 2011
2 parents a2a17ed + e18890b commit ebf9e32
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 199 deletions.
18 changes: 9 additions & 9 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -62,33 +62,33 @@ that use keywords to encompass a large amount of functionality in one function.
* The {Sass::Script::Functions#adjust adjust} function works like the old
`lighten`, `saturate`, and `adjust-hue` methods.
It increases and/or decreases the values of a color's properties by fixed amounts.
For example, `adjust($color, $lightness: 10%)` is the same as `lighten($color, 10%)`:
For example, `adjust-color($color, $lightness: 10%)` is the same as `lighten($color, 10%)`:
it returns `$color` with its lightness increased by 10%.

* The {Sass::Script::Functions#scale scale} function
* The {Sass::Script::Functions#scale_color scale_color} function
is similar to {Sass::Script::Functions#adjust adjust},
but instead of increasing and/or decreasing a color's properties by fixed amounts,
it scales them fluidly by percentages.
The closer the percentage is to 100% (or -100%),
the closer the new property value will be to its maximum (or minimum).
For example, `scale(hsl(120, 70, 80), $lightness: 50%)`
For example, `scale-color(hsl(120, 70, 80), $lightness: 50%)`
will change the lightness from 80% to 90%,
because 90% is halfway between 80% and 100%.
Similarly, `scale(hsl(120, 70, 50), $lightness: 50%)`
Similarly, `scale-color(hsl(120, 70, 50), $lightness: 50%)`
will change the lightness from 50% to 75%.

* The {Sass::Script::Functions#set set} function simply sets a color's properties
* The {Sass::Script::Functions#change_color change-color} function simply changes a color's properties
regardless of their old values.
For example `set($color, $lightness: 10%)` returns `$color` with 10% lightness,
and `set($color, $alpha: 0.7)` returns color with opacity 0.7.
For example `change-color($color, $lightness: 10%)` returns `$color` with 10% lightness,
and `change-color($color, $alpha: 0.7)` returns color with opacity 0.7.

Each keyword function accepts `$hue`, `$saturation`, `$value`,
`$red`, `$green`, `$blue`, and `$alpha` keywords,
with the exception of `scale()` which doesn't accept `$hue`.
with the exception of `scale-color()` which doesn't accept `$hue`.
These keywords modify the respective properties of the given color.

Each keyword function can modify multiple properties at once.
For example, `adjust($color, $lightness: 15%, $saturation: -10%)`
For example, `adjust-color($color, $lightness: 15%, $saturation: -10%)`
both lightens and desaturates `$color`.
HSL properties cannot be modified at the same time as RGB properties, though.

Expand Down
2 changes: 1 addition & 1 deletion doc-src/SASS_REFERENCE.md
Expand Up @@ -1098,7 +1098,7 @@ For example, if `example.scss` contains
then

#main {
@import .example;
@import "example";
}

would compile to
Expand Down
9 changes: 8 additions & 1 deletion lib/sass/script/funcall.rb
Expand Up @@ -84,7 +84,7 @@ def _perform(environment)
args = construct_ruby_args(ruby_name, args, keywords)

unless Sass::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
opts(Script::String.new("#{name}(#{args.join(', ')})"))
opts(to_literal(args))
else
opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
end
Expand All @@ -93,6 +93,13 @@ def _perform(environment)
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
end

# This method is factored out from `_perform` so that compass can override
# it with a cross-browser implementation for functions that require vendor prefixes
# in the generated css.
def to_literal(args)
Script::String.new("#{name}(#{args.join(', ')})")
end

private

def construct_ruby_args(name, args, keywords)
Expand Down
57 changes: 30 additions & 27 deletions lib/sass/script/functions.rb
Expand Up @@ -90,14 +90,14 @@ module Sass::Script
#
# ## Other Color Functions
#
# \{#adjust adjust($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# \{#adjust adjust-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# : Increase or decrease any of the components of a color.
#
# \{#scale scale($color, \[$red\], \[$green\], \[$blue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# : Fluidly scale any of the components of a color.
# \{#scale_color scale-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# : Fluidly scale one or more components of a color.
#
# \{#set set($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# : Set any of the components of a color.
# \{#change_color change-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\]}
# : Changes one or more properties of a color.
#
# ## String Functions
#
Expand Down Expand Up @@ -735,9 +735,9 @@ def adjust_hue(color, degrees)
# and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
#
# @example
# adjust(#102030, $blue: 5) => #102035
# adjust(#102030, $red: -5, $blue: 5) => #0b2035
# adjust(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
# adjust-color(#102030, $blue: 5) => #102035
# adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
# adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
# @param color [Color]
# @param red [Number]
# @param green [Number]
Expand All @@ -752,7 +752,7 @@ def adjust_hue(color, degrees)
# if any keyword argument is not in the legal range,
# if an unexpected keyword argument is given,
# or if both HSL and RGB properties are given.
def adjust(color, kwargs)
def adjust_color(color, kwargs)
assert_type color, :Color
with = Sass::Util.map_hash({
"red" => [-255..255, ""],
Expand Down Expand Up @@ -781,21 +781,21 @@ def adjust(color, kwargs)

color.with(with)
end
declare :adjust, [:color], :var_kwargs => true
declare :adjust_color, [:color], :var_kwargs => true

# Scales one or more properties of a color by a percentage value.
# Unlike \{#adjust}, which changes a color's properties by fixed amounts,
# \{#scale} fluidly changes them based on how high or low they already are.
# That means that lightening an already-light color with \{#scale}
# won't change the lightness much,
# but lightening a dark color by the same amount will change it more dramatically.
# This has the benefit of making `scale($color, ...)` have a similar effect
# This has the benefit of making `scale-color($color, ...)` have a similar effect
# regardless of what `$color` is.
#
# For example, the lightness of a color can be anywhere between 0 and 100.
# If `scale($color, $lightness: 40%)` is called, the resulting color's lightness
# If `scale-color($color, $lightness: 40%)` is called, the resulting color's lightness
# will be 40% of the way between its original lightness and 100.
# If `scale($color, $lightness: -40%)` is called instead,
# If `scale-color($color, $lightness: -40%)` is called instead,
# the lightness will be 40% of the way between the original and 0.
#
# This can change the red, green, blue, saturation, value, and alpha properties.
Expand All @@ -807,9 +807,9 @@ def adjust(color, kwargs)
# and HSL properties (`$saturation`, `$value`) at the same time.
#
# @example
# scale(hsl(120, 70, 80), $lightness: 50%) => hsl(120, 70, 90)
# scale(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
# scale(hsl(200, 70, 80), $saturation: -90%, $alpha: -30%) => hsla(200, 7, 80, 0.7)
# scale-color(hsl(120, 70, 80), $lightness: 50%) => hsl(120, 70, 90)
# scale-color(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
# scale-color(hsl(200, 70, 80), $saturation: -90%, $alpha: -30%) => hsla(200, 7, 80, 0.7)
# @param color [Color]
# @param red [Number]
# @param green [Number]
Expand All @@ -822,7 +822,7 @@ def adjust(color, kwargs)
# if any keyword argument is not a percentage between 0% and 100%,
# if an unexpected keyword argument is given,
# or if both HSL and RGB properties are given.
def scale(color, kwargs)
def scale_color(color, kwargs)
assert_type color, :Color
with = Sass::Util.map_hash({
"red" => 255,
Expand Down Expand Up @@ -854,10 +854,10 @@ def scale(color, kwargs)

color.with(with)
end
declare :scale, [:color], :var_kwargs => true
declare :scale_color, [:color], :var_kwargs => true

# Sets on or more properties of a color.
# This can set the red, green, blue, hue, saturation, value, and alpha properties.
# Changes one or more properties of a color.
# This can change the red, green, blue, hue, saturation, value, and alpha properties.
# The properties are specified as keyword arguments,
# and replace the color's current value for that property.
#
Expand All @@ -870,9 +870,9 @@ def scale(color, kwargs)
# and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.
#
# @example
# set(#102030, $blue: 5) => #102005
# set(#102030, $red: 120, $blue: 5) => #782005
# set(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
# change-color(#102030, $blue: 5) => #102005
# change-color(#102030, $red: 120, $blue: 5) => #782005
# change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
# @param color [Color]
# @param red [Number]
# @param green [Number]
Expand All @@ -887,7 +887,7 @@ def scale(color, kwargs)
# if any keyword argument is not in the legal range,
# if an unexpected keyword argument is given,
# or if both HSL and RGB properties are given.
def set(color, kwargs)
def change_color(color, kwargs)
assert_type color, :Color
with = Sass::Util.map_hash(%w[red green blue hue saturation lightness alpha]) do |name, max|
next unless val = kwargs.delete(name)
Expand All @@ -902,7 +902,7 @@ def set(color, kwargs)

color.with(with)
end
declare :set, [:color], :var_kwargs => true
declare :change_color, [:color], :var_kwargs => true

# Mixes together two colors.
# Specifically, takes the average of each of the RGB components,
Expand Down Expand Up @@ -1019,8 +1019,11 @@ def invert(color)
# unquote("foo") => foo
# unquote(foo) => foo
def unquote(string)
assert_type string, :String
Sass::Script::String.new(string.value, :identifier)
if string.is_a?(Sass::Script::String)
Sass::Script::String.new(string.value, :identifier)
else
string
end
end
declare :unquote, [:string]

Expand Down

0 comments on commit ebf9e32

Please sign in to comment.