A new function: if()
This commit is contained in:
parent
b3b7c898b1
commit
dabdaecee3
@ -47,6 +47,8 @@ COMPASS CHANGELOG
|
||||
If you provide a number with units of `deg` then it will return a unitless number
|
||||
after converting to radians. Otherwise, it assumes the number is a radian length measure
|
||||
and passes the units along to the result.
|
||||
* A new function `if()` that allows you to switch on a value without using `@if`.
|
||||
Usage: `if($truth-value, $value-if-true, $value-if-false)`.
|
||||
|
||||
### Rails
|
||||
|
||||
|
@ -2,7 +2,7 @@ module Compass::SassExtensions::Functions
|
||||
end
|
||||
|
||||
%w(
|
||||
selectors enumerate urls display
|
||||
selectors enumerate urls display if
|
||||
inline_image image_size gradient_support
|
||||
font_files constants lists colors trig
|
||||
).each do |func|
|
||||
@ -22,6 +22,7 @@ module Sass::Script::Functions
|
||||
include Compass::SassExtensions::Functions::Lists
|
||||
include Compass::SassExtensions::Functions::Colors
|
||||
include Compass::SassExtensions::Functions::Trig
|
||||
include Compass::SassExtensions::Functions::If
|
||||
end
|
||||
|
||||
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
|
||||
|
9
lib/compass/sass_extensions/functions/if.rb
Normal file
9
lib/compass/sass_extensions/functions/if.rb
Normal file
@ -0,0 +1,9 @@
|
||||
module Compass::SassExtensions::Functions::If
|
||||
def if(truth, if_true, if_false)
|
||||
if truth.to_bool
|
||||
if_true
|
||||
else
|
||||
if_false
|
||||
end
|
||||
end
|
||||
end
|
@ -59,6 +59,11 @@ class SassExtensionsTest < Test::Unit::TestCase
|
||||
assert_equal "25%", evaluate("saturation(adjust-saturation(hsl(50deg, 50%, 50%), -25%))")
|
||||
end
|
||||
|
||||
def test_if_function
|
||||
assert_equal "no", evaluate("if(false, yes, no)")
|
||||
assert_equal "yes", evaluate("if(true, yes, no)")
|
||||
end
|
||||
|
||||
def test_trig_functions
|
||||
assert_equal "0.841px", evaluate("sin(1px)")
|
||||
assert_equal "0.0", evaluate("sin(pi())")
|
||||
|
Loading…
Reference in New Issue
Block a user