Update to new rinja version (askama)
This commit is contained in:
parent
e0883a2a6c
commit
6966416a05
11 changed files with 75 additions and 24 deletions
55
Cargo.lock
55
Cargo.lock
|
@ -186,6 +186,48 @@ version = "0.7.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||
|
||||
[[package]]
|
||||
name = "askama"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
|
||||
dependencies = [
|
||||
"askama_derive",
|
||||
"itoa",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_derive"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
|
||||
dependencies = [
|
||||
"askama_parser",
|
||||
"basic-toml",
|
||||
"memchr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc-hash 2.1.1",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "askama_parser"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"winnow 0.7.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.4.0"
|
||||
|
@ -4619,6 +4661,7 @@ name = "rustdoc"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"askama",
|
||||
"base64",
|
||||
"expect-test",
|
||||
"indexmap",
|
||||
|
@ -4627,7 +4670,6 @@ dependencies = [
|
|||
"pulldown-cmark 0.9.6",
|
||||
"pulldown-cmark-escape",
|
||||
"regex",
|
||||
"rinja",
|
||||
"rustdoc-json-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -5418,7 +5460,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
"winnow 0.5.40",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -6429,6 +6471,15 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winsplit"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -9,7 +9,7 @@ path = "lib.rs"
|
|||
|
||||
[dependencies]
|
||||
arrayvec = { version = "0.7", default-features = false }
|
||||
rinja = { version = "0.3", default-features = false, features = ["config"] }
|
||||
askama = { version = "0.13", default-features = false, features = ["alloc", "config", "derive"] }
|
||||
base64 = "0.21.7"
|
||||
itertools = "0.12"
|
||||
indexmap = "2"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt::{self, Display};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
|
||||
use super::static_files::{STATIC_FILES, StaticFiles};
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::io;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::sync::mpsc::{Receiver, channel};
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
|
|
@ -43,7 +43,7 @@ use std::iter::Peekable;
|
|||
use std::path::PathBuf;
|
||||
use std::{fs, str};
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_attr_parsing::{
|
||||
ConstStability, DeprecatedSince, Deprecation, RustcVersion, StabilityLevel, StableSince,
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::cmp::Ordering;
|
|||
use std::fmt::{self, Display, Write as _};
|
||||
use std::iter;
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_abi::VariantIdx;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||
use rustc_hir as hir;
|
||||
|
@ -37,7 +37,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
|
|||
use crate::html::render::{document_full, document_item_info};
|
||||
use crate::html::url_parts_builder::UrlPartsBuilder;
|
||||
|
||||
/// Generates a Rinja template struct for rendering items with common methods.
|
||||
/// Generates a Askama template struct for rendering items with common methods.
|
||||
///
|
||||
/// Usage:
|
||||
/// ```ignore (illustrative)
|
||||
|
@ -301,7 +301,7 @@ fn toggle_close(mut w: impl fmt::Write) {
|
|||
w.write_str("</details>").unwrap();
|
||||
}
|
||||
|
||||
trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + Display {
|
||||
trait ItemTemplate<'a, 'cx: 'a>: askama::Template + Display {
|
||||
fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>);
|
||||
}
|
||||
|
||||
|
@ -1867,7 +1867,7 @@ fn item_proc_macro(cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) ->
|
|||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok::<(), fmt::Error>(())
|
||||
})?;
|
||||
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
|
||||
})
|
||||
|
@ -1944,7 +1944,7 @@ fn item_constant(
|
|||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok::<(), fmt::Error>(())
|
||||
})?;
|
||||
|
||||
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::CtorKind;
|
||||
use rustc_hir::def_id::{DefIdMap, DefIdSet};
|
||||
|
@ -123,10 +123,10 @@ impl<'a> Link<'a> {
|
|||
pub(crate) mod filters {
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use rinja::filters::Safe;
|
||||
use askama::filters::Safe;
|
||||
|
||||
use crate::html::escape::EscapeBodyTextWithWbr;
|
||||
pub(crate) fn wrapped<T>(v: T) -> rinja::Result<Safe<impl Display>>
|
||||
pub(crate) fn wrapped<T>(v: T) -> askama::Result<Safe<impl Display>>
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_abi::{Primitive, TagEncoding, Variants};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::span_bug;
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::ffi::OsStr;
|
|||
use std::path::{Component, Path, PathBuf};
|
||||
use std::{fmt, fs};
|
||||
|
||||
use rinja::Template;
|
||||
use askama::Template;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# Style for Templates
|
||||
|
||||
This directory has templates in the [Rinja templating language][rinjadoc], which is very
|
||||
This directory has templates in the [Askama templating language][askamadoc], which is very
|
||||
similar to [Jinja2][jinjadoc].
|
||||
|
||||
[jinjadoc]: https://jinja.palletsprojects.com/en/3.1.x/templates/
|
||||
[rinjadoc]: https://docs.rs/rinja/latest/rinja/
|
||||
[askamadoc]: https://docs.rs/askama/latest/askama/
|
||||
|
||||
We want our rendered output to have as little unnecessary whitespace as
|
||||
possible, so that pages load quickly. To achieve that we use Rinja's
|
||||
possible, so that pages load quickly. To achieve that we use Askama'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
|
||||
|
@ -18,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://rinja.readthedocs.io/en/stable/configuration.html#whitespace-control
|
||||
[whitespace control]: https://askama.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
|
||||
|
@ -26,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.
|
||||
|
||||
Rinja templates support quite sophisticated control flow. To keep our templates
|
||||
Askama 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 [Rinja
|
||||
we avoid [assignments in the template logic][assignments] and [Askama
|
||||
macros][macros]. This also may make things easier if we switch to a different
|
||||
Jinja-style template system in the future.
|
||||
|
||||
[assignments]: https://rinja.readthedocs.io/en/stable/template_syntax.html#assignments
|
||||
[macros]: https://rinja.readthedocs.io/en/stable/template_syntax.html#macros
|
||||
[assignments]: https://askama.readthedocs.io/en/stable/template_syntax.html#assignments
|
||||
[macros]: https://askama.readthedocs.io/en/stable/template_syntax.html#macros
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue