]> git.r.bdr.sh - rbdr/page/blobdiff - src/file_handler/mod.rs
Replace gmi with md
[rbdr/page] / src / file_handler / mod.rs
index 64224ee4061e896b51358f0d36615d903695e65c..4932ef17f567f70066e8ce480fd03b6ec1afc81a 100644 (file)
@@ -35,18 +35,18 @@ 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>) {
@@ -58,7 +58,8 @@ impl FileHandler {
     pub fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
         for strategy in self.strategies.iter() {
             if strategy.can_handle(&file.file_type) {
-                return strategy.handle(source, destination, file);
+                let layout = self.layout.as_ref().unwrap();
+                return strategy.handle(source, destination, file, layout);
             }
         }
     }
@@ -68,7 +69,7 @@ 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);
+    fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File, layout: &String);
 }
 
 pub enum FileType {