Skip to content

Commit

Permalink
Allow site path to contain underscores (#1162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bemyak authored and Keats committed Sep 22, 2020
1 parent 5a61139 commit d939621
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions components/site/src/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"))
}
Empty file.

0 comments on commit d939621

Please sign in to comment.