2020-01-18 15:47:51 -05:00
|
|
|
use crate::common::Scope;
|
|
|
|
use crate::{Stmt, StyleSheet};
|
2020-01-18 18:36:00 -05:00
|
|
|
use std::ffi::OsStr;
|
2020-01-18 15:47:51 -05:00
|
|
|
use std::path::Path;
|
2020-01-11 18:42:42 -05:00
|
|
|
|
2020-01-18 18:08:32 -05:00
|
|
|
pub fn import<P: AsRef<Path>>(name: P) -> (Vec<Stmt>, Scope) {
|
2020-01-18 15:47:51 -05:00
|
|
|
let mut rules: Vec<Stmt> = Vec::new();
|
|
|
|
let mut scope = Scope::new();
|
2020-01-18 18:08:32 -05:00
|
|
|
let path = name.as_ref().to_path_buf();
|
|
|
|
let name = path.file_name().unwrap();
|
2020-01-18 18:36:00 -05:00
|
|
|
if path.extension() == Some(OsStr::new(".css")) {
|
2020-01-18 18:12:53 -05:00
|
|
|
// || name.starts_with("http://") || name.starts_with("https://") {
|
2020-01-18 18:08:32 -05:00
|
|
|
todo!("handle css imports")
|
|
|
|
}
|
|
|
|
let mut p1 = path.clone();
|
|
|
|
p1.push("/index.scss");
|
|
|
|
let mut p2 = path.clone();
|
|
|
|
p2.push("/_index.scss");
|
|
|
|
let paths = [
|
|
|
|
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();
|
2020-01-18 15:47:51 -05:00
|
|
|
rules.extend(rules2);
|
|
|
|
scope.merge(scope2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(rules, scope)
|
2020-01-11 19:16:59 -05:00
|
|
|
}
|