From 4da676e38b82db8d1ff4844376d65ada3d55772e Mon Sep 17 00:00:00 2001 From: undefinedDarkness <38278035+undefinedDarkness@users.noreply.github.com> Date: Mon, 8 Feb 2021 15:16:33 +0530 Subject: [PATCH] SCSS relative path support, set cwd of server to eww config directory (#110) --- src/main.rs | 1 + src/server.rs | 1 + src/util.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index fe41197..50305b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,7 @@ fn main() { } else { log::info!("Initializing Eww server."); let _ = std::fs::remove_file(&*crate::IPC_SOCKET_PATH); + println!("Run `eww logs` to see any errors, warnings or information while editing your configuration."); server::initialize_server(config)?; } diff --git a/src/server.rs b/src/server.rs index db4b5cf..f04750a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -26,6 +26,7 @@ pub fn initialize_server(config_dir_override: Option) -> Res .parent() .context("config file did not have a parent?!")? .to_owned(); + std::env::set_current_dir(&config_dir).with_context(|| { format!("Failed to change working directory to {}", config_dir.display()) } )?; let scss_file_path = config_dir.join("eww.scss"); log::info!("reading configuration from {:?}", &config_file_path); diff --git a/src/util.rs b/src/util.rs index 1c7c917..6c17435 100644 --- a/src/util.rs +++ b/src/util.rs @@ -52,10 +52,12 @@ macro_rules! loop_select { /// read an scss file, replace all environment variable references within it and /// then parse it into css. -pub fn parse_scss_from_file>(path: P) -> Result { - let scss_content = replace_env_var_references(std::fs::read_to_string(path)?); - grass::from_string(scss_content, &grass::Options::default()) - .map_err(|err| anyhow!("encountered SCSS parsing error: {:?}", err)) +pub fn parse_scss_from_file(path: &Path) -> Result { + let config_dir = path.parent().context("Given SCSS file has no parent directory?!")?; + let scss_file_content = std::fs::read_to_string(path).with_context(|| { format!("Given SCSS File Doesnt Exist! {}", path.display()) })?; + let file_content = replace_env_var_references(scss_file_content); + let grass_config = grass::Options::default().load_path(config_dir); + grass::from_string(file_content, &grass_config).map_err(|err| anyhow!("Encountered SCSS parsing error: {:?}", err)) } #[ext(pub, name = StringExt)]