nargo_document/theme/
tech_theme.rs1use super::{
5 default_theme::{LocaleInfo, NavItem, PageContext, SidebarGroup, SidebarLink},
6 Theme,
7};
8use crate::config::Config;
9use askama::Template;
10
11#[derive(Debug, Clone, Template)]
13#[template(path = "tech_page.html")]
14pub struct TechPageContext {
15 pub page_title: String,
16 pub site_title: String,
17 pub content: String,
18 pub nav_items: Vec<NavItem>,
19 pub sidebar_groups: Vec<SidebarGroup>,
20 pub current_path: String,
21 pub has_footer: bool,
22 pub has_footer_message: bool,
23 pub footer_message: String,
24 pub has_footer_copyright: bool,
25 pub footer_copyright: String,
26 pub current_lang: String,
27 pub available_locales: Vec<LocaleInfo>,
28 pub root_path: String,
29}
30
31impl From<&PageContext> for TechPageContext {
32 fn from(context: &PageContext) -> Self {
33 Self { page_title: context.page_title.clone(), site_title: context.site_title.clone(), content: context.content.clone(), nav_items: context.nav_items.clone(), sidebar_groups: context.sidebar_groups.clone(), current_path: context.current_path.clone(), has_footer: context.has_footer, has_footer_message: context.has_footer_message, footer_message: context.footer_message.clone(), has_footer_copyright: context.has_footer_copyright, footer_copyright: context.footer_copyright.clone(), current_lang: context.current_lang.clone(), available_locales: context.available_locales.clone(), root_path: context.root_path.clone() }
34 }
35}
36
37#[derive(Clone)]
39pub struct TechTheme {
40 pub config: Config,
41}
42
43impl Theme for TechTheme {
44 fn name(&self) -> &str {
45 "tech"
46 }
47
48 fn render_page(&self, context: &PageContext) -> Result<String, Box<dyn std::error::Error>> {
49 let tech_context: TechPageContext = context.into();
50 <TechPageContext as Template>::render(&tech_context).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()).into())
51 }
52
53 fn config(&self) -> &Config {
54 &self.config
55 }
56}
57
58impl TechTheme {
59 pub fn new(config: Config) -> Result<Self, Box<dyn std::error::Error>> {
60 Ok(Self { config })
61 }
62
63 pub fn site_title(&self) -> &str {
64 self.config.title.as_deref().unwrap_or("")
65 }
66}