Skip to content

Commit

Permalink
Clean up if() documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Nov 26, 2010
1 parent d9b2512 commit b3f6217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -6,9 +6,10 @@
## 3.2.0 (Unreleased)

* Add an {Sass::Script::Functions#invert `invert` function} that takes the inverse of colors.

* A new sass function called `if` can be used to emit one of two values
based on the truth value of the first argument. E.g. `if(true, 1px, 2px)`
returns `1px` and `if(false, 1px, 2px)` returns `2px`
based on the truth value of the first argument.
For example, `if(true, 1px, 2px)` returns `1px` and `if(false, 1px, 2px)` returns `2px`.

* Many performance optimizations have been made by [thedarkone](http://github.com/thedarkone).

Expand Down
16 changes: 11 additions & 5 deletions lib/sass/script/functions.rb
Expand Up @@ -138,6 +138,11 @@ module Sass::Script
# \{#comparable comparable($number-1, $number-2)}
# : Returns whether two numbers can be added or compared.
#
# ## Miscellaneous Functions
#
# \{#if if($condition, $if-true, $if-false)}
# : Returns one of two values, depending on whether or not a condition is true.
#
# ## Adding Custom Functions
#
# New Sass functions can be added by adding Ruby methods to this module.
Expand Down Expand Up @@ -1078,15 +1083,16 @@ def append(list, val, separator = Sass::Script::String.new("auto"))
declare :append, [:list, :val]
declare :append, [:list, :val, :separator]

# returns one of two values based on the truth value of the first argument.
# Returns one of two values based on the truth value of the first argument.
#
# @example
# if(true, 1px, 2px) => 1px
# if(false, 1px, 2px) => 2px
# @param truth [Bool] the expression to be evaluated for truth
# @param if_true will be returned if the truth value is true.
# @param if_false will be returned if the truth value is false.
def if(truth, if_true, if_false)
# @param condition [Bool] Whether the first or second value will be returned.
# @param if_true [Literal] The value that will be returned if `$condition` is true.
# @param if_false [Literal] The value that will be returned if `$condition` is false.
def if(condition, if_true, if_false)
assert_type condition, :Bool
if truth.to_bool
if_true
else
Expand Down

0 comments on commit b3f6217

Please sign in to comment.