Browse Source

Merge pull request #255 from ErichDonGubler/sass-folders

Preserve folder structure of SCSS content
index-subcmd
Vincent Prouillet GitHub 6 years ago
parent
commit
ac8f3a6353
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 10 deletions
  1. +17
    -9
      components/site/src/lib.rs
  2. +11
    -1
      components/site/tests/site.rs
  3. +0
    -0
      test_site/sass/nested_sass/sass.sass
  4. +0
    -0
      test_site/sass/nested_sass/scss.scss
  5. +0
    -0
      test_site/sass/sass.sass
  6. +0
    -0
      test_site/sass/scss.scss

+ 17
- 9
components/site/src/lib.rs View File

@@ -528,11 +528,16 @@ impl Site {
self.copy_static_directories()
}

pub fn compile_sass(&self, base_path: &PathBuf) -> Result<()> {
pub fn compile_sass(&self, base_path: &Path) -> Result<()> {
ensure_directory_exists(&self.output_path)?;

let base_path = base_path.to_string_lossy().replace("\\", "/");
let sass_glob = format!("{}/{}", base_path, "sass/**/*.scss");
let sass_path = {
let mut sass_path = PathBuf::from(base_path);
sass_path.push("sass");
sass_path
};

let sass_glob = format!("{}/**/*.scss", sass_path.display());
let files = glob(&sass_glob)
.unwrap()
.filter_map(|e| e.ok())
@@ -542,13 +547,16 @@ impl Site {
let mut sass_options = Options::default();
sass_options.output_style = OutputStyle::Compressed;
for file in files {
let name = file.as_path().file_stem().unwrap().to_string_lossy();
let css = match compile_file(file.as_path(), sass_options.clone()) {
Ok(c) => c,
Err(e) => bail!(e)
};
let css = compile_file(&file, sass_options.clone())?;

create_file(&self.output_path.join(format!("{}.css", name)), &css)?;
let path_inside_sass = file.strip_prefix(&sass_path).unwrap();
let parent_inside_sass = path_inside_sass.parent();
let css_output_path = self.output_path.join(path_inside_sass).with_extension("css");

if parent_inside_sass.is_some() {
create_dir_all(&css_output_path.parent().unwrap())?;
}
create_file(&css_output_path, &css)?;
}

Ok(())


+ 11
- 1
components/site/tests/site.rs View File

@@ -100,7 +100,7 @@ fn can_build_site_without_live_reload() {
site.set_output_path(&public);
site.build().unwrap();

assert!(Path::new(&public).exists());
assert!(&public.exists());
assert!(file_exists!(public, "index.html"));
assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt"));
@@ -140,6 +140,16 @@ fn can_build_site_without_live_reload() {
assert!(file_exists!(public, "sample.css"));
assert!(file_exists!(public, "some.js"));

// SASS and SCSS files compile correctly
assert!(file_exists!(public, "blog.css"));
assert!(file_contains!(public, "blog.css", "red"));
assert!(file_contains!(public, "blog.css", "blue"));
assert!(!file_contains!(public, "blog.css", "@import \"included\""));
assert!(file_contains!(public, "blog.css", "2rem")); // check include
assert!(!file_exists!(public, "_included.css"));
assert!(file_exists!(public, "scss.css"));
assert!(file_exists!(public, "nested_sass/scss.css"));

// no live reload code
assert_eq!(file_contains!(public, "index.html", "/livereload.js?port=1112&mindelay=10"), false);



+ 0
- 0
test_site/sass/nested_sass/sass.sass View File


+ 0
- 0
test_site/sass/nested_sass/scss.scss View File


+ 0
- 0
test_site/sass/sass.sass View File


+ 0
- 0
test_site/sass/scss.scss View File


Loading…
Cancel
Save