Replace askama with rinja
This commit is contained in:
parent
49649bf3c5
commit
8d40b9ea6c
91
Cargo.lock
91
Cargo.lock
@ -51,6 +51,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
@ -243,47 +244,6 @@ version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||
|
||||
[[package]]
|
||||
name = "askama"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28"
|
||||
dependencies = [
|
||||
"askama_derive",
|
||||
"askama_escape",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_derive"
|
||||
version = "0.12.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83"
|
||||
dependencies = [
|
||||
"askama_parser",
|
||||
"basic-toml",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_escape"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
|
||||
|
||||
[[package]]
|
||||
name = "askama_parser"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
@ -2661,6 +2621,18 @@ version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "once_map"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa7085055bbe9c8edbd982048dbcf8181794d4a81cb04a11931673e63cc18dc6"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"hashbrown",
|
||||
"parking_lot",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "opener"
|
||||
version = "0.6.1"
|
||||
@ -3313,6 +3285,41 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rinja"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2d47a46d7729e891c8accf260e9daa02ae6d570aa2a94fb1fb27eb5364a2323"
|
||||
dependencies = [
|
||||
"rinja_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rinja_derive"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44dae9afe59d58ed8d988d67d1945f3638125d2fd2104058399382e11bd3ea2a"
|
||||
dependencies = [
|
||||
"basic-toml",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"once_map",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rinja_parser",
|
||||
"serde",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rinja_parser"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1771c78cd5d3b1646ef8d8f2ed100db936e8b291d3cc06e92a339ff346858c"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rls"
|
||||
version = "2.0.0"
|
||||
@ -4799,7 +4806,6 @@ name = "rustdoc"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"askama",
|
||||
"base64",
|
||||
"expect-test",
|
||||
"indexmap",
|
||||
@ -4807,6 +4813,7 @@ dependencies = [
|
||||
"minifier",
|
||||
"pulldown-cmark 0.9.6",
|
||||
"regex",
|
||||
"rinja",
|
||||
"rustdoc-json-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -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"
|
||||
|
@ -6,7 +6,7 @@
|
||||
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};
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
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
|
||||
|
@ -46,7 +46,7 @@
|
||||
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};
|
||||
|
@ -36,10 +36,10 @@
|
||||
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("</details>").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>>);
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use askama::Template;
|
||||
use rinja::Template;
|
||||
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -8,7 +8,7 @@
|
||||
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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user