tailwind_rs_core/config/
parser.rs

1//! Configuration parser utilities
2
3use super::TailwindConfig;
4use crate::error::Result;
5use std::path::Path;
6
7/// Configuration parser with validation
8pub struct ConfigParser;
9
10impl ConfigParser {
11    /// Create a new configuration parser
12    pub fn new() -> Self {
13        Self
14    }
15
16    /// Parse configuration from TOML string
17    pub fn parse_toml(&self, content: &str) -> Result<TailwindConfig> {
18        TailwindConfig::from_str(content)
19    }
20
21    /// Parse configuration from file
22    pub fn parse_file(&self, path: &Path) -> Result<TailwindConfig> {
23        TailwindConfig::from_file(path)
24    }
25
26    /// Validate configuration
27    pub fn validate(&self, config: &TailwindConfig) -> Result<()> {
28        config.validate()
29    }
30}
31
32impl Default for ConfigParser {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn test_parser_creation() {
44        let parser = ConfigParser::new();
45        assert!(parser.validate(&TailwindConfig::new()).is_ok());
46    }
47
48    #[test]
49    fn test_toml_parsing() {
50        let parser = ConfigParser::new();
51        let toml_content = r#"
52[build]
53output = "dist/styles.css"
54minify = true
55
56[theme]
57name = "default"
58
59[responsive]
60breakpoints = { sm = 640, md = 768 }
61container_centering = true
62container_padding = 16
63"#;
64
65        let config = parser.parse_toml(toml_content).unwrap();
66        assert_eq!(config.build.output, "dist/styles.css");
67        assert!(config.build.minify);
68    }
69}