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