Skip to content

Commit 6966416

Browse files
Update to new rinja version (askama)
1 parent e0883a2 commit 6966416

File tree

11 files changed

+75
-24
lines changed

11 files changed

+75
-24
lines changed

Cargo.lock

+53-2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,48 @@ version = "0.7.6"
186186
source = "registry+https://github.com/rust-lang/crates.io-index"
187187
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
188188

189+
[[package]]
190+
name = "askama"
191+
version = "0.13.0"
192+
source = "registry+https://github.com/rust-lang/crates.io-index"
193+
checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
194+
dependencies = [
195+
"askama_derive",
196+
"itoa",
197+
"percent-encoding",
198+
"serde",
199+
"serde_json",
200+
]
201+
202+
[[package]]
203+
name = "askama_derive"
204+
version = "0.13.0"
205+
source = "registry+https://github.com/rust-lang/crates.io-index"
206+
checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
207+
dependencies = [
208+
"askama_parser",
209+
"basic-toml",
210+
"memchr",
211+
"proc-macro2",
212+
"quote",
213+
"rustc-hash 2.1.1",
214+
"serde",
215+
"serde_derive",
216+
"syn 2.0.100",
217+
]
218+
219+
[[package]]
220+
name = "askama_parser"
221+
version = "0.13.0"
222+
source = "registry+https://github.com/rust-lang/crates.io-index"
223+
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
224+
dependencies = [
225+
"memchr",
226+
"serde",
227+
"serde_derive",
228+
"winnow 0.7.4",
229+
]
230+
189231
[[package]]
190232
name = "autocfg"
191233
version = "1.4.0"
@@ -4619,6 +4661,7 @@ name = "rustdoc"
46194661
version = "0.0.0"
46204662
dependencies = [
46214663
"arrayvec",
4664+
"askama",
46224665
"base64",
46234666
"expect-test",
46244667
"indexmap",
@@ -4627,7 +4670,6 @@ dependencies = [
46274670
"pulldown-cmark 0.9.6",
46284671
"pulldown-cmark-escape",
46294672
"regex",
4630-
"rinja",
46314673
"rustdoc-json-types",
46324674
"serde",
46334675
"serde_json",
@@ -5418,7 +5460,7 @@ dependencies = [
54185460
"serde",
54195461
"serde_spanned",
54205462
"toml_datetime",
5421-
"winnow",
5463+
"winnow 0.5.40",
54225464
]
54235465

54245466
[[package]]
@@ -6429,6 +6471,15 @@ dependencies = [
64296471
"memchr",
64306472
]
64316473

6474+
[[package]]
6475+
name = "winnow"
6476+
version = "0.7.4"
6477+
source = "registry+https://github.com/rust-lang/crates.io-index"
6478+
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
6479+
dependencies = [
6480+
"memchr",
6481+
]
6482+
64326483
[[package]]
64336484
name = "winsplit"
64346485
version = "0.1.0"

src/librustdoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ path = "lib.rs"
99

1010
[dependencies]
1111
arrayvec = { version = "0.7", default-features = false }
12-
rinja = { version = "0.3", default-features = false, features = ["config"] }
12+
askama = { version = "0.13", default-features = false, features = ["alloc", "config", "derive"] }
1313
base64 = "0.21.7"
1414
itertools = "0.12"
1515
indexmap = "2"
File renamed without changes.

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{self, Display};
22
use std::path::PathBuf;
33

4-
use rinja::Template;
4+
use askama::Template;
55
use rustc_data_structures::fx::FxIndexMap;
66

77
use super::static_files::{STATIC_FILES, StaticFiles};

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io;
55
use std::path::{Path, PathBuf};
66
use std::sync::mpsc::{Receiver, channel};
77

8-
use rinja::Template;
8+
use askama::Template;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
1010
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1111
use rustc_middle::ty::TyCtxt;

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::iter::Peekable;
4343
use std::path::PathBuf;
4444
use std::{fs, str};
4545

46-
use rinja::Template;
46+
use askama::Template;
4747
use rustc_attr_parsing::{
4848
ConstStability, DeprecatedSince, Deprecation, RustcVersion, StabilityLevel, StableSince,
4949
};

src/librustdoc/html/render/print_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp::Ordering;
22
use std::fmt::{self, Display, Write as _};
33
use std::iter;
44

5-
use rinja::Template;
5+
use askama::Template;
66
use rustc_abi::VariantIdx;
77
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
88
use rustc_hir as hir;
@@ -37,7 +37,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3737
use crate::html::render::{document_full, document_item_info};
3838
use crate::html::url_parts_builder::UrlPartsBuilder;
3939

40-
/// Generates a Rinja template struct for rendering items with common methods.
40+
/// Generates a Askama template struct for rendering items with common methods.
4141
///
4242
/// Usage:
4343
/// ```ignore (illustrative)
@@ -301,7 +301,7 @@ fn toggle_close(mut w: impl fmt::Write) {
301301
w.write_str("</details>").unwrap();
302302
}
303303

304-
trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + Display {
304+
trait ItemTemplate<'a, 'cx: 'a>: askama::Template + Display {
305305
fn item_and_cx(&self) -> (&'a clean::Item, &'a Context<'cx>);
306306
}
307307

@@ -1867,7 +1867,7 @@ fn item_proc_macro(cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) ->
18671867
}
18681868
}
18691869
}
1870-
Ok(())
1870+
Ok::<(), fmt::Error>(())
18711871
})?;
18721872
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
18731873
})
@@ -1944,7 +1944,7 @@ fn item_constant(
19441944
}
19451945
}
19461946
}
1947-
Ok(())
1947+
Ok::<(), fmt::Error>(())
19481948
})?;
19491949

19501950
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))

src/librustdoc/html/render/sidebar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22
use std::cmp::Ordering;
33

4-
use rinja::Template;
4+
use askama::Template;
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_hir::def::CtorKind;
77
use rustc_hir::def_id::{DefIdMap, DefIdSet};
@@ -123,10 +123,10 @@ impl<'a> Link<'a> {
123123
pub(crate) mod filters {
124124
use std::fmt::{self, Display};
125125

126-
use rinja::filters::Safe;
126+
use askama::filters::Safe;
127127

128128
use crate::html::escape::EscapeBodyTextWithWbr;
129-
pub(crate) fn wrapped<T>(v: T) -> rinja::Result<Safe<impl Display>>
129+
pub(crate) fn wrapped<T>(v: T) -> askama::Result<Safe<impl Display>>
130130
where
131131
T: Display,
132132
{

src/librustdoc/html/render/type_layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use rinja::Template;
3+
use askama::Template;
44
use rustc_abi::{Primitive, TagEncoding, Variants};
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::span_bug;

src/librustdoc/html/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::OsStr;
33
use std::path::{Component, Path, PathBuf};
44
use std::{fmt, fs};
55

6-
use rinja::Template;
6+
use askama::Template;
77
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
88
use rustc_hir::def_id::LOCAL_CRATE;
99
use rustc_middle::ty::TyCtxt;
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Style for Templates
22

3-
This directory has templates in the [Rinja templating language][rinjadoc], which is very
3+
This directory has templates in the [Askama templating language][askamadoc], which is very
44
similar to [Jinja2][jinjadoc].
55

66
[jinjadoc]: https://jinja.palletsprojects.com/en/3.1.x/templates/
7-
[rinjadoc]: https://docs.rs/rinja/latest/rinja/
7+
[askamadoc]: https://docs.rs/askama/latest/askama/
88

99
We want our rendered output to have as little unnecessary whitespace as
10-
possible, so that pages load quickly. To achieve that we use Rinja's
10+
possible, so that pages load quickly. To achieve that we use Askama's
1111
[whitespace control] features. By default, whitespace characters are removed
1212
around jinja tags (`{% %}` for example). At the end of most lines, we put an
1313
empty comment tag: `{# #}`. This causes all whitespace between the end of the
@@ -18,19 +18,19 @@ remove following whitespace but not preceding. We also use the whitespace
1818
control characters in most instances of tags with control flow, for example
1919
`{% if foo %}`.
2020

21-
[whitespace control]: https://rinja.readthedocs.io/en/stable/configuration.html#whitespace-control
21+
[whitespace control]: https://askama.readthedocs.io/en/stable/configuration.html#whitespace-control
2222

2323
We want our templates to be readable, so we use indentation and newlines
2424
liberally. We indent by four spaces after opening an HTML tag _or_ a Jinja
2525
tag. In most cases an HTML tag should be followed by a newline, but if the
2626
tag has simple contents and fits with its close tag on a single line, the
2727
contents don't necessarily need a new line.
2828

29-
Rinja templates support quite sophisticated control flow. To keep our templates
29+
Askama templates support quite sophisticated control flow. To keep our templates
3030
simple and understandable, we use only a subset: `if` and `for`. In particular
31-
we avoid [assignments in the template logic][assignments] and [Rinja
31+
we avoid [assignments in the template logic][assignments] and [Askama
3232
macros][macros]. This also may make things easier if we switch to a different
3333
Jinja-style template system in the future.
3434

35-
[assignments]: https://rinja.readthedocs.io/en/stable/template_syntax.html#assignments
36-
[macros]: https://rinja.readthedocs.io/en/stable/template_syntax.html#macros
35+
[assignments]: https://askama.readthedocs.io/en/stable/template_syntax.html#assignments
36+
[macros]: https://askama.readthedocs.io/en/stable/template_syntax.html#macros

0 commit comments

Comments
 (0)