Merge pull request #264 from ErichDonGubler/sass-indented-syntax
Make indented syntax available for SASS via the "sass" file extension
This commit is contained in:
commit
d0137377d5
|
@ -28,7 +28,7 @@ use std::path::{Path, PathBuf};
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use tera::{Tera, Context};
|
use tera::{Tera, Context};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use sass_rs::{Options, OutputStyle, compile_file};
|
use sass_rs::{Options as SassOptions, OutputStyle, compile_file};
|
||||||
|
|
||||||
use errors::{Result, ResultExt};
|
use errors::{Result, ResultExt};
|
||||||
use config::{Config, get_config};
|
use config::{Config, get_config};
|
||||||
|
@ -534,17 +534,39 @@ impl Site {
|
||||||
sass_path
|
sass_path
|
||||||
};
|
};
|
||||||
|
|
||||||
let sass_glob = format!("{}/**/*.scss", sass_path.display());
|
let mut options = SassOptions::default();
|
||||||
let files = glob(&sass_glob)
|
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: SassOptions) -> Result<Vec<(PathBuf, PathBuf)>> {
|
||||||
|
let glob_string = format!("{}/**/*.{}", sass_path.display(), extension);
|
||||||
|
let files = glob(&glob_string)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.filter(|entry| !entry.as_path().file_name().unwrap().to_string_lossy().starts_with('_'))
|
.filter(|entry| !entry.as_path().file_name().unwrap().to_string_lossy().starts_with('_'))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut sass_options = Options::default();
|
let mut compiled_paths = Vec::new();
|
||||||
sass_options.output_style = OutputStyle::Compressed;
|
|
||||||
for file in files {
|
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 path_inside_sass = file.strip_prefix(&sass_path).unwrap();
|
||||||
let parent_inside_sass = path_inside_sass.parent();
|
let parent_inside_sass = path_inside_sass.parent();
|
||||||
|
@ -553,10 +575,12 @@ impl Site {
|
||||||
if parent_inside_sass.is_some() {
|
if parent_inside_sass.is_some() {
|
||||||
create_dir_all(&css_output_path.parent().unwrap())?;
|
create_dir_all(&css_output_path.parent().unwrap())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(&css_output_path, &css)?;
|
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<()> {
|
pub fn render_aliases(&self) -> Result<()> {
|
||||||
|
|
|
@ -148,6 +148,8 @@ fn can_build_site_without_live_reload() {
|
||||||
assert!(file_contains!(public, "blog.css", "2rem")); // check include
|
assert!(file_contains!(public, "blog.css", "2rem")); // check include
|
||||||
assert!(!file_exists!(public, "_included.css"));
|
assert!(!file_exists!(public, "_included.css"));
|
||||||
assert!(file_exists!(public, "scss.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"));
|
assert!(file_exists!(public, "nested_sass/scss.css"));
|
||||||
|
|
||||||
// no live reload code
|
// no live reload code
|
||||||
|
|
Loading…
Reference in New Issue