Use maud for test page
I want to replace askama with maud completely. It's so much nicer to be able to use Rust code and abstractions (e.g. functions) to compose HTML than using a bespoke templating system with weird inheritance and stuff. Even though said template system is checked at compile time. Actually, since it doesn't do hot reloading anyways, maud requiring a recompile for changes to become visible doesn't make the situation worse.
This commit is contained in:
parent
36ce75b43d
commit
cf590046e9
7 changed files with 112 additions and 0 deletions
48
Cargo.lock
generated
48
Cargo.lock
generated
|
|
@ -1969,6 +1969,30 @@ version = "0.7.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
|
||||
|
||||
[[package]]
|
||||
name = "maud"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df518b75016b4289cdddffa1b01f2122f4a49802c93191f3133f6dc2472ebcaa"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"http",
|
||||
"itoa",
|
||||
"maud_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maud_macros"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa453238ec218da0af6b11fc5978d3b5c3a45ed97b722391a2a11f3306274e18"
|
||||
dependencies = [
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.62",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.6"
|
||||
|
|
@ -2278,6 +2302,29 @@ version = "0.2.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.82"
|
||||
|
|
@ -3165,6 +3212,7 @@ dependencies = [
|
|||
"gix",
|
||||
"humantime",
|
||||
"log",
|
||||
"maud",
|
||||
"mime_guess",
|
||||
"open",
|
||||
"rand",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ futures = "0.3.30"
|
|||
gethostname = "0.4.3"
|
||||
humantime = "2.1.0"
|
||||
log = "0.4.21"
|
||||
maud = { version = "0.26.0", features = ["axum"] }
|
||||
mime_guess = "2.0.4"
|
||||
open = "5.1.2"
|
||||
rand = "0.8.5"
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ use self::{
|
|||
index::get_index,
|
||||
queue::{get_queue, get_queue_delete, get_queue_inner},
|
||||
run::get_run_by_id,
|
||||
test::get_test,
|
||||
worker::get_worker_by_name,
|
||||
},
|
||||
};
|
||||
|
|
@ -57,6 +58,7 @@ pub async fn run(server: Server) -> somehow::Result<()> {
|
|||
.typed_get(get_queue_delete)
|
||||
.typed_get(get_queue_inner)
|
||||
.typed_get(get_run_by_id)
|
||||
.typed_get(get_test)
|
||||
.typed_get(get_worker_by_name)
|
||||
.typed_post(post_admin_queue_add)
|
||||
.typed_post(post_admin_queue_add_batch)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use std::fmt;
|
||||
|
||||
use maud::{html, Markup, DOCTYPE};
|
||||
|
||||
use crate::config::ServerConfig;
|
||||
|
||||
use super::{
|
||||
|
|
@ -60,6 +62,33 @@ impl Base {
|
|||
pub fn link<P: fmt::Display>(&self, to: P) -> Link {
|
||||
Self::link_with_base(&self.web_base, to)
|
||||
}
|
||||
|
||||
pub fn html(&self, title: &str, head: Markup, body: Markup) -> Markup {
|
||||
html!(
|
||||
(DOCTYPE)
|
||||
html lang="en" {
|
||||
head {
|
||||
meta charset="utf-8";
|
||||
meta name="viewport" content="width=device-width";
|
||||
title { (title) " - " (self.repo_name) }
|
||||
link rel="icon" href=(self.link_logo_svg);
|
||||
link rel="stylesheet" href=(self.link_base_css);
|
||||
(head)
|
||||
}
|
||||
body {
|
||||
nav {
|
||||
a .current[self.tab == "index"] href=(self.link_index) {
|
||||
img src=(self.link_logo_svg) alt="";
|
||||
(self.repo_name)
|
||||
}
|
||||
a .current[self.tab == "graph"] href=(self.link_graph) { "graph" }
|
||||
a .current[self.tab == "queue"] href=(self.link_queue) { "queue" }
|
||||
}
|
||||
(body)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ pub mod graph;
|
|||
pub mod index;
|
||||
pub mod queue;
|
||||
pub mod run;
|
||||
pub mod test;
|
||||
pub mod worker;
|
||||
|
||||
// TODO Admin page with vacuum+analyze, deleting output?
|
||||
|
|
|
|||
27
src/server/web/pages/test.rs
Normal file
27
src/server/web/pages/test.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use axum::{extract::State, response::IntoResponse};
|
||||
use maud::html;
|
||||
|
||||
use crate::{
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::{Base, Tab},
|
||||
paths::PathTest,
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
pub async fn get_test(
|
||||
_path: PathTest,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let base = Base::new(config, Tab::Index);
|
||||
|
||||
Ok(base.html(
|
||||
"test",
|
||||
html! {},
|
||||
html! {
|
||||
h2 { "Test" }
|
||||
p { "Hello world!" }
|
||||
},
|
||||
))
|
||||
}
|
||||
|
|
@ -57,6 +57,10 @@ pub struct PathWorkerByName {
|
|||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/test")]
|
||||
pub struct PathTest {}
|
||||
|
||||
///////////////////
|
||||
// Admin actions //
|
||||
///////////////////
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue