chiark / gitweb /
web templates: Use stem for template names (without .tera extension)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Mar 2022 00:12:17 +0000 (01:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Mar 2022 00:16:50 +0000 (01:16 +0100)
This moves a bit of code to startup, and makes the macro use a bit
cleaner again.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
TODO
daemon/main.rs
templates/landscape.tera
templates/session.tera

diff --git a/TODO b/TODO
index d41d9bec12a8477aaba2a02569b69a8322e5bb6f..76fc57e893836fca97c2d86fd51e950c2ed46161 100644 (file)
--- 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
index bd2b6828b3d7d429486a67034e62a40c931cb28f..ad484e680b1595e6c55bd8cbdcced076b1013401 100644 (file)
@@ -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<tera::Context>)
              -> 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)
index 84006b031946522ce125c22dd4d1294d3aa42f31..eeaad5a4588ced1c9cc0e8e4a07b9c9506bded4e 100644 (file)
@@ -1,4 +1,4 @@
-{% import "macros.tera" as m %}{# -*- HTML -*- -#}
+{% import "macros" as m %}{# -*- HTML -*- -#}
 <!-- Copyright 2020u Ian Jackson
      SPDX-License-Identifier: AGPL-3.0-or-later
      There is NO WARRANTY. -->
index 25728e3257f46d36bfcd7f251d6ad8983d52ef25..22c414f01ae090ccc20758d3215478f5c58ee55e 100644 (file)
@@ -1,4 +1,4 @@
-{% import "macros.tera" as m %}{# -*- HTML -*- -#}
+{% import "macros" as m %}{# -*- HTML -*- -#}
 <!-- Copyright 2020u Ian Jackson
      SPDX-License-Identifier: AGPL-3.0-or-later
      There is NO WARRANTY. -->