We carry around a list of stylesheets that can carry two different types of thing: 1. Internal stylesheets specific to a page type (only for settings) 2. Themes In this change I move the link generation for settings.css into settings(), so Context.style_files is reserved just for themes. We had two places where we extracted a base theme name from a list of StylePaths. I consolidated that code to be a method on StylePath. I moved generation of link tags for stylesheets into the page.html template. With that change, I made the template responsible for special handling of light.css (making it the default theme) and of the other themes (marking them disabled). That allowed getting rid of the `disabled` field on StylePath.
59 lines
1.3 KiB
Rust
59 lines
1.3 KiB
Rust
use std::error;
|
|
use std::fmt::{self, Formatter};
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use crate::docfs::PathError;
|
|
|
|
#[derive(Debug)]
|
|
crate struct Error {
|
|
crate file: PathBuf,
|
|
crate error: String,
|
|
}
|
|
|
|
impl error::Error for Error {}
|
|
|
|
impl std::fmt::Display for Error {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
let file = self.file.display().to_string();
|
|
if file.is_empty() {
|
|
write!(f, "{}", self.error)
|
|
} else {
|
|
write!(f, "\"{}\": {}", self.file.display(), self.error)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl PathError for Error {
|
|
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error
|
|
where
|
|
S: ToString + Sized,
|
|
{
|
|
Error { file: path.as_ref().to_path_buf(), error: e.to_string() }
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! try_none {
|
|
($e:expr, $file:expr) => {{
|
|
use std::io;
|
|
match $e {
|
|
Some(e) => e,
|
|
None => {
|
|
return Err(<crate::error::Error as crate::docfs::PathError>::new(
|
|
io::Error::new(io::ErrorKind::Other, "not found"),
|
|
$file,
|
|
));
|
|
}
|
|
}
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! try_err {
|
|
($e:expr, $file:expr) => {{
|
|
match $e {
|
|
Ok(e) => e,
|
|
Err(e) => return Err(Error::new(e, $file)),
|
|
}
|
|
}};
|
|
}
|