archive
/
md-pdf-rs
Archived
1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf-rs/build.rs

37 lines
1.1 KiB
Rust
Raw Normal View History

2017-09-06 21:40:48 +01:00
extern crate include_dir;
2017-11-26 14:17:21 +00:00
extern crate rsass;
2017-09-06 21:40:48 +01:00
use std::env;
use std::path::Path;
use include_dir::include_dir;
2017-11-26 14:17:21 +00:00
use rsass::{OutputStyle, compile_scss};
use std::fs::File;
use std::io::{Read, Write};
2017-09-06 21:40:48 +01:00
2017-11-26 14:17:21 +00:00
const ASSETS_DIR: &str = "assets";
const ASSET_KEY: &str = "SRC";
const STATIC_DIR: &str = "static";
fn build_stylesheet() {
2017-11-26 14:23:49 +00:00
let mut in_file =
File::open(Path::new(STATIC_DIR).join("style.scss")).expect("Failed to open scss file");
2017-11-26 14:17:21 +00:00
let mut buffer = Vec::new();
in_file.read_to_end(&mut buffer).expect("Failed to read scss");
2017-11-26 14:23:49 +00:00
let compiled =
compile_scss(buffer.as_slice(), OutputStyle::Compressed).expect("SCSS compile failed");
let mut out_file =
File::create(Path::new(ASSETS_DIR).join("style.css")).expect("Failed to open css file");
2017-11-26 14:17:21 +00:00
out_file.write_all(&mut compiled.as_slice()).expect("Failed to write css to file");
}
fn embed_assets() {
2017-11-26 14:23:49 +00:00
let out_dir = env::var("OUT_DIR").expect("Missing output directory variable");
2017-09-06 21:40:48 +01:00
let dest_path = Path::new(&out_dir).join("assets.rs");
2017-11-26 14:17:21 +00:00
include_dir(ASSETS_DIR).as_variable(ASSET_KEY).to_file(dest_path).unwrap();
}
2017-09-06 21:40:48 +01:00
2017-11-26 14:17:21 +00:00
fn main() {
build_stylesheet();
embed_assets();
2017-09-06 21:40:48 +01:00
}