use std::path::{Path, PathBuf};
pub struct FileHandler {
- pub strategies: Vec<Box<dyn FileHandlerStrategy>>,
+ pub strategies: Vec<Box<dyn Strategy>>,
pub layout: Option<String>,
}
impl FileHandler {
pub fn identify(&self, path: &Path) -> FileType {
- for strategy in self.strategies.iter() {
+ for strategy in &self.strategies {
if strategy.is(path) {
return strategy.identify();
}
gemini_destination: &Path,
files: &[File],
) {
- files.iter().for_each(|file| {
+ for file in files {
self.handle(source, html_destination, gemini_destination, file);
- });
+ }
}
pub fn handle(
}
}
-pub trait FileHandlerStrategy {
+pub trait Strategy {
fn is(&self, path: &Path) -> bool;
fn identify(&self) -> FileType;
fn can_handle(&self, file_type: &FileType) -> bool;
let files = vec![
create_test_internal_file("test.gmi", FileType::Gemini),
create_test_internal_file(
- &layout_path.to_str().expect("Could not encode layout"),
+ layout_path.to_str().expect("Could not encode layout"),
FileType::Layout,
),
create_test_internal_file("regular.html", FileType::File),
file_type: FileType,
}
- impl FileHandlerStrategy for MockStrategy {
+ impl Strategy for MockStrategy {
fn is(&self, _path: &Path) -> bool {
self.is_match
}
#[test]
fn test_handle_with_layout() {
- let mut handler = FileHandler::default();
- handler.layout = Some("test layout".to_string());
+ let handler = FileHandler {
+ layout: Some("test layout".to_string()),
+ ..Default::default()
+ };
let test_dir = setup_test_dir();
- create_dir_all(&test_dir.join("output_html"))
+ create_dir_all(test_dir.join("output_html"))
.expect("Could not create output html test directory");
- create_dir_all(&test_dir.join("output_gemini"))
+ create_dir_all(test_dir.join("output_gemini"))
.expect("Could not create output gemini test directory");
let test_path = test_dir.join("test.gmi");
create_test_file(&test_path, "");
let file = create_test_internal_file(
- &test_path
+ test_path
.to_str()
.expect("Could not encode gemini test file"),
FileType::Gemini,
create_test_file(&test_dir.join("test1.gmi"), "");
create_test_file(&test_dir.join("test2.gmi"), "");
create_test_file(&test_dir.join("test3.gmi"), "");
- create_dir_all(&test_dir.join("output_html"))
+ create_dir_all(test_dir.join("output_html"))
.expect("Could not create output html test directory");
- create_dir_all(&test_dir.join("output_gemini"))
+ create_dir_all(test_dir.join("output_gemini"))
.expect("Could not create output gemini test directory");
let mut handler = FileHandler::default();
- let files = vec![
+ let files = [
create_test_internal_file(
- &test_dir
+ test_dir
.join("test1.gmi")
.to_str()
.expect("Could not encode test1"),
FileType::Gemini,
),
create_test_internal_file(
- &layout_path.to_str().expect("Could not encode layout"),
+ layout_path.to_str().expect("Could not encode layout"),
FileType::Layout,
),
create_test_internal_file(
- &test_dir
+ test_dir
.join("test2.gmi")
.to_str()
.expect("Could not encode test2"),
FileType::Gemini,
),
create_test_internal_file(
- &test_dir
+ test_dir
.join("test3.gmi")
.to_str()
.expect("Could not encode test3"),