From beabd7b1f6a7fef9cf3e313db5b997837f5e0464 Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Thu, 21 May 2026 20:50:06 +0200 Subject: [PATCH] style: Minor style modifications --- src/compiler/compiler.rs | 51 ++++++++++++++++--------------------- src/compiler/models.rs | 2 +- src/compiler/models_impl.rs | 1 - 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 8d206e8..c52927e 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -1,6 +1,5 @@ use std::fs; -// Make sure your models match your struct definitions use crate::compiler::models::{Page, PageRoute, Project, Template}; pub fn compile() { @@ -26,11 +25,9 @@ fn list_all_paths() -> Vec { for entry in entries { let entry = entry.unwrap(); let path = entry.path(); - + if path.is_dir() { - let dir_name = path.file_name() - .and_then(|n| n.to_str()) - .unwrap_or(""); + let dir_name = path.file_name().and_then(|n| n.to_str()).unwrap_or(""); if !dir_name.starts_with('.') && dir_name != "target" { paths.push(path.to_str().unwrap().to_string()); @@ -42,7 +39,6 @@ fn list_all_paths() -> Vec { } fn construct_page(page_path: &str) -> Page { - // --- 1. Route Resolution --- let suffixes = [".regexpr", ".js", ""]; let mut route_option: Option = None; @@ -52,33 +48,32 @@ fn construct_page(page_path: &str) -> Page { if let Ok(content) = fs::read_to_string(&file_path) { route_option = Some(match suffix { ".regexpr" => PageRoute::Regexpr(content), - ".js" => PageRoute::CustomScript(content), - "" => PageRoute::Static(content), - _ => unreachable!(), + ".js" => PageRoute::CustomScript(content), + "" => PageRoute::Static(content), + _ => unreachable!(), }); - break; + break; } } let route = route_option.unwrap_or_else(|| { - panic!("No valid route file found (route.regexpr, route.js, or route) in '{}'", page_path) - }); + panic!( + "No valid route file found (route.regexpr, route.js, or route) in '{}'", + page_path + ) + }); - // --- 2. Page-level Style --- let style_path = format!("{}/style.css", page_path); let style = fs::read_to_string(&style_path).ok(); - // --- 3. Parse Templates --- let mut content = Vec::new(); let templates_dir = format!("{}/templates", page_path); - // Check if the templates directory exists for this page if let Ok(entries) = fs::read_dir(&templates_dir) { for entry in entries { let entry = entry.expect("Failed to read template entry"); let path = entry.path(); - - // Only process folders inside the 'templates' directory + if path.is_dir() { let template_path = path.to_str().unwrap(); let template = construct_template(template_path); @@ -95,40 +90,38 @@ fn construct_page(page_path: &str) -> Page { } fn construct_template(template_path: &str) -> Template { - // --- 1. Template-level Style --- let style_path = format!("{}/style.css", template_path); let style = fs::read_to_string(&style_path).ok(); - // --- 2. Template Content Resolution --- let script_path = format!("{}/script.js", template_path); let template_html_path = format!("{}/template.html", template_path); - + if let Ok(script_content) = fs::read_to_string(&script_path) { Template::CustomScript { script: script_content, style, } - } - else if let Ok(template_content) = fs::read_to_string(&template_html_path) { + } else if let Ok(template_content) = fs::read_to_string(&template_html_path) { let scraper_path = format!("{}/scrape.js", template_path); let scraper = fs::read_to_string(&scraper_path).ok(); let replace_selector_path = format!("{}/replace_selector", template_path); let replace_selector = fs::read_to_string(&replace_selector_path).unwrap_or_else(|_| { - panic!("replace_selector file not found in '{}': Required for template injection", template_path); + panic!( + "replace_selector file not found in '{}': Required for template injection", + template_path + ); }); - + Template::TemplateInjector { template: template_content, - // .trim() prevents trailing newlines in text files from breaking CSS selectors - replace_selector: replace_selector.trim().to_string(), + replace_selector: replace_selector.trim().to_string(), scraper, style, } - } - else { + } else { panic!( - "Template content not found in '{}': Directory must contain either script.js or template.html", + "Template content not found in '{}': Directory must contain either script.js or template.html", template_path ); } diff --git a/src/compiler/models.rs b/src/compiler/models.rs index 0045643..af92d7d 100644 --- a/src/compiler/models.rs +++ b/src/compiler/models.rs @@ -4,7 +4,7 @@ pub struct Project { pub struct Page { pub route: PageRoute, - pub style: Option, + pub style: Option, // TODO: Actually use this lmao pub content: Vec