2020-02-02 22:33:04 -05:00
|
|
|
use std::collections::BTreeMap;
|
2020-02-02 21:09:29 -05:00
|
|
|
|
2020-02-02 22:33:04 -05:00
|
|
|
use super::Builtin;
|
2020-02-03 07:35:04 -05:00
|
|
|
use crate::common::QuoteKind;
|
2020-02-02 22:33:04 -05:00
|
|
|
use crate::value::Value;
|
|
|
|
|
|
|
|
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
2020-02-03 07:11:35 -05:00
|
|
|
decl!(f "if", |args| {
|
|
|
|
let cond: &Value = arg!(args, 0, "condition");
|
|
|
|
let if_true = arg!(args, 1, "if-true").clone();
|
|
|
|
let if_false = arg!(args, 2, "if-false").clone();
|
|
|
|
if cond.is_true() {
|
|
|
|
Some(if_true)
|
|
|
|
} else {
|
|
|
|
Some(if_false)
|
|
|
|
}
|
|
|
|
});
|
2020-02-03 07:22:20 -05:00
|
|
|
decl!(f "feature-exists", |args| {
|
|
|
|
let feature: &Value = arg!(args, 0, "feature");
|
2020-02-03 07:27:57 -05:00
|
|
|
match feature.clone().unquote().to_string().as_str() {
|
2020-02-03 07:22:20 -05:00
|
|
|
// A local variable will shadow a global variable unless
|
|
|
|
// `!global` is used.
|
|
|
|
"global-variable-shadowing" => Some(Value::False),
|
|
|
|
// the @extend rule will affect selectors nested in pseudo-classes
|
|
|
|
// like :not()
|
|
|
|
"extend-selector-pseudoclass" => Some(Value::False),
|
|
|
|
// Full support for unit arithmetic using units defined in the
|
|
|
|
// [Values and Units Level 3][] spec.
|
|
|
|
"units-level-3" => Some(Value::False),
|
|
|
|
// The Sass `@error` directive is supported.
|
|
|
|
"at-error" => Some(Value::True),
|
|
|
|
// The "Custom Properties Level 1" spec is supported. This means
|
|
|
|
// that custom properties are parsed statically, with only
|
|
|
|
// interpolation treated as SassScript.
|
|
|
|
"custom-property" => Some(Value::False),
|
|
|
|
_ => Some(Value::False),
|
|
|
|
}
|
|
|
|
});
|
2020-02-03 07:35:04 -05:00
|
|
|
decl!(f "unit", |args| {
|
|
|
|
let number = arg!(args, 0, "number");
|
|
|
|
let unit = match number {
|
|
|
|
Value::Dimension(_, u) => u.to_string(),
|
|
|
|
_ => String::new()
|
|
|
|
};
|
|
|
|
Some(Value::Ident(unit, QuoteKind::Double))
|
|
|
|
});
|
2020-02-02 22:33:04 -05:00
|
|
|
}
|