Skip to content

Commit

Permalink
Fix file paths for @import in scss.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Jun 5, 2017
1 parent e47afcf commit 6d47150
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy_static = "^0.2"
md5 = "^0.3"
nom = { version = "^2", features = ["verbose-errors"] }

rsass = { version = "^0.3.2", optional = true }
rsass = { version = "^0.3.4", optional = true }

[badges]
travis-ci = { repository = "kaj/ructe" }
3 changes: 3 additions & 0 deletions examples/static-sass/scss/foo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
greeting {
hello: world;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
body {
background: static_name("burlap.jpg");
}

// For importing, paths are relative to the file containing the @import.
@import "foo.scss";
2 changes: 1 addition & 1 deletion examples/static-sass/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
let base_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut statics = StaticFiles::new(&out_dir).unwrap();
statics.add_files(&base_dir.join("static")).unwrap();
statics.add_sass_file("style.scss".as_ref()).unwrap();
statics.add_sass_file("scss/style.scss".as_ref()).unwrap();

let template_dir = base_dir.join("templates");
compile_templates(&template_dir, &out_dir).expect("templates");
Expand Down
11 changes: 6 additions & 5 deletions examples/static-sass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod test {
<head>\n \
<title>Example with stylesheet</title>\n \
<link rel=\"stylesheet\" \
href=\"/static/style-YntjOhkp.css\" \
href=\"/static/style-dp91gNUn.css\" \
type=\"text/css\"/>\n \
</head>\n \
<body>\n \
Expand All @@ -40,14 +40,15 @@ mod test {
use templates::statics::style_css;
use std::str::from_utf8;
assert_eq!(from_utf8(&style_css.content).unwrap(),
"body{background:\"burlap-oPfjAg2n.jpg\"}\n");
"body{background:\"burlap-oPfjAg2n.jpg\"}\
greeting{hello:world}\n");
}

#[test]
fn get_static_by_name() {
use templates::statics::StaticFile;
assert_eq!(StaticFile::get("style-YntjOhkp.css").map(|s| s.name),
Some("style-YntjOhkp.css"))
assert_eq!(StaticFile::get("style-dp91gNUn.css").map(|s| s.name),
Some("style-dp91gNUn.css"))
}

#[test]
Expand All @@ -60,7 +61,7 @@ mod test {
fn all_statics_known() {
use templates::statics::STATICS;
assert_eq!(STATICS.iter().map(|s| s.name).collect::<Vec<_>>(),
["burlap-oPfjAg2n.jpg", "style-YntjOhkp.css"]);
["burlap-oPfjAg2n.jpg", "style-dp91gNUn.css"]);
}

fn r2s<Call>(call: Call) -> String
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ impl StaticFiles {
}
})));

let scss = parse_scss_file(src).unwrap();
let style = OutputStyle::Compressed;
let file_context = FileContext::new();
let (file_context, src) = file_context.file(src);
let scss = parse_scss_file(&src).unwrap();
let style = OutputStyle::Compressed;
let css = style.write_root(&scss, &mut scope, file_context).unwrap();
self.add_file_data(&src.with_extension("css"), &css)
}
Expand Down

0 comments on commit 6d47150

Please sign in to comment.