diff --git a/Cargo.toml b/Cargo.toml index 9056cb9..c25dba5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,9 +2,11 @@ name = "lf-builder" version = "0.1.0" edition = "2021" -authors = [ "Alina Marquardt" ] +authors = [ "Alina Marquardt " ] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] chrono = "0.4.24" +json = "0.12.4" +mustache = "0.9.0" diff --git a/src/main.rs b/src/main.rs index 5d590b4..af95fe6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,41 +6,47 @@ use std::time::Instant; const PUBLISH_PATH: &str = "./pub/"; const TEMPLATE_PATH: &str = "./src/templates/"; -fn render_html(file: &str, template: &str, data: Vec) -> Result<(), Error> { +fn render_html(file: &str, template_file: &str) { let output_path = &format!("{}{}", PUBLISH_PATH, file); - let template_path = &format!("{}{}", TEMPLATE_PATH, template); + let template_path = &format!("{}{}", TEMPLATE_PATH, template_file); let now = Instant::now(); - // TODO: Templating with template and data + // TODO: Generate HTML with template and data let html_string = "

Hello!

"; - let elapsed = now.elapsed(); - let mut output_file = File::create(output_path)?; - write!(output_file, -"{}\n -", + let output = format!( + "{}\n\n", html_string, - template, + template_path, chrono::offset::Local::now(), - elapsed - )?; + now.elapsed(), + ); + let result = write_file(output_path, output); + match result { + Ok(file) => file, + Err(e) => panic!("Problem creating {:?}", e) + } + + /* let input = File::open(output_path)?; let buffered = BufReader::new(input); for line in buffered.lines() { println!("{}", line?); } + */ +} + +fn write_file(file_path: &str, contents: String) -> Result<(), Error> { + let mut output_file = File::create(file_path)?; + write!(output_file, "{}", contents)?; Ok(()) } fn main() { - render_html("index.html", "index.tmpl", vec![1, 2, 3]); + render_html("index.html", "index.tmpl"); }