From: Ruben Beltran del Rio Date: Sat, 15 Apr 2023 14:39:12 +0000 (+0200) Subject: Add basic strategies X-Git-Tag: 1.0.0~11 X-Git-Url: https://git.r.bdr.sh/rbdr/page/commitdiff_plain/102a4884c3d7d26817fefb38c675be07047f5ee2 Add basic strategies --- diff --git a/src/file_handler/file_strategies/file.rs b/src/file_handler/file_strategies/file.rs index 530bbd6..c9e8c96 100644 --- a/src/file_handler/file_strategies/file.rs +++ b/src/file_handler/file_strategies/file.rs @@ -14,7 +14,7 @@ impl FileHandlerStrategy for Strategy { } fn can_handle(&self, path: &PathBuf) -> bool { - !path.is_dir() + self.is(path) } fn handle(&self, path: &PathBuf) { diff --git a/src/file_handler/file_strategies/gemini.rs b/src/file_handler/file_strategies/gemini.rs index e69de29..ffa2a9f 100644 --- a/src/file_handler/file_strategies/gemini.rs +++ b/src/file_handler/file_strategies/gemini.rs @@ -0,0 +1,26 @@ +pub struct Strategy {} + +use std::path::PathBuf; + +use crate::file_handler::{FileType, FileHandlerStrategy}; + +impl FileHandlerStrategy for Strategy { + fn is(&self, path: &PathBuf) -> bool { + if let Some(extension) = path.extension() { + return !path.is_dir() && extension == "gmi" + } + false + } + + fn identify(&self) -> FileType { + FileType::Gemini + } + + fn can_handle(&self, path: &PathBuf) -> bool { + self.is(path) + } + + fn handle(&self, path: &PathBuf) { + println!("Should convert {}", path.display()) + } +} diff --git a/src/file_handler/file_strategies/layout.rs b/src/file_handler/file_strategies/layout.rs index e69de29..cf1bb9f 100644 --- a/src/file_handler/file_strategies/layout.rs +++ b/src/file_handler/file_strategies/layout.rs @@ -0,0 +1,24 @@ +pub struct Strategy {} + +use std::path::PathBuf; + +use crate::file_handler::{FileType, FileHandlerStrategy}; + +impl FileHandlerStrategy for Strategy { + fn is(&self, path: &PathBuf) -> bool { + return !path.is_dir() && path.ends_with("_layout.html"); + } + + fn identify(&self) -> FileType { + FileType::Layout + } + + fn can_handle(&self, path: &PathBuf) -> bool { + self.is(path) + } + + fn handle(&self, path: &PathBuf) { + println!("Should convert {}", path.display()) + } +} + diff --git a/src/file_handler/file_strategies/mod.rs b/src/file_handler/file_strategies/mod.rs index 2e172cd..c4b17b6 100644 --- a/src/file_handler/file_strategies/mod.rs +++ b/src/file_handler/file_strategies/mod.rs @@ -1 +1,3 @@ pub mod file; +pub mod gemini; +pub mod layout; diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index 8038b3c..44fec6d 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -1,6 +1,9 @@ mod file_strategies; use file_strategies::file::Strategy as FileStrategy; +use file_strategies::gemini::Strategy as GeminiStrategy; +use file_strategies::layout::Strategy as LayoutStrategy; + use std::path::PathBuf; pub struct FileHandler { @@ -10,7 +13,11 @@ pub struct FileHandler { impl Default for FileHandler { fn default() -> FileHandler { FileHandler { - strategies: vec![Box::new(FileStrategy{})] + strategies: vec![ + Box::new(GeminiStrategy{}), + Box::new(LayoutStrategy{}), + Box::new(FileStrategy{}), + ] } } }