Add unit function
This commit is contained in:
parent
e57a189c77
commit
c92781a20e
@ -1,6 +1,7 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
|
use crate::common::QuoteKind;
|
||||||
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>) {
|
||||||
@ -35,4 +36,12 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
_ => Some(Value::False),
|
_ => Some(Value::False),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
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))
|
||||||
|
});
|
||||||
}
|
}
|
@ -38,3 +38,23 @@ test!(
|
|||||||
"a {\n color: feature-exists($feature: at-error)\n}\n",
|
"a {\n color: feature-exists($feature: at-error)\n}\n",
|
||||||
"a {\n color: true;\n}\n"
|
"a {\n color: true;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
unit_px,
|
||||||
|
"a {\n color: unit(1px)\n}\n",
|
||||||
|
"a {\n color: \"px\";\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
unit_none,
|
||||||
|
"a {\n color: unit(1)\n}\n",
|
||||||
|
"a {\n color: \"\";\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
unit_non_numeric,
|
||||||
|
"a {\n color: unit(red)\n}\n",
|
||||||
|
"a {\n color: \"\";\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
unit_named_args,
|
||||||
|
"a {\n color: unit($number: 1px)\n}\n",
|
||||||
|
"a {\n color: \"px\";\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user