diff options
Diffstat (limited to 'src/archiver/gopher.rs')
| -rw-r--r-- | src/archiver/gopher.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/archiver/gopher.rs b/src/archiver/gopher.rs index 28f4f46..fc0c04f 100644 --- a/src/archiver/gopher.rs +++ b/src/archiver/gopher.rs @@ -1,20 +1,22 @@ +use crate::template::{find, parse, TemplateContext}; use std::fs::write; use std::io::{Error, ErrorKind::Other, Result}; -use std::path::PathBuf; -use crate::template::{find, parse, TemplateContext}; +use std::path::Path; const FILENAME: &str = "index.gph"; -pub fn archive(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> { - match find(template_directory, FILENAME) { - Some(template) => { - let parsed_template = parse(&template) - .ok_or_else(|| Error::new(Other, "Unable to parse Gopher Archive template"))?; - let rendered_template = parsed_template.render(context)?; - let location = target.join(FILENAME); - write(location, rendered_template)?; - }, - None => {} +pub fn archive( + _: &Path, + template_directory: &Path, + target: &Path, + context: &TemplateContext, +) -> Result<()> { + if let Some(template) = find(template_directory, FILENAME) { + let parsed_template = parse(&template) + .ok_or_else(|| Error::new(Other, "Unable to parse Gopher Archive template"))?; + let rendered_template = parsed_template.render(context)?; + let location = target.join(FILENAME); + write(location, rendered_template)?; } Ok(()) } |