Skip to content

Commit 139f11b

Browse files
Update to new rinja version (askama 0.13)
1 parent e51d8d8 commit 139f11b

File tree

15 files changed

+77
-85
lines changed

15 files changed

+77
-85
lines changed

Cargo.lock

Lines changed: 43 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ tempfile = "3.1.0"
9090
fn-error-context = "0.2.0"
9191

9292
# Templating
93-
rinja = "0.3.4"
93+
askama = "0.13"
9494
walkdir = "2"
9595

9696
# Date and Time utilities

src/utils/html.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::web::page::templates::{Body, Head, Vendored};
22
use crate::web::rustdoc::RustdocPage;
3+
use askama::Template;
34
use lol_html::element;
45
use lol_html::errors::RewritingError;
5-
use rinja::Template;
66

77
/// Rewrite a rustdoc page to have the docs.rs topbar
88
///
@@ -45,7 +45,7 @@ pub(crate) fn rewrite_lol(
4545
rustdoc_body_class.set_attribute("tabindex", "-1")?;
4646
// Change the `body` to a `div`
4747
rustdoc_body_class.set_tag_name("div")?;
48-
// Prepend the rinja content
48+
// Prepend the askama content
4949
rustdoc_body_class.prepend(&body_html, ContentType::Html);
5050
// Wrap the transformed body and topbar into a <body> element
5151
rustdoc_body_class.before(r#"<body class="rustdoc-page">"#, ContentType::Html);

src/web/build_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::{
1212
},
1313
};
1414
use anyhow::Context as _;
15+
use askama::Template;
1516
use axum::{extract::Extension, response::IntoResponse};
1617
use chrono::{DateTime, Utc};
1718
use futures_util::TryStreamExt;
18-
use rinja::Template;
1919
use semver::Version;
2020
use serde::Deserialize;
2121
use std::sync::Arc;

src/web/builds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
},
1818
};
1919
use anyhow::{Result, anyhow};
20+
use askama::Template;
2021
use axum::{
2122
Json, extract::Extension, http::header::ACCESS_CONTROL_ALLOW_ORIGIN, response::IntoResponse,
2223
};
@@ -27,7 +28,6 @@ use axum_extra::{
2728
use chrono::{DateTime, Utc};
2829
use constant_time_eq::constant_time_eq;
2930
use http::StatusCode;
30-
use rinja::Template;
3131
use semver::Version;
3232
use std::sync::Arc;
3333

src/web/crate_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ use crate::{
1818
},
1919
};
2020
use anyhow::{Context, Result, anyhow};
21+
use askama::Template;
2122
use axum::{
2223
extract::Extension,
2324
response::{IntoResponse, Response as AxumResponse},
2425
};
2526
use chrono::{DateTime, Utc};
2627
use futures_util::stream::TryStreamExt;
2728
use log::warn;
28-
use rinja::Template;
2929
use semver::Version;
3030
use serde::Deserialize;
3131
use serde_json::Value;

src/web/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
},
1414
};
1515
use anyhow::anyhow;
16+
use askama::Template;
1617
use axum::response::IntoResponse;
17-
use rinja::Template;
1818
use serde_json::Value;
1919
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
2020

src/web/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::utils::get_correct_docsrs_style_file;
1010
use crate::utils::report_error;
1111
use crate::web::page::templates::{RenderSolid, filters};
1212
use anyhow::{Context as _, Result, anyhow, bail};
13+
use askama::Template;
1314
use axum_extra::middleware::option_layer;
14-
use rinja::Template;
1515
use serde_json::Value;
1616
use tracing::{info, instrument};
1717

src/web/page/templates.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::Result;
22
use crate::web::rustdoc::RustdocPage;
33
use anyhow::Context;
4-
use rinja::Template;
4+
use askama::Template;
55
use std::sync::Arc;
66
use tracing::trace;
77

@@ -88,12 +88,12 @@ impl TemplateData {
8888
}
8989

9090
pub mod filters {
91+
use askama::filters::Safe;
9192
use chrono::{DateTime, Utc};
92-
use rinja::filters::Safe;
9393
use std::borrow::Cow;
9494

9595
// Copied from `tera`.
96-
pub fn escape_html(input: &str) -> rinja::Result<Cow<'_, str>> {
96+
pub fn escape_html(input: &str) -> askama::Result<Cow<'_, str>> {
9797
if !input.chars().any(|c| "&<>\"'/".contains(c)) {
9898
return Ok(Cow::Borrowed(input));
9999
}
@@ -115,7 +115,7 @@ pub mod filters {
115115
}
116116

117117
// Copied from `tera`.
118-
pub fn escape_xml(input: &str) -> rinja::Result<Cow<'_, str>> {
118+
pub fn escape_xml(input: &str) -> askama::Result<Cow<'_, str>> {
119119
if !input.chars().any(|c| "&<>\"'".contains(c)) {
120120
return Ok(Cow::Borrowed(input));
121121
}
@@ -135,11 +135,11 @@ pub mod filters {
135135

136136
/// Prettily format a timestamp
137137
// TODO: This can be replaced by chrono
138-
pub fn timeformat(value: &DateTime<Utc>) -> rinja::Result<String> {
138+
pub fn timeformat(value: &DateTime<Utc>) -> askama::Result<String> {
139139
Ok(crate::web::duration_to_str(*value))
140140
}
141141

142-
pub fn format_secs(mut value: f32) -> rinja::Result<String> {
142+
pub fn format_secs(mut value: f32) -> askama::Result<String> {
143143
const TIMES: &[&str] = &["seconds", "minutes", "hours"];
144144

145145
let mut chosen_time = &TIMES[0];
@@ -167,7 +167,7 @@ pub mod filters {
167167
pub fn dedent<T: std::fmt::Display, I: Into<Option<i32>>>(
168168
value: T,
169169
levels: I,
170-
) -> rinja::Result<String> {
170+
) -> askama::Result<String> {
171171
let string = value.to_string();
172172

173173
let unindented = if let Some(levels) = levels.into() {
@@ -200,7 +200,7 @@ pub mod filters {
200200
Ok(unindented)
201201
}
202202

203-
pub fn highlight(code: impl std::fmt::Display, lang: &str) -> rinja::Result<Safe<String>> {
203+
pub fn highlight(code: impl std::fmt::Display, lang: &str) -> askama::Result<Safe<String>> {
204204
let highlighted_code =
205205
crate::web::highlight::with_lang(Some(lang), &code.to_string(), None);
206206
Ok(Safe(format!(
@@ -209,7 +209,7 @@ pub mod filters {
209209
)))
210210
}
211211

212-
pub fn round(value: &f32, precision: u32) -> rinja::Result<String> {
212+
pub fn round(value: &f32, precision: u32) -> askama::Result<String> {
213213
let multiplier = if precision == 0 {
214214
1.0
215215
} else {
@@ -218,43 +218,43 @@ pub mod filters {
218218
Ok(((multiplier * *value).round() / multiplier).to_string())
219219
}
220220

221-
pub fn split_first<'a>(value: &'a str, pat: &str) -> rinja::Result<Option<&'a str>> {
221+
pub fn split_first<'a>(value: &'a str, pat: &str) -> askama::Result<Option<&'a str>> {
222222
Ok(value.split(pat).next())
223223
}
224224

225-
pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> rinja::Result<Safe<String>> {
225+
pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> askama::Result<Safe<String>> {
226226
Ok(Safe(
227227
serde_json::to_string(value).expect("`encode_json` failed"),
228228
))
229229
}
230230
}
231231

232232
pub trait RenderSolid {
233-
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
233+
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String>;
234234
}
235235

236236
impl<T: font_awesome_as_a_crate::Solid> RenderSolid for T {
237-
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
237+
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String> {
238238
render("fa-solid", self.icon_name(), fw, spin, extra)
239239
}
240240
}
241241

242242
pub trait RenderRegular {
243-
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
243+
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String>;
244244
}
245245

246246
impl<T: font_awesome_as_a_crate::Regular> RenderRegular for T {
247-
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
247+
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String> {
248248
render("fa-regular", self.icon_name(), fw, spin, extra)
249249
}
250250
}
251251

252252
pub trait RenderBrands {
253-
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
253+
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String>;
254254
}
255255

256256
impl<T: font_awesome_as_a_crate::Brands> RenderBrands for T {
257-
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
257+
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> askama::filters::Safe<String> {
258258
render("fa-brands", self.icon_name(), fw, spin, extra)
259259
}
260260
}
@@ -265,7 +265,7 @@ fn render(
265265
fw: bool,
266266
spin: bool,
267267
extra: &str,
268-
) -> rinja::filters::Safe<String> {
268+
) -> askama::filters::Safe<String> {
269269
let mut classes = Vec::new();
270270
if fw {
271271
classes.push("fa-fw");
@@ -281,5 +281,5 @@ fn render(
281281
classes = classes.join(" "),
282282
);
283283

284-
rinja::filters::Safe(icon)
284+
askama::filters::Safe(icon)
285285
}

src/web/page/web_page.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use http::header::CONTENT_LENGTH;
1010
use std::sync::Arc;
1111

1212
pub(crate) trait AddCspNonce: IntoResponse {
13-
fn render_with_csp_nonce(&mut self, csp_nonce: String) -> rinja::Result<String>;
13+
fn render_with_csp_nonce(&mut self, csp_nonce: String) -> askama::Result<String>;
1414
}
1515

1616
#[macro_export]
@@ -25,7 +25,7 @@ macro_rules! impl_axum_webpage {
2525
$(,)?
2626
) => {
2727
impl $crate::web::page::web_page::AddCspNonce for $page {
28-
fn render_with_csp_nonce(&mut self, csp_nonce: String) -> rinja::Result<String> {
28+
fn render_with_csp_nonce(&mut self, csp_nonce: String) -> askama::Result<String> {
2929
self.csp_nonce = csp_nonce;
3030
self.render()
3131
}

src/web/releases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
},
1515
};
1616
use anyhow::{Context as _, Result, anyhow};
17+
use askama::Template;
1718
use axum::{
1819
extract::{Extension, Query},
1920
response::{IntoResponse, Response as AxumResponse},
@@ -22,7 +23,6 @@ use base64::{Engine, engine::general_purpose::STANDARD as b64};
2223
use chrono::{DateTime, Utc};
2324
use futures_util::stream::TryStreamExt;
2425
use itertools::Itertools;
25-
use rinja::Template;
2626
use serde::{Deserialize, Serialize};
2727
use sqlx::Row;
2828
use std::collections::{BTreeMap, HashMap, HashSet};

0 commit comments

Comments
 (0)