feat: embed htmx
							parent
							
								
									35f1433e40
								
							
						
					
					
						commit
						412f4cd2c7
					
				|  | @ -38,6 +38,21 @@ dependencies = [ | ||||||
|  "memchr", |  "memchr", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "alloc-no-stdlib" | ||||||
|  | version = "2.0.4" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" | ||||||
|  | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "alloc-stdlib" | ||||||
|  | version = "0.2.2" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" | ||||||
|  | dependencies = [ | ||||||
|  |  "alloc-no-stdlib", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "android-tzdata" | name = "android-tzdata" | ||||||
| version = "0.1.1" | version = "0.1.1" | ||||||
|  | @ -53,6 +68,20 @@ dependencies = [ | ||||||
|  "libc", |  "libc", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "async-compression" | ||||||
|  | version = "0.4.18" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "df895a515f70646414f4b45c0b79082783b80552b373a68283012928df56f522" | ||||||
|  | dependencies = [ | ||||||
|  |  "brotli", | ||||||
|  |  "flate2", | ||||||
|  |  "futures-core", | ||||||
|  |  "memchr", | ||||||
|  |  "pin-project-lite", | ||||||
|  |  "tokio", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "async-trait" | name = "async-trait" | ||||||
| version = "0.1.83" | version = "0.1.83" | ||||||
|  | @ -167,6 +196,27 @@ dependencies = [ | ||||||
|  "generic-array", |  "generic-array", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "brotli" | ||||||
|  | version = "7.0.0" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" | ||||||
|  | dependencies = [ | ||||||
|  |  "alloc-no-stdlib", | ||||||
|  |  "alloc-stdlib", | ||||||
|  |  "brotli-decompressor", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "brotli-decompressor" | ||||||
|  | version = "4.0.1" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" | ||||||
|  | dependencies = [ | ||||||
|  |  "alloc-no-stdlib", | ||||||
|  |  "alloc-stdlib", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "bstr" | name = "bstr" | ||||||
| version = "1.11.1" | version = "1.11.1" | ||||||
|  | @ -206,6 +256,7 @@ dependencies = [ | ||||||
|  "serde", |  "serde", | ||||||
|  "tera", |  "tera", | ||||||
|  "tokio", |  "tokio", | ||||||
|  |  "tower-http", | ||||||
|  "tracing", |  "tracing", | ||||||
|  "tracing-subscriber", |  "tracing-subscriber", | ||||||
| ] | ] | ||||||
|  | @ -276,6 +327,15 @@ dependencies = [ | ||||||
|  "libc", |  "libc", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "crc32fast" | ||||||
|  | version = "1.4.2" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" | ||||||
|  | dependencies = [ | ||||||
|  |  "cfg-if", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "crossbeam-deque" | name = "crossbeam-deque" | ||||||
| version = "0.8.6" | version = "0.8.6" | ||||||
|  | @ -339,6 +399,16 @@ version = "0.1.9" | ||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" | checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "flate2" | ||||||
|  | version = "1.0.35" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" | ||||||
|  | dependencies = [ | ||||||
|  |  "crc32fast", | ||||||
|  |  "miniz_oxide", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "fnv" | name = "fnv" | ||||||
| version = "1.0.7" | version = "1.0.7" | ||||||
|  | @ -369,6 +439,12 @@ version = "0.3.31" | ||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" | checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "futures-sink" | ||||||
|  | version = "0.3.31" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "futures-task" | name = "futures-task" | ||||||
| version = "0.3.31" | version = "0.3.31" | ||||||
|  | @ -1254,6 +1330,19 @@ dependencies = [ | ||||||
|  "syn", |  "syn", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "tokio-util" | ||||||
|  | version = "0.7.13" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" | ||||||
|  | dependencies = [ | ||||||
|  |  "bytes", | ||||||
|  |  "futures-core", | ||||||
|  |  "futures-sink", | ||||||
|  |  "pin-project-lite", | ||||||
|  |  "tokio", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "tower" | name = "tower" | ||||||
| version = "0.5.2" | version = "0.5.2" | ||||||
|  | @ -1270,6 +1359,25 @@ dependencies = [ | ||||||
|  "tracing", |  "tracing", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "tower-http" | ||||||
|  | version = "0.6.2" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" | ||||||
|  | dependencies = [ | ||||||
|  |  "async-compression", | ||||||
|  |  "bitflags", | ||||||
|  |  "bytes", | ||||||
|  |  "futures-core", | ||||||
|  |  "http", | ||||||
|  |  "http-body", | ||||||
|  |  "pin-project-lite", | ||||||
|  |  "tokio", | ||||||
|  |  "tokio-util", | ||||||
|  |  "tower-layer", | ||||||
|  |  "tower-service", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "tower-layer" | name = "tower-layer" | ||||||
| version = "0.3.3" | version = "0.3.3" | ||||||
|  |  | ||||||
|  | @ -11,5 +11,6 @@ r2d2_sqlite = "0.25.0" | ||||||
| serde = { version = "1.0.217", features = ["derive"] } | serde = { version = "1.0.217", features = ["derive"] } | ||||||
| tera = "1.20.0" | tera = "1.20.0" | ||||||
| tokio = { version = "1.42.0", features = ["full"] } | tokio = { version = "1.42.0", features = ["full"] } | ||||||
|  | tower-http = { version = "0.6.2", features = ["compression-br", "compression-gzip"] } | ||||||
| tracing = "0.1.41" | tracing = "0.1.41" | ||||||
| tracing-subscriber = "0.3.19" | tracing-subscriber = "0.3.19" | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ use std::sync::Arc; | ||||||
| 
 | 
 | ||||||
| use r2d2_sqlite::{rusqlite, SqliteConnectionManager}; | use r2d2_sqlite::{rusqlite, SqliteConnectionManager}; | ||||||
| use tera::Tera; | use tera::Tera; | ||||||
|  | use tower_http::compression::CompressionLayer; | ||||||
| 
 | 
 | ||||||
| pub type DbPool = r2d2::Pool<SqliteConnectionManager>; | pub type DbPool = r2d2::Pool<SqliteConnectionManager>; | ||||||
| 
 | 
 | ||||||
|  | @ -11,6 +12,10 @@ const MIGRATIONS: [&str; 2] = [ | ||||||
|     include_str!("migrations/000_initial.sql"), |     include_str!("migrations/000_initial.sql"), | ||||||
|     include_str!("migrations/001_plants.sql"), |     include_str!("migrations/001_plants.sql"), | ||||||
| ]; | ]; | ||||||
|  | const STATIC_FILES: [(&str, &'static str); 1] = [( | ||||||
|  |     "htmx_2.0.4.min.js", | ||||||
|  |     include_str!("static/htmx_2.0.4.min.js"), | ||||||
|  | )]; | ||||||
| 
 | 
 | ||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
| pub struct Context { | pub struct Context { | ||||||
|  | @ -31,7 +36,7 @@ async fn main() { | ||||||
|         pool, |         pool, | ||||||
|         tera: Arc::new(tera), |         tera: Arc::new(tera), | ||||||
|     }; |     }; | ||||||
|     let app = server::app(ctx); |     let app = server::app(ctx).layer(CompressionLayer::new().br(true).gzip(true)); | ||||||
| 
 | 
 | ||||||
|     let address = "0.0.0.0:8000"; |     let address = "0.0.0.0:8000"; | ||||||
| 
 | 
 | ||||||
|  | @ -80,6 +85,7 @@ fn load_templates() -> Tera { | ||||||
| 
 | 
 | ||||||
|     tera.add_raw_templates(vec![ |     tera.add_raw_templates(vec![ | ||||||
|         ("index.html", include_str!("templates/index.html")), |         ("index.html", include_str!("templates/index.html")), | ||||||
|  |         ("plants_ul.html", include_str!("templates/plants_ul.html")), | ||||||
|         ("plant_li.html", include_str!("templates/plant_li.html")), |         ("plant_li.html", include_str!("templates/plant_li.html")), | ||||||
|     ]) |     ]) | ||||||
|     .unwrap(); |     .unwrap(); | ||||||
|  |  | ||||||
|  | @ -30,10 +30,15 @@ impl TryFrom<&Row<'_>> for Plant { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn app(ctx: crate::Context) -> axum::Router { | pub fn app(ctx: crate::Context) -> axum::Router { | ||||||
|     Router::new() |     let mut router = Router::new() | ||||||
|         .route("/", get(get_index)) |         .route("/", get(get_index)) | ||||||
|         .route("/plants", post(post_plants)) |         .route("/plants", post(post_plants)); | ||||||
|         .with_state(ctx) | 
 | ||||||
|  |     for (name, content) in crate::STATIC_FILES { | ||||||
|  |         router = router.route(&format!("/static/{}", name), get(content)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     router.with_state(ctx) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async fn get_index(State(ctx): State<crate::Context>) -> Html<String> { | async fn get_index(State(ctx): State<crate::Context>) -> Html<String> { | ||||||
|  |  | ||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -1,15 +1,12 @@ | ||||||
| <html> | <html> | ||||||
|     <head> |     <head> | ||||||
|         <script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script> |         <script src="/static/htmx_2.0.4.min.js" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+"></script> | ||||||
|     </head> |     </head> | ||||||
|     <body> |     <body> | ||||||
|         <h1>Calathea</h1> |         <h1>Calathea</h1> | ||||||
|         <h2>Plants</h2> |         <h2>Plants</h2> | ||||||
|         <ul id="plants"> |         {% include "plants_ul.html" %} | ||||||
|             {% for plant in plants %} |         <h3>Add new plant</h3> | ||||||
|             <li>{{ plant.name }} ({{ plant.species }})</li> |  | ||||||
|             {% endfor %} |  | ||||||
|         </ul> |  | ||||||
|         <form hx-post="/plants" hx-target="#plants" hx-swap="beforeend"> |         <form hx-post="/plants" hx-target="#plants" hx-swap="beforeend"> | ||||||
|             <label for="name">Name:</label> |             <label for="name">Name:</label> | ||||||
|             <input type="text" id="name" name="name"></br> |             <input type="text" id="name" name="name"></br> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue