Allow site path to contain underscores (#1162)

* Allow site path to contain underscores

Fixes site.css is not being generated if any part of the path contains
underscores

* Add tests for path with underscores
This commit is contained in:
bemyak 2020-09-09 09:20:55 +03:00 committed by Vincent Prouillet
parent 5a61139719
commit d9396213de
2 changed files with 46 additions and 8 deletions

View file

@ -44,14 +44,7 @@ fn compile_sass_glob(
extension: &str,
options: &Options,
) -> Result<Vec<(PathBuf, PathBuf)>> {
let glob_string = format!("{}/**/*.{}", sass_path.display(), extension);
let files = glob(&glob_string)
.expect("Invalid glob for sass")
.filter_map(|e| e.ok())
.filter(|entry| {
!entry.as_path().components().any(|c| c.as_os_str().to_string_lossy().starts_with('_'))
})
.collect::<Vec<_>>();
let files = get_non_partial_scss(sass_path, extension);
let mut compiled_paths = Vec::new();
for file in files {
@ -71,3 +64,48 @@ fn compile_sass_glob(
Ok(compiled_paths)
}
fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {
let glob_string = format!("{}/**/*.{}", sass_path.display(), extension);
glob(&glob_string)
.expect("Invalid glob for sass")
.filter_map(|e| e.ok())
.filter(|entry| {
!entry
.as_path()
.iter()
.last()
.map(|c| c.to_string_lossy().starts_with('_'))
.unwrap_or(true)
})
.collect::<Vec<_>>()
}
#[test]
fn test_get_non_partial_scss() {
use std::env;
let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
path.push("test_site");
path.push("sass");
let result = get_non_partial_scss(&path, "scss");
assert!(result.len() != 0);
assert!(result.iter().filter_map(|path| path.file_name()).any(|file| file == "scss.scss"))
}
#[test]
fn test_get_non_partial_scss_underscores() {
use std::env;
let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
path.push("test_site");
path.push("_dir_with_underscores");
path.push("..");
path.push("sass");
let result = get_non_partial_scss(&path, "scss");
assert!(result.len() != 0);
assert!(result.iter().filter_map(|path| path.file_name()).any(|file| file == "scss.scss"))
}

View file