Skip to content

Commit

Permalink
Add basic templating
Browse files Browse the repository at this point in the history
  • Loading branch information
raffomania committed Dec 12, 2023
1 parent 9f0956e commit 1cf5f2d
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
131 changes: 131 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
askama = { version = "0.12.1", features = ["with-axum"] }
askama_axum = "0.4.0"
axum = { version = "0.7.2", features = ["macros", "tracing"] }
clap = { version = "4.4.11", features = ["derive", "env"] }
listenfd = "1.0.1"
Expand Down
9 changes: 7 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use askama::Template;
use axum::{debug_handler, routing::get, Router};
use listenfd::ListenFd;
use tower_http::trace::TraceLayer;
Expand Down Expand Up @@ -29,6 +30,10 @@ pub async fn start(listen_address: Option<String>) {
}

#[debug_handler]
async fn hello() -> &'static str {
"Hello, Web!"
async fn hello() -> HelloTemplate {
HelloTemplate {}
}

#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate {}
1 change: 1 addition & 0 deletions templates/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, templating!

0 comments on commit 1cf5f2d

Please sign in to comment.