]> git.r.bdr.sh - rbdr/page/blobdiff - src/file_handler/mod.rs
Remove clang from page
[rbdr/page] / src / file_handler / mod.rs
index a106c27745013db17b9941e640afee7040d44b86..9a0133adf999f78172243084449775ad7787768c 100644 (file)
@@ -35,31 +35,33 @@ impl FileHandler {
         FileType::Unknown
     }
 
-    pub fn get_layout_or_panic(&mut self, files: &Vec<File>) {
+    pub fn get_layout_or_panic(&mut self, files: &Vec<File>) -> Result<(), &str> {
         for file in files {
             match file.file_type {
                 FileType::Layout => {
                     let layout_text = read_to_string(&file.path).unwrap();
                     self.layout = Some(layout_text);
-                    return;
+                    return Ok(());
                 },
                 _ => {}
             }
         }
-        panic!("No layout found. Please ensure there's a _layout.html file at the root");
+        Err("No layout found. Please ensure there's a _layout.html file at the root")
     }
 
-    pub fn handle_all(&self, source: &PathBuf, destination: &PathBuf, files: &Vec<File>) {
+    pub fn handle_all(&self, source: &PathBuf, html_destination: &PathBuf, gemini_destination: &PathBuf, files: &Vec<File>) {
         for file in files {
-            self.handle(source, destination, file);
+            self.handle(source, html_destination, gemini_destination, file);
         }
     }
 
-    pub fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
+    pub fn handle(&self, source: &PathBuf, html_destination: &PathBuf, gemini_destination: &PathBuf, file: &File) {
         for strategy in self.strategies.iter() {
             if strategy.can_handle(&file.file_type) {
                 let layout = self.layout.as_ref().unwrap();
-                return strategy.handle(source, destination, file, layout);
+                strategy.handle_html(source, html_destination, file, layout);
+                strategy.handle_gemini(source, gemini_destination, file);
+                return;
             }
         }
     }
@@ -69,7 +71,8 @@ pub trait FileHandlerStrategy {
     fn is(&self, path: &PathBuf) -> bool;
     fn identify(&self) -> FileType;
     fn can_handle(&self, file_type: &FileType) -> bool;
-    fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File, layout: &String);
+    fn handle_html(&self, source: &PathBuf, destination: &PathBuf, file: &File, layout: &String);
+    fn handle_gemini(&self, source: &PathBuf, destination: &PathBuf, file: &File);
 }
 
 pub enum FileType {