}
fn can_handle(&self, path: &PathBuf) -> bool {
- !path.is_dir()
+ self.is(path)
}
fn handle(&self, path: &PathBuf) {
+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())
+ }
+}
+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())
+ }
+}
+
pub mod file;
+pub mod gemini;
+pub mod layout;
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 {
impl Default for FileHandler {
fn default() -> FileHandler {
FileHandler {
- strategies: vec![Box::new(FileStrategy{})]
+ strategies: vec![
+ Box::new(GeminiStrategy{}),
+ Box::new(LayoutStrategy{}),
+ Box::new(FileStrategy{}),
+ ]
}
}
}