2015-09-18 18:05:55 +08:00
|
|
|
// build.rs
|
2015-12-30 19:59:19 +08:00
|
|
|
extern crate sass_rs;
|
2015-09-18 18:05:55 +08:00
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::path::Path;
|
2015-12-30 19:59:19 +08:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
2015-09-18 18:05:55 +08:00
|
|
|
|
2015-12-30 19:59:19 +08:00
|
|
|
use sass_rs::sass_context::SassFileContext;
|
2015-09-18 18:05:55 +08:00
|
|
|
|
2015-12-30 19:59:19 +08:00
|
|
|
fn main() {
|
2015-09-24 21:37:20 +08:00
|
|
|
if let Ok(_) = env::var("CARGO_FEATURE_REGENERATE_CSS") {
|
|
|
|
// Compile stylus stylesheet to css
|
|
|
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
2015-09-18 18:05:55 +08:00
|
|
|
|
2015-09-24 21:37:20 +08:00
|
|
|
let theme_dir = Path::new(&manifest_dir).join("src/theme/");
|
2015-12-30 19:59:19 +08:00
|
|
|
let scss_index_file = theme_dir.join("stylus/book.scss");
|
2015-09-24 21:37:20 +08:00
|
|
|
|
2015-12-30 19:59:19 +08:00
|
|
|
let css = SassFileContext::new(&scss_index_file.to_string_lossy())
|
|
|
|
.compile()
|
|
|
|
.expect("error compiling SCSS files");
|
|
|
|
let mut output_file = File::create(&theme_dir.join("book.css"))
|
|
|
|
.expect("error creating CSS file");
|
|
|
|
output_file.write_all(&mut css.as_bytes()).expect("error writing CSS to file");
|
2015-09-19 04:13:55 +08:00
|
|
|
}
|
2015-09-18 18:05:55 +08:00
|
|
|
}
|