grass/src/imports.rs

25 lines
696 B
Rust
Raw Normal View History

2020-01-18 15:47:51 -05:00
use crate::common::Scope;
use crate::{Stmt, StyleSheet};
use std::path::Path;
2020-01-11 18:42:42 -05:00
2020-01-18 15:47:51 -05:00
pub fn import(name: String) -> (Vec<Stmt>, Scope) {
let mut rules: Vec<Stmt> = Vec::new();
let mut scope = Scope::new();
for name in &[
&name,
&format!("{}.scss", name),
&format!("_{}.scss", name),
&format!("{}/index.scss", name),
&format!("{}/_index.scss", name),
&format!("{}.css", name),
] {
let p = Path::new(&name);
if p.exists() && p.is_file() {
let (rules2, scope2) = StyleSheet::export_from_path(*name).unwrap();
rules.extend(rules2);
scope.merge(scope2);
}
}
(rules, scope)
2020-01-11 19:16:59 -05:00
}