Skip to content

Commit

Permalink
Drop tera context sooner
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Aug 31, 2024
1 parent 7f6bb33 commit 1416cf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn build_tera_cache() -> Fallible<Tera> {
}

#[allow(unused_variables)]
pub fn render_template<C: Serialize>(name: &str, context: &C) -> Fallible<String> {
pub fn render_template<C: Serialize>(name: &str, context: C) -> Fallible<String> {
// On debug builds the cache is rebuilt every time to pick up changed templates
let tera_owned: Tera;
let tera;
Expand All @@ -161,7 +161,8 @@ pub fn render_template<C: Serialize>(name: &str, context: &C) -> Fallible<String
tera = &TERA_CACHE;
}

let tera_context = tera::Context::from_serialize(context)?;
Ok(tera
.render(name, &tera::Context::from_serialize(context)?)
.render(name, &tera_context)
.map_err(|e| failure::format_err!("{:?}", e))?)
}
9 changes: 5 additions & 4 deletions src/report/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ fn write_report<W: ReportWriter>(
};

info!("generating {}", to);
let rendered = assets::render_template("report/results.html", &context)
.context("rendering template report/results.html")?;
let html = minifier::html::minify(&rendered);
dest.write_string(to, html.into(), &mime::TEXT_HTML)?;

if output_templates {
dest.write_string(
Expand All @@ -269,6 +265,11 @@ fn write_report<W: ReportWriter>(
)?;
}

let rendered = assets::render_template("report/results.html", context)
.context("rendering template report/results.html")?;
let html = minifier::html::minify(&rendered);
dest.write_string(to, html.into(), &mime::TEXT_HTML)?;

Ok(())
}

Expand Down

0 comments on commit 1416cf3

Please sign in to comment.