diff options
Diffstat (limited to 'src/theming.rs')
-rw-r--r-- | src/theming.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/theming.rs b/src/theming.rs new file mode 100644 index 0000000..62e32b4 --- /dev/null +++ b/src/theming.rs @@ -0,0 +1,22 @@ +mod hbs; + +use reqwest::StatusCode; + +use crate::CONFIG; + +pub fn render_theme(name: Option<&str>, ctx: &crate::ctx::Ctx) -> (String, Result<String, StatusCode>) { + let mut theme = ""; + let mut res = None; + + if let Some(name) = name { + theme = name; + res = hbs::render_theme(name, ctx) + } + + res = res.or_else(|| { log::debug!("Falling back to default theme!"); theme = &CONFIG.default_theme; None }) + .or_else(|| hbs::render_theme(theme, ctx)); + + let res = res.unwrap_or_else(|| { log::error!("Couldn't load requested theme or default theme `{}`!", CONFIG.default_theme); Err(StatusCode::INTERNAL_SERVER_ERROR)}); + + (theme.into(), res) +} |