Factor out scss handling into it's own module
This commit is contained in:
parent
89ea0a1fbc
commit
d3b94cc76e
5 changed files with 21 additions and 16 deletions
|
@ -139,7 +139,7 @@ impl App {
|
|||
if let Err(e) = config_result.and_then(|new_config| self.load_config(new_config)) {
|
||||
errors.push(e)
|
||||
}
|
||||
let css_result = crate::util::parse_scss_from_file(&self.paths.get_eww_scss_path());
|
||||
let css_result = crate::config::scss::parse_scss_from_file(&self.paths.get_eww_scss_path());
|
||||
if let Err(e) = css_result.and_then(|css| self.load_css(&css)) {
|
||||
errors.push(e)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
pub mod eww_config;
|
||||
pub mod inbuilt;
|
||||
pub mod script_var;
|
||||
pub mod scss;
|
||||
pub mod system_stats;
|
||||
pub mod window_definition;
|
||||
pub use eww_config::*;
|
||||
|
|
16
crates/eww/src/config/scss.rs
Normal file
16
crates/eww/src/config/scss.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::{anyhow, Context};
|
||||
|
||||
use crate::util::replace_env_var_references;
|
||||
|
||||
/// read an scss file, replace all environment variable references within it and
|
||||
/// then parse it into css.
|
||||
pub fn parse_scss_from_file(path: &Path) -> anyhow::Result<String> {
|
||||
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 doesn't 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))
|
||||
}
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
app::{self, DaemonCommand},
|
||||
config, daemon_response, error_handling_ctx, ipc_server, script_var_handler,
|
||||
state::scope_graph::ScopeGraph,
|
||||
util, EwwPaths,
|
||||
EwwPaths,
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
|
@ -83,7 +83,7 @@ pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>, should_
|
|||
gtk::StyleContext::add_provider_for_screen(&screen, &app.css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
|
||||
if let Ok(eww_css) = util::parse_scss_from_file(&app.paths.get_eww_scss_path()) {
|
||||
if let Ok(eww_css) = config::scss::parse_scss_from_file(&app.paths.get_eww_scss_path()) {
|
||||
app.load_css(&eww_css)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use extend::ext;
|
||||
use itertools::Itertools;
|
||||
use std::{fmt::Write, path::Path};
|
||||
use std::fmt::Write;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! try_logging_errors {
|
||||
|
@ -83,17 +82,6 @@ pub fn list_difference<'a, 'b, T: PartialEq>(a: &'a [T], b: &'b [T]) -> (Vec<&'a
|
|||
(missing, new)
|
||||
}
|
||||
|
||||
/// read an scss file, replace all environment variable references within it and
|
||||
/// then parse it into css.
|
||||
pub fn parse_scss_from_file(path: &Path) -> Result<String> {
|
||||
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)]
|
||||
impl<T: AsRef<str>> T {
|
||||
/// check if the string is empty after removing all linebreaks and trimming
|
||||
|
|
Loading…
Add table
Reference in a new issue