From 13c9bd2b07d7518cb980488674dd18109e6f5d6a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 28 Mar 2022 01:12:17 +0100 Subject: [PATCH] web templates: Use stem for template names (without .tera extension) This moves a bit of code to startup, and makes the macro use a bit cleaner again. Signed-off-by: Ian Jackson --- TODO | 1 - daemon/main.rs | 6 +++--- templates/landscape.tera | 2 +- templates/session.tera | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index d41d9bec..76fc57e8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -template don't do */* thing, and strip .tera TODOs in diff content-type for download bundles http2 HEAD requests diff --git a/daemon/main.rs b/daemon/main.rs index bd2b6828..ad484e68 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -75,8 +75,8 @@ impl Templates { fs::read_dir(template_dir).context("open directory")? .filter_map_ok(|entry| { let leaf = entry.file_name().into_string().ok()?; - leaf.ends_with(".tera").then(||())?; - Some((entry.path(), Some(leaf))) + let leaf = leaf.strip_suffix(".tera")?; + Some((entry.path(), Some(leaf.to_owned()))) }) .try_collect().context("read directory")?; tera.add_template_files(files).context("process templates")?; @@ -90,7 +90,7 @@ impl Templates { #[throws(InternalError)] fn inner(tmpls: &Templates, template: &str, c: tera::Result) -> Template { - let s = tmpls.tera.render(&format!("{}.tera", template), &c?)?; + let s = tmpls.tera.render(template, &c?)?; HttpResponseBuilder::new(StatusCode::OK) .content_type(CT_HTML) .body(s) diff --git a/templates/landscape.tera b/templates/landscape.tera index 84006b03..eeaad5a4 100644 --- a/templates/landscape.tera +++ b/templates/landscape.tera @@ -1,4 +1,4 @@ -{% import "macros.tera" as m %}{# -*- HTML -*- -#} +{% import "macros" as m %}{# -*- HTML -*- -#} diff --git a/templates/session.tera b/templates/session.tera index 25728e32..22c414f0 100644 --- a/templates/session.tera +++ b/templates/session.tera @@ -1,4 +1,4 @@ -{% import "macros.tera" as m %}{# -*- HTML -*- -#} +{% import "macros" as m %}{# -*- HTML -*- -#} -- 2.30.2