handle maps in nth()
This commit is contained in:
parent
225894d0e9
commit
cba2b12771
@ -26,6 +26,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
max_args!(args, 2);
|
||||
let list = match arg!(args, 0, "list") {
|
||||
Value::List(v, ..) => v,
|
||||
Value::Map(m) => m.entries(),
|
||||
v => vec![v],
|
||||
};
|
||||
let n = match arg!(args, 1, "n") {
|
||||
|
@ -2,6 +2,7 @@ use std::slice::Iter;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use super::Value;
|
||||
use crate::common::{Brackets, ListSeparator};
|
||||
use crate::error::SassResult;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -48,6 +49,13 @@ impl SassMap {
|
||||
self.0.into_iter().map(|(.., v)| v).collect()
|
||||
}
|
||||
|
||||
pub fn entries(self) -> Vec<Value> {
|
||||
self.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| Value::List(vec![k, v], ListSeparator::Space, Brackets::None))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: Value, value: Value) {
|
||||
for &mut (ref k, ref mut v) in &mut self.0 {
|
||||
if k == &key {
|
||||
|
@ -38,6 +38,11 @@ test!(
|
||||
"a {\n color: nth(foo, 1);\n}\n",
|
||||
"a {\n color: foo;\n}\n"
|
||||
);
|
||||
test!(
|
||||
nth_map,
|
||||
"a {\n color: nth((c: d, e: f, g: h), 2);\n}\n",
|
||||
"a {\n color: e f;\n}\n"
|
||||
);
|
||||
test!(
|
||||
list_separator_space_separated,
|
||||
"a {\n color: list-separator(a b c);\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user