Properly interpolate all path variants
This commit is contained in:
parent
0485256115
commit
0d9d1fc234
@ -2,20 +2,28 @@ use crate::common::Scope;
|
|||||||
use crate::{Stmt, StyleSheet};
|
use crate::{Stmt, StyleSheet};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn import(name: String) -> (Vec<Stmt>, Scope) {
|
pub fn import<P: AsRef<Path>>(name: P) -> (Vec<Stmt>, Scope) {
|
||||||
let mut rules: Vec<Stmt> = Vec::new();
|
let mut rules: Vec<Stmt> = Vec::new();
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
for name in &[
|
let path = name.as_ref().to_path_buf();
|
||||||
&name,
|
let name = path.file_name().unwrap();
|
||||||
&format!("{}.scss", name),
|
if path.extension() == Some(std::ffi::OsStr::new(".css")) {// || name.starts_with("http://") || name.starts_with("https://") {
|
||||||
&format!("_{}.scss", name),
|
todo!("handle css imports")
|
||||||
&format!("{}/index.scss", name),
|
}
|
||||||
&format!("{}/_index.scss", name),
|
let mut p1 = path.clone();
|
||||||
&format!("{}.css", name),
|
p1.push("/index.scss");
|
||||||
] {
|
let mut p2 = path.clone();
|
||||||
let p = Path::new(&name);
|
p2.push("/_index.scss");
|
||||||
if p.exists() && p.is_file() {
|
let paths = [
|
||||||
let (rules2, scope2) = StyleSheet::export_from_path(*name).unwrap();
|
path.with_file_name(format!("{}.scss", name.to_str().unwrap())),
|
||||||
|
path.with_file_name(format!("_{}.scss", name.to_str().unwrap())),
|
||||||
|
path,
|
||||||
|
p1,
|
||||||
|
p2,
|
||||||
|
];
|
||||||
|
for name in &paths {
|
||||||
|
if name.is_file() {
|
||||||
|
let (rules2, scope2) = StyleSheet::export_from_path(name.to_str().unwrap()).unwrap();
|
||||||
rules.extend(rules2);
|
rules.extend(rules2);
|
||||||
scope.merge(scope2);
|
scope.merge(scope2);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user