2024-01-04 20:16:34 +08:00
|
|
|
use handlebars::{
|
|
|
|
|
Context, Handlebars, Helper, Output, RenderContext, RenderError, RenderErrorReason,
|
|
|
|
|
};
|
2022-06-24 16:50:02 +05:30
|
|
|
use log::trace;
|
2018-10-13 14:44:10 +01:00
|
|
|
|
2025-07-25 09:02:55 -07:00
|
|
|
pub(crate) fn theme_option(
|
2024-01-04 20:16:34 +08:00
|
|
|
h: &Helper<'_>,
|
2020-01-24 11:01:44 +08:00
|
|
|
_r: &Handlebars<'_>,
|
2018-10-13 14:44:10 +01:00
|
|
|
ctx: &Context,
|
2020-01-24 11:01:44 +08:00
|
|
|
rc: &mut RenderContext<'_, '_>,
|
2019-05-07 03:50:34 +07:00
|
|
|
out: &mut dyn Output,
|
2018-10-13 14:44:10 +01:00
|
|
|
) -> Result<(), RenderError> {
|
|
|
|
|
trace!("theme_option (handlebars helper)");
|
|
|
|
|
|
2019-05-07 01:20:58 +07:00
|
|
|
let param = h.param(0).and_then(|v| v.value().as_str()).ok_or_else(|| {
|
2024-01-04 20:16:34 +08:00
|
|
|
RenderErrorReason::ParamTypeMismatchForName(
|
|
|
|
|
"theme_option",
|
|
|
|
|
"0".to_owned(),
|
|
|
|
|
"string".to_owned(),
|
|
|
|
|
)
|
2019-05-07 01:20:58 +07:00
|
|
|
})?;
|
2018-10-13 14:44:10 +01:00
|
|
|
|
2019-07-13 00:11:05 +08:00
|
|
|
let default_theme = rc.evaluate(ctx, "@root/default_theme")?;
|
2024-01-04 20:16:34 +08:00
|
|
|
let default_theme_name = default_theme.as_json().as_str().ok_or_else(|| {
|
|
|
|
|
RenderErrorReason::ParamTypeMismatchForName(
|
|
|
|
|
"theme_option",
|
|
|
|
|
"default_theme".to_owned(),
|
|
|
|
|
"string".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
})?;
|
2018-10-13 14:44:10 +01:00
|
|
|
|
|
|
|
|
out.write(param)?;
|
2019-07-13 00:11:05 +08:00
|
|
|
if param.to_lowercase() == default_theme_name.to_lowercase() {
|
2018-10-13 14:44:10 +01:00
|
|
|
out.write(" (default)")?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|