]>
Commit | Line | Data |
---|---|---|
60307a9a | 1 | use std::fs::write; |
50f53dc4 | 2 | use std::io::{Error, ErrorKind::Other, Result}; |
29982470 | 3 | use std::path::PathBuf; |
f6a545b0 | 4 | use crate::template::{find, parse, TemplateContext}; |
29982470 | 5 | |
60307a9a RBR |
6 | const FILENAME: &str = "index.html"; |
7 | ||
8 | pub fn generate(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> { | |
9 | match find(template_directory, FILENAME) { | |
29982470 | 10 | Some(template) => { |
50f53dc4 RBR |
11 | let parsed_template = parse(&template) |
12 | .ok_or_else(|| Error::new(Other, "Unable to parse HTML template"))?; | |
13 | let rendered_template = parsed_template.render(context)?; | |
60307a9a RBR |
14 | let location = target.join(FILENAME); |
15 | write(location, rendered_template)?; | |
29982470 RBR |
16 | }, |
17 | None => {} | |
18 | } | |
19 | Ok(()) | |
20 | } |