diff options
author | Bao Trinh <qubidt@gmail.com> | 2023-07-21 00:14:15 +0000 |
---|---|---|
committer | Bao Trinh <qubidt@gmail.com> | 2023-07-21 00:14:15 +0000 |
commit | e84ca11eab6636904a42636455ea2cbe239fd1f4 (patch) | |
tree | 5f6935ea3a230a5d70555f78a943a435d2ff14d8 | |
parent | remove commented code (diff) | |
download | miniserve-e84ca11eab6636904a42636455ea2cbe239fd1f4.tar.gz miniserve-e84ca11eab6636904a42636455ea2cbe239fd1f4.zip |
use grass include macro; remove build.rs
-rw-r--r-- | Cargo.lock | 22 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | build.rs | 40 | ||||
-rw-r--r-- | data/style.scss | 9 | ||||
-rw-r--r-- | data/themes/archlinux.scss | 8 | ||||
-rw-r--r-- | data/themes/monokai.scss | 8 | ||||
-rw-r--r-- | data/themes/squirrel.scss | 8 | ||||
-rw-r--r-- | data/themes/zenburn.scss | 8 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/renderer.rs | 8 |
10 files changed, 60 insertions, 57 deletions
@@ -1102,24 +1102,27 @@ dependencies = [ [[package]] name = "grass" -version = "0.12.4" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cc4b64880a2264a41f9eab431780e72a68a6c88b9bddef361ba638812d572e" +checksum = "7746cd9bf09f9bb7d98638774a70642000356f543898d9a352cd043f82744528" dependencies = [ + "clap", "grass_compiler", + "include_sass", ] [[package]] name = "grass_compiler" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e4feeef87d958eebd4d55431040768b93a5b088202198e0b203adc3c1d468c6" +checksum = "187adfc0b34289c7f8f3819453ce9da3177c3d73f40ac74bb17faba578813d45" dependencies = [ "codemap", "indexmap", "lasso", "once_cell", "phf", + "rand", ] [[package]] @@ -1327,6 +1330,17 @@ dependencies = [ ] [[package]] +name = "include_sass" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a09c0170cacc99c494307c6482e81653a8fb767c605ee7cf8febd53d9e72ed6" +dependencies = [ + "grass_compiler", + "quote", + "syn 1.0.109", +] + +[[package]] name = "indexmap" version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -35,6 +35,7 @@ colored = "2" comrak = { version = "0.18", default-features = false } fast_qr = { version = "0.9", features = ["svg"] } futures = "0.3" +grass = { version = "0.13", features = ["macro"] } hex = "0.4" http = "0.2" httparse = "1" @@ -80,6 +81,3 @@ url = "2" [target.'cfg(not(windows))'.dev-dependencies] # fake_tty does not support Windows for now fake-tty = "0.3.1" - -[build-dependencies] -grass = { version = "0.12", default-features = false } diff --git a/build.rs b/build.rs deleted file mode 100644 index 75cc3e2..0000000 --- a/build.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::env; -use std::fs; -use std::path::Path; - -const THEMES: &[&str] = &["squirrel", "archlinux", "zenburn", "monokai"]; - -fn main() { - let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR env var missing"); - - let dest_path = Path::new(&out_dir).join("style.css"); - fs::write( - dest_path, - grass::from_path("data/style.scss", &grass::Options::default()) - .expect("scss failed to compile"), - ) - .expect("failed to write css file"); - - for theme in THEMES.iter() { - let dest_path = Path::new(&out_dir).join(format!("theme-{}.css", theme)); - fs::write( - dest_path, - grass::from_string( - format!( - r#" - @use "data/themes/{theme}"; - body:not([data-theme]) {{ - @include {theme}.theme(); - }} - "#, - theme = theme - ), - &grass::Options::default(), - ) - .expect("scss failed to compile"), - ) - .expect("failed to write css file"); - } - - println!("cargo:rerun-if-changed=data/style.scss"); -} diff --git a/data/style.scss b/data/style.scss index 6276708..909dc6f 100644 --- a/data/style.scss +++ b/data/style.scss @@ -1,8 +1,7 @@ -@use "sass:selector"; -@use "themes/archlinux"; -@use "themes/monokai"; -@use "themes/squirrel"; -@use "themes/zenburn"; +@use "themes/archlinux" with ($generate_default: false); +@use "themes/monokai" with ($generate_default: false); +@use "themes/squirrel" with ($generate_default: false); +@use "themes/zenburn" with ($generate_default: false); // theme colors can be found at the bottom $themes: squirrel, archlinux, monokai, zenburn; diff --git a/data/themes/archlinux.scss b/data/themes/archlinux.scss index f0504ed..f95b8bb 100644 --- a/data/themes/archlinux.scss +++ b/data/themes/archlinux.scss @@ -1,3 +1,5 @@ +$generate_default: true !default; + @mixin theme { --background: #383c4a; --text_color: #fefefe; @@ -43,4 +45,10 @@ --size_text_color: #fefefe; --error_color: #e44b4b; --footer_color: #8eabcc; +}; + +@if $generate_default { + body { + @include theme; + } } diff --git a/data/themes/monokai.scss b/data/themes/monokai.scss index b477f2d..4a47794 100644 --- a/data/themes/monokai.scss +++ b/data/themes/monokai.scss @@ -1,3 +1,5 @@ +$generate_default: true !default; + @mixin theme { --background: #272822; --text_color: #f8f8f2; @@ -43,4 +45,10 @@ --size_text_color: #f8f8f2; --error_color: #d02929; --footer_color: #56c9df; +}; + +@if $generate_default { + body { + @include theme; + } } diff --git a/data/themes/squirrel.scss b/data/themes/squirrel.scss index 65aea8b..9eb572e 100644 --- a/data/themes/squirrel.scss +++ b/data/themes/squirrel.scss @@ -1,3 +1,5 @@ +$generate_default: true !default; + @mixin theme { --background: #ffffff; --text_color: #323232; @@ -43,4 +45,10 @@ --size_text_color: #ffffff; --error_color: #d02424; --footer_color: #898989; +}; + +@if $generate_default { + body { + @include theme; + } } diff --git a/data/themes/zenburn.scss b/data/themes/zenburn.scss index 5c64892..9eb4d11 100644 --- a/data/themes/zenburn.scss +++ b/data/themes/zenburn.scss @@ -1,3 +1,5 @@ +$generate_default: true !default; + @mixin theme { --background: #3f3f3f; --text_color: #efefef; @@ -43,4 +45,10 @@ --size_text_color: #efefef; --error_color: #d06565; --footer_color: #bfaf9f; +}; + +@if $generate_default { + body { + @include theme; + } } diff --git a/src/main.rs b/src/main.rs index 33b0699..851f9ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ mod renderer; use crate::config::MiniserveConfig; use crate::errors::ContextualError; -static STYLESHEET: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css")); +static STYLESHEET: &str = grass::include!("data/style.scss"); fn main() -> Result<()> { let args = args::CliArgs::parse(); diff --git a/src/renderer.rs b/src/renderer.rs index 29418da..946089d 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -347,10 +347,10 @@ pub enum ThemeSlug { impl ThemeSlug { pub fn css(&self) -> &str { match self { - ThemeSlug::Squirrel => include_str!(concat!(env!("OUT_DIR"), "/theme-squirrel.css")), - ThemeSlug::Archlinux => include_str!(concat!(env!("OUT_DIR"), "/theme-archlinux.css")), - ThemeSlug::Zenburn => include_str!(concat!(env!("OUT_DIR"), "/theme-zenburn.css")), - ThemeSlug::Monokai => include_str!(concat!(env!("OUT_DIR"), "/theme-monokai.css")), + ThemeSlug::Squirrel => grass::include!("data/themes/squirrel.scss"), + ThemeSlug::Archlinux => grass::include!("data/themes/archlinux.scss"), + ThemeSlug::Zenburn => grass::include!("data/themes/zenburn.scss"), + ThemeSlug::Monokai => grass::include!("data/themes/monokai.scss"), } } |