Implement unitless builtin function
This commit is contained in:
parent
901bdcae3b
commit
816688cb84
@ -2,6 +2,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
use crate::common::QuoteKind;
|
use crate::common::QuoteKind;
|
||||||
|
use crate::units::Unit;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||||
@ -48,4 +49,12 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
let value = arg!(args, 0, "value");
|
let value = arg!(args, 0, "value");
|
||||||
Some(Value::Ident(value.kind().to_owned(), QuoteKind::None))
|
Some(Value::Ident(value.kind().to_owned(), QuoteKind::None))
|
||||||
});
|
});
|
||||||
|
decl!(f "unitless", |args| {
|
||||||
|
let number = arg!(args, 0, "number");
|
||||||
|
match number {
|
||||||
|
Value::Dimension(_, Unit::None) => Some(Value::True),
|
||||||
|
Value::Dimension(_, _) => Some(Value::False),
|
||||||
|
_ => Some(Value::True)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
@ -123,3 +123,18 @@ test!(
|
|||||||
"a {\n color: type-of(hi + bye)\n}\n",
|
"a {\n color: type-of(hi + bye)\n}\n",
|
||||||
"a {\n color: string;\n}\n"
|
"a {\n color: string;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
unitless_px,
|
||||||
|
"a {\n color: unitless(1px)\n}\n",
|
||||||
|
"a {\n color: false;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
unitless_num,
|
||||||
|
"a {\n color: unitless(1)\n}\n",
|
||||||
|
"a {\n color: true;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
unitless_string,
|
||||||
|
"a {\n color: unitless(foo)\n}\n",
|
||||||
|
"a {\n color: true;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user