1 | use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError}; |
2 | use log::trace; |
3 | |
4 | pub fn theme_option( |
5 | h: &Helper<'_, '_>, |
6 | _r: &Handlebars<'_>, |
7 | ctx: &Context, |
8 | rc: &mut RenderContext<'_, '_>, |
9 | out: &mut dyn Output, |
10 | ) -> Result<(), RenderError> { |
11 | trace!("theme_option (handlebars helper)" ); |
12 | |
13 | let param: &str = h.param(0).and_then(|v| v.value().as_str()).ok_or_else(|| { |
14 | RenderError::new(desc:"Param 0 with String type is required for theme_option helper." ) |
15 | })?; |
16 | |
17 | let default_theme: ScopedJson<'_, '_> = rc.evaluate(context:ctx, relative_path:"@root/default_theme" )?; |
18 | let default_theme_name: &str = default_theme |
19 | .as_json() |
20 | .as_str() |
21 | .ok_or_else(|| RenderError::new(desc:"Type error for `default_theme`, string expected" ))?; |
22 | |
23 | out.write(seg:param)?; |
24 | if param.to_lowercase() == default_theme_name.to_lowercase() { |
25 | out.write(seg:" (default)" )?; |
26 | } |
27 | |
28 | Ok(()) |
29 | } |
30 | |