refactor @ import
based on code review by @pickfire here, https://github.com/connorskees/grass/pull/13
This commit is contained in:
parent
74971a7d62
commit
191f2dfba4
@ -1,8 +1,4 @@
|
|||||||
use std::{
|
use std::{ffi::OsStr, fs, path::Path};
|
||||||
ffi::{OsStr, OsString},
|
|
||||||
fs,
|
|
||||||
path::Path,
|
|
||||||
};
|
|
||||||
|
|
||||||
use peekmore::PeekMore;
|
use peekmore::PeekMore;
|
||||||
|
|
||||||
@ -42,7 +38,6 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
let path: &Path = file_name.as_ref();
|
let path: &Path = file_name.as_ref();
|
||||||
|
|
||||||
let mut rules = Vec::new();
|
|
||||||
let path_buf = if path.is_absolute() {
|
let path_buf = if path.is_absolute() {
|
||||||
// todo: test for absolute path imports
|
// todo: test for absolute path imports
|
||||||
path.into()
|
path.into()
|
||||||
@ -58,24 +53,23 @@ impl<'a> Parser<'a> {
|
|||||||
// || name.starts_with("http://") || name.starts_with("https://") {
|
// || name.starts_with("http://") || name.starts_with("https://") {
|
||||||
todo!("css imports")
|
todo!("css imports")
|
||||||
}
|
}
|
||||||
let mut p1 = path_buf.clone();
|
|
||||||
p1.push(OsString::from("index.scss"));
|
|
||||||
let mut p2 = path_buf.clone();
|
|
||||||
p2.push(OsString::from("_index.scss"));
|
|
||||||
let paths = [
|
let paths = [
|
||||||
path_buf.with_file_name(name).with_extension("scss"),
|
path_buf.with_file_name(name).with_extension("scss"),
|
||||||
path_buf.with_file_name(format!("_{}.scss", name.to_str().unwrap())),
|
path_buf.with_file_name(format!("_{}.scss", name.to_str().unwrap())),
|
||||||
path_buf,
|
path_buf.clone(),
|
||||||
p1,
|
path_buf.clone().join("index.scss"),
|
||||||
p2,
|
path_buf.clone().join("_index.scss"),
|
||||||
];
|
];
|
||||||
|
|
||||||
for name in &paths {
|
for name in &paths {
|
||||||
if name.is_file() {
|
if name.is_file() {
|
||||||
let file = self.map.add_file(
|
let file = self.map.add_file(
|
||||||
name.to_string_lossy().into(),
|
name.to_string_lossy().into(),
|
||||||
String::from_utf8(fs::read(name)?)?,
|
String::from_utf8(fs::read(name)?)?,
|
||||||
);
|
);
|
||||||
let rules2 = Parser {
|
|
||||||
|
return Parser {
|
||||||
toks: &mut Lexer::new(&file)
|
toks: &mut Lexer::new(&file)
|
||||||
.collect::<Vec<Token>>()
|
.collect::<Vec<Token>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -93,13 +87,10 @@ impl<'a> Parser<'a> {
|
|||||||
at_root: self.at_root,
|
at_root: self.at_root,
|
||||||
at_root_has_selector: self.at_root_has_selector,
|
at_root_has_selector: self.at_root_has_selector,
|
||||||
}
|
}
|
||||||
.parse()?;
|
.parse();
|
||||||
|
|
||||||
rules.extend(rules2);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(rules)
|
Ok(Vec::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@ impl SassMap {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.0.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn remove(&mut self, key: &Value) {
|
pub fn remove(&mut self, key: &Value) {
|
||||||
self.0.retain(|(ref k, ..)| k != key);
|
self.0.retain(|(ref k, ..)| k != key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user