Skip to content

Commit abd4ad6

Browse files
committed
Update tera to 2.3
1 parent 45631dd commit abd4ad6

4 files changed

Lines changed: 33 additions & 22 deletions

File tree

tools/build-templated-pages/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ license = "MIT OR Apache-2.0"
99
toml_edit = { version = "0.25.1", default-features = false, features = [
1010
"parse",
1111
] }
12-
tera = "2.2"
12+
tera = { version = "2.3", features = ["glob_fs", "preserve_order"] }
13+
tera-contrib = { version = "0.3", features = ["slug"] }
1314
serde = { version = "1.0", features = ["derive"] }
1415
bitflags = "2.3"
1516
hashbrown = { version = "0.16.0", features = ["serde"] }

tools/build-templated-pages/src/examples.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use alloc::collections::BTreeMap;
12
use core::cmp::Ordering;
23
use std::fs::File;
34

4-
use hashbrown::HashMap;
55
use serde::Serialize;
66
use tera::{Context, Tera};
77
use toml_edit::{DocumentMut, Item};
@@ -81,7 +81,7 @@ fn parse_examples(panic_on_missing: bool) -> Vec<Example> {
8181
.collect()
8282
}
8383

84-
fn parse_categories() -> HashMap<Box<str>, String> {
84+
fn parse_categories() -> BTreeMap<String, String> {
8585
let manifest_file = std::fs::read_to_string("Cargo.toml").unwrap();
8686
let manifest = manifest_file.parse::<DocumentMut>().unwrap();
8787
manifest
@@ -108,10 +108,10 @@ pub(crate) fn check(what_to_run: Command) {
108108

109109
if what_to_run.contains(Command::UPDATE) {
110110
let categories = parse_categories();
111-
let examples_by_category: HashMap<Box<str>, Category> = examples
111+
let examples_by_category: BTreeMap<String, Category> = examples
112112
.into_iter()
113-
.fold(HashMap::<Box<str>, Vec<Example>>::new(), |mut v, ex| {
114-
v.entry_ref(ex.category.as_str()).or_default().push(ex);
113+
.fold(BTreeMap::<String, Vec<Example>>::new(), |mut v, ex| {
114+
v.entry(ex.category.clone()).or_default().push(ex);
115115
v
116116
})
117117
.into_iter()
@@ -130,13 +130,16 @@ pub(crate) fn check(what_to_run: Command) {
130130

131131
let mut context = Context::new();
132132
context.insert("all_examples", &examples_by_category);
133-
Tera::new("docs-template/*.md.tpl")
134-
.expect("error parsing template")
135-
.render_to(
136-
"EXAMPLE_README.md.tpl",
137-
&context,
138-
File::create("examples/README.md").expect("error creating file"),
139-
)
140-
.expect("error rendering template");
133+
let mut tera = Tera::new();
134+
tera.register_filter("slugify", tera_contrib::slug::slug);
135+
tera.load_from_glob("docs-template/*.md.tpl")
136+
.expect("error parsing template");
137+
138+
tera.render_to(
139+
"EXAMPLE_README.md.tpl",
140+
&context,
141+
File::create("examples/README.md").expect("error creating file"),
142+
)
143+
.expect("error rendering template");
141144
}
142145
}

tools/build-templated-pages/src/features.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,18 @@ pub(crate) fn check(what_to_run: Command) {
124124
let mut context = Context::new();
125125
context.insert("features", &features);
126126
context.insert("sorted_features", &sorted_features);
127-
Tera::new("docs-template/*.md.tpl")
128-
.expect("error parsing template")
129-
.render_to(
130-
"features.md.tpl",
131-
&context,
132-
File::create("docs/cargo_features.md").expect("error creating file"),
133-
)
134-
.expect("error rendering template");
127+
128+
let mut tera = Tera::new();
129+
tera.register_filter("slugify", tera_contrib::slug::slug);
130+
131+
tera.load_from_glob("docs-template/*.md.tpl")
132+
.expect("error parsing template");
133+
134+
tera.render_to(
135+
"features.md.tpl",
136+
&context,
137+
File::create("docs/cargo_features.md").expect("error creating file"),
138+
)
139+
.expect("error rendering template");
135140
}
136141
}

tools/build-templated-pages/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tool used to build the templated pages of the Bevy website.
22
3+
extern crate alloc;
4+
35
use bitflags::bitflags;
46

57
mod examples;

0 commit comments

Comments
 (0)