Skip to content

Commit

Permalink
Add htmx
Browse files Browse the repository at this point in the history
  • Loading branch information
raffomania committed Dec 17, 2023
1 parent c9d7c2c commit 48a277f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ axum = { version = "0.7.2", features = ["macros", "tracing"] }
clap = { version = "4.4.11", features = ["derive", "env"] }
listenfd = "1.0.1"
tokio = { version = "1.35.0", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.5.0", features = ["tracing", "trace"] }
tower-http = { version = "0.5.0", features = ["tracing", "trace", "fs"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
9 changes: 8 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{app_error::Result, cli::ListenArgs};
use askama::Template;
use axum::{debug_handler, routing::get, Router};
use listenfd::ListenFd;
use tower_http::trace::TraceLayer;
use tower_http::{services::ServeDir, trace::TraceLayer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

pub async fn start(listen: ListenArgs) -> anyhow::Result<()> {
Expand All @@ -17,6 +17,8 @@ pub async fn start(listen: ListenArgs) -> anyhow::Result<()> {

let app = Router::new()
.route("/", get(hello))
.route("/htmx-fragment", get(htmx_fragment))
.nest_service("/static", ServeDir::new("static"))
.layer(TraceLayer::new_for_http());

let listener = if let Some(listen_address) = listen.listen {
Expand All @@ -42,3 +44,8 @@ async fn hello() -> Result<HelloTemplate> {
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate {}

#[debug_handler]
async fn htmx_fragment() -> &'static str {
"Here's some dynamically loaded content!"
}
1 change: 1 addition & 0 deletions static/htmx.1.9.9.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion templates/hello.html
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
Hello, templating!
<!DOCTYPE html>
<html>
<head>
<script src="static/htmx.1.9.9.js"></script>
</head>
<body>
<div>Hello, htmx!</div>
<button hx-get="/htmx-fragment" hx-swap="outerHTML">
load some stuff!
</button>
</body>
</html>

0 comments on commit 48a277f

Please sign in to comment.