Implement builtin function list-separator()
This commit is contained in:
parent
dd1c1e5b06
commit
284bc8ea6d
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
|||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
|
use crate::common::{ListSeparator, QuoteKind};
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
@ -55,4 +56,18 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
f.insert(
|
||||||
|
"list-separator".to_owned(),
|
||||||
|
Box::new(|args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
|
Ok(Value::Ident(
|
||||||
|
match arg!(args, 0, "list") {
|
||||||
|
Value::List(_, sep) => sep.name(),
|
||||||
|
_ => ListSeparator::Space.name(),
|
||||||
|
}
|
||||||
|
.to_owned(),
|
||||||
|
QuoteKind::None,
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -382,8 +382,6 @@ impl ListSeparator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used in currently unimplemented builtin function
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn name(self) -> &'static str {
|
pub fn name(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Space => "space",
|
Self::Space => "space",
|
||||||
|
@ -33,3 +33,25 @@ test!(
|
|||||||
"a {\n color: nth((a, b, c), 3);\n}\n",
|
"a {\n color: nth((a, b, c), 3);\n}\n",
|
||||||
"a {\n color: c;\n}\n"
|
"a {\n color: c;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
list_separator_space_separated,
|
||||||
|
"a {\n color: list-separator(a b c);\n}\n",
|
||||||
|
"a {\n color: space;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
list_separator_foo,
|
||||||
|
"a {\n color: list-separator(foo);\n}\n",
|
||||||
|
"a {\n color: space;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
list_separator_comma_separated,
|
||||||
|
"a {\n color: list-separator((a, b, c));\n}\n",
|
||||||
|
"a {\n color: comma;\n}\n"
|
||||||
|
);
|
||||||
|
// blocked on better parsing of comma separated lists with
|
||||||
|
// space separated lists inside
|
||||||
|
// test!(
|
||||||
|
// list_separator_comma_separated_with_space,
|
||||||
|
// "a {\n color: list-separator(((a b, c d)));\n}\n",
|
||||||
|
// "a {\n color: comma;\n}\n"
|
||||||
|
// );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user