X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/f6a545b00a4046879b7cc25c06c37bb6b6880b43..40a5de55c35d6481fd538f4c5205e47c201e3289:/src/generator/html.rs?ds=sidebyside diff --git a/src/generator/html.rs b/src/generator/html.rs index cff4aea..70cc320 100644 --- a/src/generator/html.rs +++ b/src/generator/html.rs @@ -1,14 +1,22 @@ -use std::io::Result; -use std::path::PathBuf; -use crate::template::{find, parse, TemplateContext}; +use crate::template::{find, parse, Context}; +use std::fs::write; +use std::io::{Error, ErrorKind::Other, Result}; +use std::path::Path; -pub fn generate(_: &PathBuf, template_directory: &PathBuf, _: &PathBuf, context: &TemplateContext) -> Result<()> { - match find(template_directory, "index.html") { - Some(template) => { - let parsed_template = parse(&template); - println!("TOKEN {}", parsed_template.render(context)); - }, - None => {} +const FILENAME: &str = "index.html"; + +pub fn generate( + _: &Path, + template_directory: &Path, + target: &Path, + context: &Context, +) -> Result<()> { + if let Some(template) = find(template_directory, FILENAME) { + let parsed_template = + parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse HTML template"))?; + let rendered_template = parsed_template.render(context)?; + let location = target.join(FILENAME); + write(location, rendered_template)?; } Ok(()) }