use crate::registry::DocsRegistry;
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct ThemeConfig {
pub default_theme: String,
pub toggle_themes: Option<(String, String)>,
pub storage_key: String,
}
pub struct DocsConfig {
nav_json: String,
content_map: HashMap<&'static str, &'static str>,
openapi_specs: Vec<(String, String)>,
default_path: Option<String>,
api_group_name: Option<String>,
theme: Option<ThemeConfig>,
}
impl DocsConfig {
pub fn new(nav_json: &str, content_map: HashMap<&'static str, &'static str>) -> Self {
Self {
nav_json: nav_json.to_string(),
content_map,
openapi_specs: Vec::new(),
default_path: None,
api_group_name: None,
theme: None,
}
}
pub fn with_openapi(mut self, prefix: &str, yaml: &str) -> Self {
self.openapi_specs
.push((prefix.to_string(), yaml.to_string()));
self
}
pub fn with_default_path(mut self, path: &str) -> Self {
self.default_path = Some(path.to_string());
self
}
pub fn with_api_group_name(mut self, name: &str) -> Self {
self.api_group_name = Some(name.to_string());
self
}
pub fn with_theme(mut self, theme: &str) -> Self {
self.theme = Some(ThemeConfig {
default_theme: theme.to_string(),
toggle_themes: None,
storage_key: "docs-theme".to_string(),
});
self
}
pub fn with_theme_toggle(mut self, light: &str, dark: &str, default: &str) -> Self {
self.theme = Some(ThemeConfig {
default_theme: default.to_string(),
toggle_themes: Some((light.to_string(), dark.to_string())),
storage_key: "docs-theme".to_string(),
});
self
}
pub fn build(self) -> DocsRegistry {
DocsRegistry::from_config(self)
}
pub(crate) fn nav_json(&self) -> &str {
&self.nav_json
}
pub(crate) fn content_map(&self) -> &HashMap<&'static str, &'static str> {
&self.content_map
}
pub(crate) fn openapi_specs(&self) -> &[(String, String)] {
&self.openapi_specs
}
pub(crate) fn default_path_value(&self) -> Option<&str> {
self.default_path.as_deref()
}
pub(crate) fn api_group_name_value(&self) -> Option<&str> {
self.api_group_name.as_deref()
}
pub(crate) fn theme_config(&self) -> Option<&ThemeConfig> {
self.theme.as_ref()
}
}