X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/5732d284ebc2cc2cbde0f050443b8f137dbf585b..5e9cc429045749ff7c1e6396de7657122783528d:/src/file_handler/mod.rs diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index a079c74..e8a446b 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -8,7 +8,7 @@ use std::fs::read_to_string; use std::path::{Path, PathBuf}; pub struct FileHandler { - pub strategies: Vec>, + pub strategies: Vec>, pub layout: Option, } @@ -27,7 +27,7 @@ impl Default for FileHandler { impl FileHandler { pub fn identify(&self, path: &Path) -> FileType { - for strategy in self.strategies.iter() { + for strategy in &self.strategies { if strategy.is(path) { return strategy.identify(); } @@ -53,9 +53,9 @@ impl FileHandler { gemini_destination: &Path, files: &[File], ) { - files.iter().for_each(|file| { + for file in files { self.handle(source, html_destination, gemini_destination, file); - }); + } } pub fn handle( @@ -80,7 +80,7 @@ impl FileHandler { } } -pub trait FileHandlerStrategy { +pub trait Strategy { fn is(&self, path: &Path) -> bool; fn identify(&self) -> FileType; fn can_handle(&self, file_type: &FileType) -> bool; @@ -156,7 +156,7 @@ mod tests { let files = vec![ create_test_internal_file("test.gmi", FileType::Gemini), create_test_internal_file( - &layout_path.to_str().expect("Could not encode layout"), + layout_path.to_str().expect("Could not encode layout"), FileType::Layout, ), create_test_internal_file("regular.html", FileType::File), @@ -182,7 +182,7 @@ mod tests { file_type: FileType, } - impl FileHandlerStrategy for MockStrategy { + impl Strategy for MockStrategy { fn is(&self, _path: &Path) -> bool { self.is_match } @@ -231,18 +231,20 @@ mod tests { #[test] fn test_handle_with_layout() { - let mut handler = FileHandler::default(); - handler.layout = Some("test layout".to_string()); + let handler = FileHandler { + layout: Some("test layout".to_string()), + ..Default::default() + }; let test_dir = setup_test_dir(); - create_dir_all(&test_dir.join("output_html")) + create_dir_all(test_dir.join("output_html")) .expect("Could not create output html test directory"); - create_dir_all(&test_dir.join("output_gemini")) + create_dir_all(test_dir.join("output_gemini")) .expect("Could not create output gemini test directory"); let test_path = test_dir.join("test.gmi"); create_test_file(&test_path, ""); let file = create_test_internal_file( - &test_path + test_path .to_str() .expect("Could not encode gemini test file"), FileType::Gemini, @@ -279,33 +281,33 @@ mod tests { create_test_file(&test_dir.join("test1.gmi"), ""); create_test_file(&test_dir.join("test2.gmi"), ""); create_test_file(&test_dir.join("test3.gmi"), ""); - create_dir_all(&test_dir.join("output_html")) + create_dir_all(test_dir.join("output_html")) .expect("Could not create output html test directory"); - create_dir_all(&test_dir.join("output_gemini")) + create_dir_all(test_dir.join("output_gemini")) .expect("Could not create output gemini test directory"); let mut handler = FileHandler::default(); - let files = vec![ + let files = [ create_test_internal_file( - &test_dir + test_dir .join("test1.gmi") .to_str() .expect("Could not encode test1"), FileType::Gemini, ), create_test_internal_file( - &layout_path.to_str().expect("Could not encode layout"), + layout_path.to_str().expect("Could not encode layout"), FileType::Layout, ), create_test_internal_file( - &test_dir + test_dir .join("test2.gmi") .to_str() .expect("Could not encode test2"), FileType::Gemini, ), create_test_internal_file( - &test_dir + test_dir .join("test3.gmi") .to_str() .expect("Could not encode test3"),