diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-04 02:20:55 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-04 02:20:55 +0100 |
| commit | 8766e4412b95cfa0288683748cc20aba81a64d08 (patch) | |
| tree | b068bbd32915b2c0ca846465edfd6cb9bf718d6c /src/file_handler/file_strategies | |
| parent | b03284133baa6339fe4adf48e4a6499ef3ac287b (diff) | |
Address pedantic issues
Diffstat (limited to 'src/file_handler/file_strategies')
| -rw-r--r-- | src/file_handler/file_strategies/file.rs | 8 | ||||
| -rw-r--r-- | src/file_handler/file_strategies/gemini.rs | 52 | ||||
| -rw-r--r-- | src/file_handler/file_strategies/layout.rs | 2 |
3 files changed, 28 insertions, 34 deletions
diff --git a/src/file_handler/file_strategies/file.rs b/src/file_handler/file_strategies/file.rs index c3c3016..e5573a2 100644 --- a/src/file_handler/file_strategies/file.rs +++ b/src/file_handler/file_strategies/file.rs @@ -3,10 +3,10 @@ pub struct Strategy {} use std::fs::{copy, create_dir_all}; use std::path::Path; -use crate::file_handler::{File, FileHandlerStrategy, FileType}; +use crate::file_handler::{File, FileType, Strategy as FileHandlerStrategy}; impl Strategy { - fn handle(&self, source: &Path, destination: &Path, file: &File) { + fn handle(source: &Path, destination: &Path, file: &File) { let relative_path = file.path.strip_prefix(source).unwrap(); let complete_destination = destination.join(relative_path); let destination_parent = complete_destination.parent().unwrap(); @@ -29,11 +29,11 @@ impl FileHandlerStrategy for Strategy { } fn handle_html(&self, source: &Path, destination: &Path, file: &File, _l: &str) { - self.handle(source, destination, file) + Strategy::handle(source, destination, file); } fn handle_gemini(&self, source: &Path, destination: &Path, file: &File) { - self.handle(source, destination, file) + Strategy::handle(source, destination, file); } } diff --git a/src/file_handler/file_strategies/gemini.rs b/src/file_handler/file_strategies/gemini.rs index 32cb99e..df35d64 100644 --- a/src/file_handler/file_strategies/gemini.rs +++ b/src/file_handler/file_strategies/gemini.rs @@ -4,24 +4,24 @@ use std::fs::{create_dir_all, read_to_string, File as IOFile}; use std::io::Write; use std::path::Path; -use crate::file_handler::{File, FileHandlerStrategy, FileType}; +use crate::file_handler::{File, FileType, Strategy as FileHandlerStrategy}; use crate::gemini_parser::parse; use crate::html_renderer::render_html; impl Strategy { - fn is_title(&self, line: &str) -> bool { + fn is_title(line: &str) -> bool { line.starts_with("--- title:") } - fn is_description(&self, line: &str) -> bool { + fn is_description(line: &str) -> bool { line.starts_with("--- description:") } - fn get_title<'a>(&self, line: &'a str) -> &'a str { + fn get_title(line: &str) -> &str { line.split_once("--- title:").unwrap().1 } - fn get_description<'a>(&self, line: &'a str) -> &'a str { + fn get_description(line: &str) -> &str { line.split_once("--- description:").unwrap().1 } } @@ -46,19 +46,19 @@ impl FileHandlerStrategy for Strategy { let gemini_contents = read_to_string(&file.path).unwrap(); // Front matter extraction - let lines: Vec<&str> = gemini_contents.split("\n").collect(); + let lines: Vec<&str> = gemini_contents.split('\n').collect(); let mut lines_found = 0; let mut title = ""; let mut description = ""; if let Some(slice) = lines.get(..2) { - for line in slice.iter() { - if self.is_title(line) { - title = self.get_title(line).trim(); + for line in slice { + if Strategy::is_title(line) { + title = Strategy::get_title(line).trim(); lines_found += 1; continue; } - if self.is_description(line) { - description = self.get_description(line).trim(); + if Strategy::is_description(line) { + description = Strategy::get_description(line).trim(); lines_found += 1; continue; } @@ -66,7 +66,7 @@ impl FileHandlerStrategy for Strategy { } let gemini_source = lines[lines_found..].join("\n"); - let content_html = render_html(parse(&gemini_source[..])); + let content_html = render_html(&parse(&gemini_source[..])); let generated_html = layout .replace("{{ title }}", title) @@ -89,15 +89,15 @@ impl FileHandlerStrategy for Strategy { let gemini_contents = read_to_string(&file.path).unwrap(); // Front matter extraction - let lines: Vec<&str> = gemini_contents.split("\n").collect(); + let lines: Vec<&str> = gemini_contents.split('\n').collect(); let mut lines_found = 0; if let Some(slice) = lines.get(..2) { - for line in slice.iter() { - if self.is_title(line) { + for line in slice { + if Strategy::is_title(line) { lines_found += 1; continue; } - if self.is_description(line) { + if Strategy::is_description(line) { lines_found += 1; continue; } @@ -128,40 +128,34 @@ mod tests { #[test] fn detects_title() { - let strategy = Strategy {}; - assert!(strategy.is_title("--- title: Hello!")); + assert!(Strategy::is_title("--- title: Hello!")); } #[test] fn does_not_detect_other_keys_as_title() { - let strategy = Strategy {}; - assert!(!strategy.is_title("--- description: Hello!")); + assert!(!Strategy::is_title("--- description: Hello!")); } #[test] fn detects_description() { - let strategy = Strategy {}; - assert!(strategy.is_description("--- description: What is this?")); + assert!(Strategy::is_description("--- description: What is this?")); } #[test] fn does_not_detect_other_keys_as_description() { - let strategy = Strategy {}; - assert!(!strategy.is_description("--- title: What is this?")); + assert!(!Strategy::is_description("--- title: What is this?")); } #[test] fn extracts_title() { - let strategy = Strategy {}; - assert_eq!(strategy.get_title("--- title: Hello!").trim(), "Hello!"); + assert_eq!(Strategy::get_title("--- title: Hello!").trim(), "Hello!"); } #[test] fn extracts_description() { - let strategy = Strategy {}; assert_eq!( - strategy - .get_description("--- description: What is this?") + Strategy + ::get_description("--- description: What is this?") .trim(), "What is this?" ); diff --git a/src/file_handler/file_strategies/layout.rs b/src/file_handler/file_strategies/layout.rs index 8d9689c..9a60f12 100644 --- a/src/file_handler/file_strategies/layout.rs +++ b/src/file_handler/file_strategies/layout.rs @@ -2,7 +2,7 @@ pub struct Strategy {} use std::path::Path; -use crate::file_handler::{File, FileHandlerStrategy, FileType}; +use crate::file_handler::{File, FileType, Strategy as FileHandlerStrategy}; impl FileHandlerStrategy for Strategy { fn is(&self, path: &Path) -> bool { |