pub fn load_dynamic_files() -> Result<HashMap<String, String>, String> {
    let current_dir = get_current_dir()?;
    let resources_dir = PathBuf::from(string_from_path(current_dir)? + "/resources/templates");

    let mut result = HashMap::new();

    let files = match fs::read_dir(&resources_dir) {
        Ok(files) => files,
        Err(_) => return Err("Could not read dynamic files from resources. Make sure the directory lays in the current directory".to_string())
    };

    for entry in files {
        let entry = match entry {
            Ok(entry) => entry.path(),
            Err(_) => continue
        };

        if entry.is_file() {
            let file_name = match entry.file_name() {
                Some(file_name) => {
                    match file_name.to_str() {
                        Some(file_name) => format!("/{}", file_name),
                        None => continue
                    }
                }
                None => continue
            };

            match fs::read_to_string(&entry) {
                Ok(file_content) => result.insert(file_name, file_content),
                Err(_) => continue
            };
        }
    }
    Ok(result)
}
/// Loads the files from the dynamic resources directory into memory
Loads the files from the dynamic resources directory into memory
Loads the files from the dynamic resources directory into memory
pub fn load_dynamic_files() -> Result<HashMap<String, String>, String> {
    let current_dir = get_current_dir()?;
    let resources_dir = PathBuf::from(string_from_path(current_dir)? + "/resources/templates");
    let mut result = HashMap::new();
    let files = match fs::read_dir(&resources_dir) {
        Ok(files) => files,
        Err(_) => return Err("Could not read dynamic files from resources. Make sure the directory lays in the current directory".to_string())
    };
    for entry in files {
        let entry = match entry {
            Ok(entry) => entry.path(),
            Err(_) => continue
        };
        if entry.is_file() {
            let file_name = match entry.file_name() {
                Some(file_name) => {
                    match file_name.to_str() {
                        Some(file_name) => format!("/{}", file_name),
                        None => continue
                    }
                }
                None => continue
            };
            match fs::read_to_string(&entry) {
                Ok(file_content) => result.insert(file_name, file_content),
                Err(_) => continue
            };
        }
    }
    Ok(result)
}
pub fn load_dynamic_files ( ) -> Result < HashMap < String , String > , String > { let current_dir = get_current_dir ( ) ? ; let resources_dir = PathBuf :: from ( string_from_path ( current_dir ) ? + " " ) ; let mut result = HashMap :: new ( ) ; let files = match fs :: read_dir ( & resources_dir ) { Ok ( files ) => files , Err ( _ ) => return Err ( " " . to_string ( ) ) } ; for entry in files { let entry = match entry { Ok ( entry ) => entry . path ( ) , Err ( _ ) => continue } ; if entry . is_file ( ) { let file_name = match entry . file_name ( ) { Some ( file_name ) => { match file_name . to_str ( ) { Some ( file_name ) => format ! ( " " file_name ) , None => continue } } None => continue } ; match fs :: read_to_string ( & entry ) { Ok ( file_content ) => result . insert ( file_name , file_content ) , Err ( _ ) => continue } ; } } Ok ( result ) }
Loads the files from the dynamic resources directory into memory
Loads the files from the dynamic resources directory into memory