Compile and embed scss
This commit is contained in:
parent
a7d0961d3c
commit
e663bfee4e
5 changed files with 187 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -115,3 +115,6 @@ lib/
|
|||
|
||||
### Other ###
|
||||
test-files/output.pdf
|
||||
|
||||
#### Static Assets ###
|
||||
assets/style.css
|
||||
|
|
66
Cargo.lock
generated
66
Cargo.lock
generated
|
@ -6,6 +6,7 @@ dependencies = [
|
|||
"include_dir 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mktemp 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pandoc 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rsass 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sciter-rs 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -251,6 +252,14 @@ name = "matches"
|
|||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz-sys"
|
||||
version = "0.1.9"
|
||||
|
@ -278,6 +287,44 @@ dependencies = [
|
|||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "3.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.1.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.1.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-bigint 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.40"
|
||||
|
@ -351,6 +398,19 @@ name = "redox_syscall"
|
|||
version = "0.1.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rsass"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.5"
|
||||
|
@ -602,9 +662,14 @@ dependencies = [
|
|||
"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699"
|
||||
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
|
||||
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
|
||||
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
|
||||
"checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726"
|
||||
"checksum mktemp 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77001ceb9eed65439f3dc2a2543f9ba1417d912686bf224a7738d0966e6dcd69"
|
||||
"checksum msdos_time 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "65ba9d75bcea84e07812618fedf284a64776c2f2ea0cad6bca7f69739695a958"
|
||||
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
|
||||
"checksum num-bigint 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "8fd0f8dbb4c0960998958a796281d88c16fbe68d87b1baa6f31e2979e81fd0bd"
|
||||
"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba"
|
||||
"checksum num-rational 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "0c7cb72a95250d8a370105c828f388932373e0e94414919891a0f945222310fe"
|
||||
"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0"
|
||||
"checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e"
|
||||
"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
|
||||
|
@ -616,6 +681,7 @@ dependencies = [
|
|||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf"
|
||||
"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509"
|
||||
"checksum rsass 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b38a5a27b41ad6cf49ffe8d778ef3213bab8f270b8fdd7e43c12d147aa933172"
|
||||
"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
|
||||
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||
"checksum sciter-rs 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ca8ac2fcc3a52718253633821182a7d257360bc39ce0b7fcf81c50f8dcccab"
|
||||
|
|
|
@ -17,6 +17,7 @@ zip = "0.2.6"
|
|||
|
||||
[build-dependencies]
|
||||
include_dir = "0.1.3"
|
||||
rsass = "0.5.0"
|
||||
|
||||
[profile.dev]
|
||||
rpath = true
|
||||
|
|
27
build.rs
27
build.rs
|
@ -1,12 +1,33 @@
|
|||
extern crate include_dir;
|
||||
extern crate rsass;
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use include_dir::include_dir;
|
||||
use rsass::{OutputStyle, compile_scss};
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
fn main() {
|
||||
const ASSETS_DIR: &str = "assets";
|
||||
const ASSET_KEY: &str = "SRC";
|
||||
const STATIC_DIR: &str = "static";
|
||||
|
||||
fn build_stylesheet() {
|
||||
let mut in_file = File::open("static/style.scss").expect("Failed to open scss file");
|
||||
let mut buffer = Vec::new();
|
||||
in_file.read_to_end(&mut buffer).expect("Failed to read scss");
|
||||
let compiled = compile_scss(buffer.as_slice(), OutputStyle::Compressed).expect("SCSS compiler failed");
|
||||
let mut out_file = File::create("assets/style.css").expect("Failed to open css file");
|
||||
out_file.write_all(&mut compiled.as_slice()).expect("Failed to write css to file");
|
||||
}
|
||||
|
||||
fn embed_assets() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("assets.rs");
|
||||
|
||||
include_dir("assets").as_variable("SRC").to_file(dest_path).unwrap();
|
||||
include_dir(ASSETS_DIR).as_variable(ASSET_KEY).to_file(dest_path).unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
build_stylesheet();
|
||||
embed_assets();
|
||||
}
|
||||
|
|
93
static/style.scss
Normal file
93
static/style.scss
Normal file
|
@ -0,0 +1,93 @@
|
|||
$image-spacing: 30px;
|
||||
$font-size-base: 12px;
|
||||
|
||||
body.cover {
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
|
||||
& h1 {
|
||||
padding-top: 300px;
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
& h3 {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
& h4 {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
body.content {
|
||||
line-height: 1.5;
|
||||
font-size: $font-size-base;
|
||||
|
||||
img {
|
||||
margin-top: $image-spacing;
|
||||
width: 100%;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
p.caption {
|
||||
margin: 1px 5px $image-spacing;
|
||||
padding: 0;
|
||||
font-style: italic;
|
||||
page-break-before: avoid;
|
||||
}
|
||||
|
||||
.references-title {
|
||||
page-break-before: always;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
code {
|
||||
white-space: inherit !important;
|
||||
}
|
||||
}
|
||||
|
||||
body.footer, body.header {
|
||||
font-size: $font-size-base;
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
|
||||
td {
|
||||
width: 33%;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.tocs {
|
||||
h1 {
|
||||
margin-bottom: 45px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.row {
|
||||
margin-bottom: $font-size-base;
|
||||
border-bottom: 1px dashed black;
|
||||
font-size: $font-size-base * 1.5;
|
||||
}
|
||||
|
||||
.page-number {
|
||||
float: right;
|
||||
padding-right: $font-size-base * 0.5;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 0;
|
||||
|
||||
li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: $font-size-base;
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue