From d9396213de6184bd5ed74ec1f5ccd30394f46ad3 Mon Sep 17 00:00:00 2001 From: bemyak Date: Wed, 9 Sep 2020 09:20:55 +0300 Subject: [PATCH] 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 --- components/site/src/sass.rs | 54 ++++++++++++++++++++---- test_site/_dir_with_underscores/.gitkeep | 0 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 test_site/_dir_with_underscores/.gitkeep diff --git a/components/site/src/sass.rs b/components/site/src/sass.rs index 2b1b1ef3..a9dc5b96 100644 --- a/components/site/src/sass.rs +++ b/components/site/src/sass.rs @@ -44,14 +44,7 @@ fn compile_sass_glob( extension: &str, options: &Options, ) -> Result> { - 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::>(); + 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 { + 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::>() +} + +#[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")) +} diff --git a/test_site/_dir_with_underscores/.gitkeep b/test_site/_dir_with_underscores/.gitkeep new file mode 100644 index 00000000..e69de29b