")]
+pub fn hello(name: &str) -> Template {
+ Template::render(
+ "minijinja/index",
+ context! {
+ title: "Hello",
+ name: Some(name),
+ items: vec!["One", "Two", "Three"],
+ },
+ )
+}
+
+#[get("/about")]
+pub fn about() -> Template {
+ Template::render(
+ "minijinja/about.html",
+ context! {
+ title: "About",
+ },
+ )
+}
+
+#[catch(404)]
+pub fn not_found(req: &Request<'_>) -> Template {
+ println!("Handling 404 for URI: {}", req.uri());
+
+ Template::render(
+ "minijinja/error/404",
+ context! {
+ uri: req.uri()
+ },
+ )
+}
+
+pub fn customize(env: &mut Environment) {
+ env.add_template(
+ "minijinja/about.html",
+ r#"
+ {% extends "minijinja/layout" %}
+
+ {% block page %}
+
+ About - Here's another page!
+
+ {% endblock %}
+ "#,
+ )
+ .expect("valid Jinja2 template");
+}
diff --git a/examples/templating/src/tests.rs b/examples/templating/src/tests.rs
index afdbc0450c..449840386c 100644
--- a/examples/templating/src/tests.rs
+++ b/examples/templating/src/tests.rs
@@ -40,11 +40,11 @@ fn test_404(base: &str) {
let client = Client::tracked(rocket()).unwrap();
for bad_path in &["/hello", "/foo/bar", "/404"] {
let path = format!("/{}{}", base, bad_path);
- let escaped_path = RawStr::new(&path).html_escape();
+ let escaped_path = RawStr::new(&path).html_escape().to_lowercase();
let response = client.get(&path).dispatch();
assert_eq!(response.status(), Status::NotFound);
- let response = response.into_string().unwrap();
+ let response = response.into_string().unwrap().to_lowercase();
assert!(response.contains(base));
assert! {
@@ -66,6 +66,7 @@ fn test_index() {
let response = client.get("/").dispatch().into_string().unwrap();
assert!(response.contains("Tera"));
assert!(response.contains("Handlebars"));
+ assert!(response.contains("MiniJinja"));
}
#[test]
@@ -83,3 +84,11 @@ fn tera() {
test_404("tera");
test_about("tera");
}
+
+#[test]
+fn minijinja() {
+ test_root("minijinja");
+ test_name("minijinja");
+ test_404("minijinja");
+ test_about("minijinja");
+}
\ No newline at end of file
diff --git a/examples/templating/templates/minijinja/error/404.html.j2 b/examples/templating/templates/minijinja/error/404.html.j2
new file mode 100644
index 0000000000..b04eb553f7
--- /dev/null
+++ b/examples/templating/templates/minijinja/error/404.html.j2
@@ -0,0 +1,11 @@
+
+
+
+
+ 404 - minijinja
+
+
+ 404: Hey! There's nothing here.
+ The page at {{ uri }} does not exist!
+
+
diff --git a/examples/templating/templates/minijinja/footer.html.j2 b/examples/templating/templates/minijinja/footer.html.j2
new file mode 100644
index 0000000000..98266dbe77
--- /dev/null
+++ b/examples/templating/templates/minijinja/footer.html.j2
@@ -0,0 +1,3 @@
+
diff --git a/examples/templating/templates/minijinja/index.html.j2 b/examples/templating/templates/minijinja/index.html.j2
new file mode 100644
index 0000000000..55b6ba7ea0
--- /dev/null
+++ b/examples/templating/templates/minijinja/index.html.j2
@@ -0,0 +1,17 @@
+{% extends "minijinja/layout" %}
+
+{% block page %}
+
+ Hi {{ name }}!
+ Here are your items:
+
+ {% for item in items %}
+ - {{ item }}
+ {% endfor %}
+
+
+
+
+{% endblock %}
diff --git a/examples/templating/templates/minijinja/layout.html.j2 b/examples/templating/templates/minijinja/layout.html.j2
new file mode 100644
index 0000000000..b3c2ff844b
--- /dev/null
+++ b/examples/templating/templates/minijinja/layout.html.j2
@@ -0,0 +1,11 @@
+
+
+
+ Rocket Example - {{ title }}
+
+
+ {% include "minijinja/nav" %}
+ {% block page %}{% endblock %}
+ {% include "minijinja/footer" %}
+
+
diff --git a/examples/templating/templates/minijinja/nav.html.j2 b/examples/templating/templates/minijinja/nav.html.j2
new file mode 100644
index 0000000000..67dcde4348
--- /dev/null
+++ b/examples/templating/templates/minijinja/nav.html.j2
@@ -0,0 +1 @@
+Hello | About