From 8d40b9ea6c253b58fcc28af5eaaf55d44b6ee165 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Jul 2024 20:56:36 +0200 Subject: Replace askama with rinja --- src/librustdoc/Cargo.toml | 2 +- src/librustdoc/askama.toml | 3 --- src/librustdoc/html/layout.rs | 2 +- src/librustdoc/html/render/context.rs | 2 +- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/render/print_item.rs | 6 +++--- src/librustdoc/html/render/sidebar.rs | 2 +- src/librustdoc/html/render/type_layout.rs | 2 +- src/librustdoc/html/sources.rs | 2 +- src/librustdoc/html/templates/STYLE.md | 20 +++++++++----------- src/librustdoc/rinja.toml | 3 +++ 11 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 src/librustdoc/askama.toml create mode 100644 src/librustdoc/rinja.toml (limited to 'src') diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 51fb126cb34..fe531f0ff59 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -8,7 +8,7 @@ path = "lib.rs" [dependencies] arrayvec = { version = "0.7", default-features = false } -askama = { version = "0.12", default-features = false, features = ["config"] } +rinja = { version = "0.2", default-features = false, features = ["config"] } base64 = "0.21.7" itertools = "0.12" indexmap = "2" diff --git a/src/librustdoc/askama.toml b/src/librustdoc/askama.toml deleted file mode 100644 index 2732c4bc61e..00000000000 --- a/src/librustdoc/askama.toml +++ /dev/null @@ -1,3 +0,0 @@ -[general] -dirs = ["html/templates"] -whitespace = "suppress" diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index d4b4db0f3fd..22576b76e41 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -6,7 +6,7 @@ use crate::externalfiles::ExternalHtml; use crate::html::format::{Buffer, Print}; use crate::html::render::{ensure_trailing_slash, StylePath}; -use askama::Template; +use rinja::Template; use super::static_files::{StaticFiles, STATIC_FILES}; diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index db1119eca1d..7718413c956 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -36,7 +36,7 @@ use crate::html::url_parts_builder::UrlPartsBuilder; use crate::html::{layout, sources, static_files}; use crate::scrape_examples::AllCallLocations; use crate::try_err; -use askama::Template; +use rinja::Template; /// Major driving force in all rustdoc rendering. This contains information /// about where in the tree-like hierarchy rendering is occurring and controls diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 877a00e206d..5b9ef67109c 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -46,7 +46,7 @@ use std::path::PathBuf; use std::rc::Rc; use std::str; -use askama::Template; +use rinja::Template; use rustc_attr::{ConstStability, DeprecatedSince, Deprecation, StabilityLevel, StableSince}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 9256330ac7c..a04313b4b79 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -36,10 +36,10 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine}; use crate::html::render::{document_full, document_item_info}; use crate::html::url_parts_builder::UrlPartsBuilder; -use askama::Template; use itertools::Itertools; +use rinja::Template; -/// Generates an Askama template struct for rendering items with common methods. +/// Generates a Rinja template struct for rendering items with common methods. /// /// Usage: /// ```ignore (illustrative) @@ -309,7 +309,7 @@ fn toggle_close(mut w: impl fmt::Write) { w.write_str("").unwrap(); } -trait ItemTemplate<'a, 'cx: 'a>: askama::Template + fmt::Display { +trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + fmt::Display { fn item_and_mut_cx(&self) -> (&'a clean::Item, RefMut<'_, &'a mut Context<'cx>>); } diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 3d28937eb99..e5bc2ace203 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, rc::Rc}; -use askama::Template; +use rinja::Template; use rustc_data_structures::fx::FxHashSet; use rustc_hir::{def::CtorKind, def_id::DefIdSet}; use rustc_middle::ty::{self, TyCtxt}; diff --git a/src/librustdoc/html/render/type_layout.rs b/src/librustdoc/html/render/type_layout.rs index a27e327f235..35a38d5375f 100644 --- a/src/librustdoc/html/render/type_layout.rs +++ b/src/librustdoc/html/render/type_layout.rs @@ -1,4 +1,4 @@ -use askama::Template; +use rinja::Template; use rustc_data_structures::captures::Captures; use rustc_hir::def_id::DefId; diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index d4b1da71b40..7b4d1fa5305 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -8,7 +8,7 @@ use crate::html::layout; use crate::html::render::Context; use crate::visit::DocVisitor; -use askama::Template; +use rinja::Template; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::ty::TyCtxt; diff --git a/src/librustdoc/html/templates/STYLE.md b/src/librustdoc/html/templates/STYLE.md index 38aac2a60e9..32bacb11475 100644 --- a/src/librustdoc/html/templates/STYLE.md +++ b/src/librustdoc/html/templates/STYLE.md @@ -1,15 +1,13 @@ # Style for Templates -This directory has templates in the [Tera templating language][teradoc], which is very -similar to [Jinja2][jinjadoc] and [Django][djangodoc] templates, and also to [Askama][askamadoc]. +This directory has templates in the [Rinja templating language][rinjadoc], which is very +similar to [Jinja2][jinjadoc]. -[teradoc]: https://tera.netlify.app/docs/#templates [jinjadoc]: https://jinja.palletsprojects.com/en/3.1.x/templates/ -[djangodoc]: https://docs.djangoproject.com/en/4.1/topics/templates/ -[askamadoc]: https://docs.rs/askama/latest/askama/ +[rinjadoc]: https://docs.rs/rinja/latest/rinja/ We want our rendered output to have as little unnecessary whitespace as -possible, so that pages load quickly. To achieve that we use Tera's +possible, so that pages load quickly. To achieve that we use Rinja's [whitespace control] features. By default, whitespace characters are removed around jinja tags (`{% %}` for example). At the end of most lines, we put an empty comment tag: `{# #}`. This causes all whitespace between the end of the @@ -20,7 +18,7 @@ remove following whitespace but not preceding. We also use the whitespace control characters in most instances of tags with control flow, for example `{% if foo %}`. -[whitespace control]: https://tera.netlify.app/docs/#whitespace-control +[whitespace control]: https://rinja.readthedocs.io/en/stable/configuration.html#whitespace-control We want our templates to be readable, so we use indentation and newlines liberally. We indent by four spaces after opening an HTML tag _or_ a Jinja @@ -28,11 +26,11 @@ tag. In most cases an HTML tag should be followed by a newline, but if the tag has simple contents and fits with its close tag on a single line, the contents don't necessarily need a new line. -Askama templates support quite sophisticated control flow. To keep our templates +Rinja templates support quite sophisticated control flow. To keep our templates simple and understandable, we use only a subset: `if` and `for`. In particular -we avoid [assignments in the template logic][assignments] and [Askama +we avoid [assignments in the template logic][assignments] and [Rinja macros][macros]. This also may make things easier if we switch to a different Jinja-style template system in the future. -[assignments]: https://djc.github.io/askama/template_syntax.html#assignments -[macros]: https://djc.github.io/askama/template_syntax.html#macros +[assignments]: https://rinja.readthedocs.io/en/stable/template_syntax.html#assignments +[macros]: https://rinja.readthedocs.io/en/stable/template_syntax.html#macros diff --git a/src/librustdoc/rinja.toml b/src/librustdoc/rinja.toml new file mode 100644 index 00000000000..2732c4bc61e --- /dev/null +++ b/src/librustdoc/rinja.toml @@ -0,0 +1,3 @@ +[general] +dirs = ["html/templates"] +whitespace = "suppress" -- cgit 1.4.1-3-g733a5