1use serde::Deserialize;
2
3#[non_exhaustive]
16#[derive(Debug, Clone, Deserialize)]
17#[serde(default)]
18pub struct TemplateConfig {
19 pub templates_path: String,
21 pub static_path: String,
23 pub static_url_prefix: String,
25}
26
27impl Default for TemplateConfig {
28 fn default() -> Self {
29 Self {
30 templates_path: "templates".into(),
31 static_path: "static".into(),
32 static_url_prefix: "/assets".into(),
33 }
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn default_config_has_sensible_values() {
43 let config = TemplateConfig::default();
44 assert_eq!(config.templates_path, "templates");
45 assert_eq!(config.static_path, "static");
46 assert_eq!(config.static_url_prefix, "/assets");
47 }
48
49 #[test]
50 fn config_deserializes_from_yaml() {
51 let yaml = r#"
52 templates_path: "views"
53 static_path: "public"
54 static_url_prefix: "/static"
55 "#;
56 let config: TemplateConfig = serde_yaml_ng::from_str(yaml).unwrap();
57 assert_eq!(config.templates_path, "views");
58 assert_eq!(config.static_path, "public");
59 assert_eq!(config.static_url_prefix, "/static");
60 }
61
62 #[test]
63 fn config_uses_defaults_for_missing_fields() {
64 let yaml = r#"
65 templates_path: "views"
66 "#;
67 let config: TemplateConfig = serde_yaml_ng::from_str(yaml).unwrap();
68 assert_eq!(config.templates_path, "views");
69 assert_eq!(config.static_path, "static");
70 assert_eq!(config.static_url_prefix, "/assets");
71 }
72}