From ea4cc63aa990e6d916766f4915e8cca978c586a6 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sat, 17 Mar 2018 12:57:03 -0600 Subject: [PATCH 1/2] Make indented syntax available for SASS via the "sass" file extension --- components/site/src/lib.rs | 31 +++++++++++++++++++++++++------ components/site/tests/site.rs | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index eaeabc59..01fd050d 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -537,17 +537,34 @@ impl Site { sass_path }; - let sass_glob = format!("{}/**/*.scss", sass_path.display()); - let files = glob(&sass_glob) + let mut options = Options::default(); + options.output_style = OutputStyle::Compressed; + let mut compiled_paths = self.compile_sass_glob(&sass_path, "scss", options.clone())?; + + options.indented_syntax = true; + compiled_paths.extend(self.compile_sass_glob(&sass_path, "sass", options)?); + + compiled_paths.sort(); + for window in compiled_paths.windows(2) { + if window[0].1 == window[1].1 { + bail!("SASS path conflict: \"{}\" and \"{}\" both compile to \"{}\"", window[0].0.display(), window[1].0.display(), window[0].1.display()); + } + } + + Ok(()) + } + + fn compile_sass_glob(&self, sass_path: &Path, extension: &str, options: Options) -> Result> { + let glob_string = format!("{}/**/*.{}", sass_path.display(), extension); + let files = glob(&glob_string) .unwrap() .filter_map(|e| e.ok()) .filter(|entry| !entry.as_path().file_name().unwrap().to_string_lossy().starts_with('_')) .collect::>(); - let mut sass_options = Options::default(); - sass_options.output_style = OutputStyle::Compressed; + let mut compiled_paths = Vec::new(); for file in files { - let css = compile_file(&file, sass_options.clone())?; + let css = compile_file(&file, options.clone())?; let path_inside_sass = file.strip_prefix(&sass_path).unwrap(); let parent_inside_sass = path_inside_sass.parent(); @@ -556,10 +573,12 @@ impl Site { if parent_inside_sass.is_some() { create_dir_all(&css_output_path.parent().unwrap())?; } + create_file(&css_output_path, &css)?; + compiled_paths.push((path_inside_sass.to_owned(), css_output_path)); } - Ok(()) + Ok(compiled_paths) } pub fn render_aliases(&self) -> Result<()> { diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 9470b116..598a4f4c 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -148,6 +148,8 @@ fn can_build_site_without_live_reload() { 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, "sass.css")); + assert!(file_exists!(public, "nested_sass/sass.css")); assert!(file_exists!(public, "nested_sass/scss.css")); // no live reload code From 0d8dc656f18a64b603781674c4bec7f19e052667 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 19 Mar 2018 10:04:48 -0600 Subject: [PATCH 2/2] CR review: s/Options/SassOptions/, break bail args in compile_sass into multiple lines --- components/site/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 01fd050d..b16a381f 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -28,7 +28,7 @@ use std::path::{Path, PathBuf}; use glob::glob; use tera::{Tera, Context}; use walkdir::WalkDir; -use sass_rs::{Options, OutputStyle, compile_file}; +use sass_rs::{Options as SassOptions, OutputStyle, compile_file}; use errors::{Result, ResultExt}; use config::{Config, get_config}; @@ -537,7 +537,7 @@ impl Site { sass_path }; - let mut options = Options::default(); + let mut options = SassOptions::default(); options.output_style = OutputStyle::Compressed; let mut compiled_paths = self.compile_sass_glob(&sass_path, "scss", options.clone())?; @@ -547,14 +547,19 @@ impl Site { compiled_paths.sort(); for window in compiled_paths.windows(2) { if window[0].1 == window[1].1 { - bail!("SASS path conflict: \"{}\" and \"{}\" both compile to \"{}\"", window[0].0.display(), window[1].0.display(), window[0].1.display()); + bail!( + "SASS path conflict: \"{}\" and \"{}\" both compile to \"{}\"", + window[0].0.display(), + window[1].0.display(), + window[0].1.display(), + ); } } Ok(()) } - fn compile_sass_glob(&self, sass_path: &Path, extension: &str, options: Options) -> Result> { + fn compile_sass_glob(&self, sass_path: &Path, extension: &str, options: SassOptions) -> Result> { let glob_string = format!("{}/**/*.{}", sass_path.display(), extension); let files = glob(&glob_string) .unwrap()