~aleteoryx/lfm_embed

ref: 4424fb9b44c893dc937dc5077be7ef819680ea2c lfm_embed/src/theming.rs -rw-r--r-- 693 bytes
4424fb9balyx clippy 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: AGPL-3.0-only
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)
}