Эх сурвалжийг харах

Create FileType enum for retrieving all indices and components.

Lee Morgan 3 сар өмнө
parent
commit
59d0f2bda6
3 өөрчлөгдсөн 14 нэмэгдсэн , 9 устгасан
  1. 2 6
      src/build_dev.rs
  2. 11 2
      src/file_type.rs
  3. 1 1
      src/main.rs

+ 2 - 6
src/build_dev.rs

@@ -1,7 +1,7 @@
 use std::env;
 use crate::{
     options::Options,
-    routes_map::FileType
+    file_type::FileType
 };
 
 pub fn build_dev(opt: Options) {
@@ -13,9 +13,5 @@ pub fn build_dev(opt: Options) {
     //Create route for index files
 
     let current_dir = env::current_dir().expect("Error");
-    let files = FileType::get_all(current_dir.join(opt.routes_dir));
-
-    files
-        .into_iter()
-        .map()
+    let files = FileType::from_dir(current_dir.join(opt.routes_dir));
 }

+ 11 - 2
src/routes_map.rs → src/file_type.rs

@@ -10,7 +10,7 @@ pub enum FileType {
 }
 
 impl FileType {
-    pub fn get_all(dir: PathBuf) -> Vec<FileType> {
+    pub fn from_dir(dir: PathBuf) -> Vec<FileType> {
         let entries = fs::read_dir(dir).expect("Create failed");
         let mut files = Vec::new();
 
@@ -18,7 +18,7 @@ impl FileType {
             let path = entry.expect("Failed to read directory").path();
 
             if path.is_dir() {
-                files.append(&mut FileType::get_all(path));
+                files.append(&mut FileType::from_dir(path));
             } else if path.is_file() {
                 let filename = path.file_name().expect("Error reading file").to_string_lossy();
 
@@ -38,4 +38,13 @@ impl FileType {
 
         files
     }
+
+    pub fn path(&self) -> &PathBuf {
+        match self {
+            FileType::HtmlIndex(p) => p,
+            FileType::NeovanIndex(p) => p,
+            FileType::HtmlComponent(p) => p,
+            FileType::NeovanComponent(p) => p
+        }
+    }
 }

+ 1 - 1
src/main.rs

@@ -8,7 +8,7 @@ use crate::{
 mod create;
 mod build_dev;
 mod options;
-mod routes_map;
+mod file_type;
 
 #[derive(Parser)]
 #[command(version, about, long_about = None)]