Implement basic templating
This commit is contained in:
parent
234458e11c
commit
1cf099845b
5 changed files with 1317 additions and 85 deletions
1375
Cargo.lock
generated
1375
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -7,3 +7,5 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = "=0.5.0-rc.3"
|
rocket = "=0.5.0-rc.3"
|
||||||
|
rocket_contrib = { version = "0.4.11", features = ["templates"] }
|
||||||
|
rocket_dyn_templates = { version = "0.1.0-rc.3", features = ["tera"] }
|
||||||
|
|
2
Rocket.toml
Normal file
2
Rocket.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[default]
|
||||||
|
template_dir = "templates"
|
14
src/main.rs
14
src/main.rs
|
@ -1,11 +1,19 @@
|
||||||
#[macro_use] extern crate rocket;
|
#[macro_use] extern crate rocket;
|
||||||
|
|
||||||
|
use rocket_dyn_templates::{Template, context};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> &'static str {
|
fn index() -> Template {
|
||||||
"Hello, world!"
|
Template::render("index", context! {
|
||||||
|
challenge: 114,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
fn rocket() -> _ {
|
fn rocket() -> _ {
|
||||||
rocket::build().mount("/", routes![index])
|
let config = rocket::Config::figment()
|
||||||
|
.merge(("port", 1313));
|
||||||
|
rocket::custom(config)
|
||||||
|
.mount("/", routes![index])
|
||||||
|
.attach(Template::fairing())
|
||||||
}
|
}
|
9
templates/index.html.tera
Normal file
9
templates/index.html.tera
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Tegaki Tuesday</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to Tegaki Tuesday #{{ challenge }}!</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue