Skip to main content

reinhardt_conf/settings/
static_files.rs

1//! Static files settings fragment
2//!
3//! Provides composable static file serving configuration as a [`SettingsFragment`](crate::settings::fragment::SettingsFragment).
4
5use reinhardt_core::macros::settings;
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9/// Static files configuration fragment.
10///
11/// Controls the URL prefix and root directory for serving static files.
12#[settings(fragment = true, section = "static_files")]
13#[non_exhaustive]
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct StaticSettings {
16	/// URL prefix for serving static files (e.g., `"/static/"`).
17	#[serde(default = "default_static_url")]
18	pub url: String,
19	/// Root directory for collected static files.
20	#[serde(default = "default_static_root")]
21	pub root: PathBuf,
22}
23
24fn default_static_url() -> String {
25	"/static/".to_string()
26}
27
28fn default_static_root() -> PathBuf {
29	PathBuf::from("static")
30}
31
32impl Default for StaticSettings {
33	fn default() -> Self {
34		Self {
35			url: "/static/".to_string(),
36			root: PathBuf::from("static"),
37		}
38	}
39}
40
41#[cfg(test)]
42mod tests {
43	use super::*;
44	use crate::settings::fragment::SettingsFragment;
45	use rstest::rstest;
46
47	#[rstest]
48	fn test_static_files_section_name() {
49		// Arrange / Act
50		let section = StaticSettings::section();
51
52		// Assert
53		assert_eq!(section, "static_files");
54	}
55
56	#[rstest]
57	fn test_static_files_default_values() {
58		// Arrange / Act
59		let settings = StaticSettings::default();
60
61		// Assert
62		assert_eq!(settings.url, "/static/");
63		assert_eq!(settings.root, PathBuf::from("static"));
64	}
65}