From d80415590f2c81abf875dac657ae9e83847d0e17 Mon Sep 17 00:00:00 2001 From: Kartikeya Agate Date: Fri, 28 Mar 2025 17:54:01 +0530 Subject: [PATCH] fix examples dont build --- examples/handlers.rs | 22 ----------- examples/hello_world.rs | 86 ++++++++++++++++++++++++++++++++++++++++- examples/views.rs | 57 --------------------------- 3 files changed, 84 insertions(+), 81 deletions(-) delete mode 100644 examples/handlers.rs delete mode 100644 examples/views.rs diff --git a/examples/handlers.rs b/examples/handlers.rs deleted file mode 100644 index a37bd17..0000000 --- a/examples/handlers.rs +++ /dev/null @@ -1,22 +0,0 @@ -use axum::{ - extract::Form, - response::{Html, IntoResponse}, -}; -use serde::Deserialize; -use crate::views::{render_form, render_response}; - -// Define a form data structure using Serde -#[derive(Deserialize)] -pub struct NameForm { - pub name: String, -} - -// Handle GET request to render the form -pub async fn get_form() -> impl IntoResponse { - Html(render_form().into_string()) -} - -// Handle POST request when form is submitted -pub async fn handle_submit(Form(form): Form) -> impl IntoResponse { - Html(render_response(&form.name).into_string()) -} diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 0de9343..d770697 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -4,8 +4,90 @@ use axum::{ }; use std::net::SocketAddr; -mod handlers; -mod views; +mod views { + use maud::{html, Markup}; + + /// Renders the form using Maud + pub fn render_form() -> Markup { + html! { + (maud::DOCTYPE) + html { + head { + meta charset="UTF-8"; + meta name="viewport" content="width=device-width, initial-scale=1.0"; + link rel="stylesheet" href="https://yree.io/mold/assets/css/main.css"; + link rel="icon" href="data:image/svg+xml,🥔"; + link rel="preconnect" href="https://fonts.googleapis.com"; + link rel="preconnect" href="https://fonts.gstatic.com" crossorigin=""; + link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet"; + title { "A mash demo 🥔" } + script src="https://unpkg.com/htmx.org" {} + } + body a="auto" { + main class="content" aria-label="Content" { + div class="w" id="markdown-view" _="on load call MathJax.typeset()" { + h1 { "Mash 🥔" } + p { "A simple demo using the mash stack." } + h2 { "What's your name?" } + form hx-post="/submit" hx-target="#response" { + div class="grid" { + input + type="text" + id="name" + name="name" + placeholder="Enter your name" + required; + button type="submit" { "Submit" } + } + } + br; + div id="response" { + p { "Hello world!" } + } + } + } + } + footer { + div class="w" { + p { a href="https://yree.io/mash" { "mash" } " 🥔 :: a " a href="https://yree.io" { "Yree" } " stack ♥" } + } + } + } + } + } + + /// Renders the response when a form is submitted + pub fn render_response(name: &str) -> Markup { + html! { + p { "Hello, " (name) "!" } + } + } +} + +mod handlers { + use crate::views::{render_form, render_response}; + use axum::{ + extract::Form, + response::{Html, IntoResponse}, + }; + use serde::Deserialize; + + // Define a form data structure using Serde + #[derive(Deserialize)] + pub struct NameForm { + pub name: String, + } + + // Handle GET request to render the form + pub async fn get_form() -> impl IntoResponse { + Html(render_form().into_string()) + } + + // Handle POST request when form is submitted + pub async fn handle_submit(Form(form): Form) -> impl IntoResponse { + Html(render_response(&form.name).into_string()) + } +} #[tokio::main] async fn main() { diff --git a/examples/views.rs b/examples/views.rs deleted file mode 100644 index b57eb4c..0000000 --- a/examples/views.rs +++ /dev/null @@ -1,57 +0,0 @@ -use maud::{html, Markup}; - -/// Renders the form using Maud -pub fn render_form() -> Markup { - html! { - (maud::DOCTYPE) - html { - head { - meta charset="UTF-8"; - meta name="viewport" content="width=device-width, initial-scale=1.0"; - link rel="stylesheet" href="https://yree.io/mold/assets/css/main.css"; - link rel="icon" href="data:image/svg+xml,🥔"; - link rel="preconnect" href="https://fonts.googleapis.com"; - link rel="preconnect" href="https://fonts.gstatic.com" crossorigin=""; - link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet"; - title { "A mash demo 🥔" } - script src="https://unpkg.com/htmx.org" {} - } - body a="auto" { - main class="content" aria-label="Content" { - div class="w" id="markdown-view" _="on load call MathJax.typeset()" { - h1 { "Mash 🥔" } - p { "A simple demo using the mash stack." } - h2 { "What's your name?" } - form hx-post="/submit" hx-target="#response" { - div class="grid" { - input - type="text" - id="name" - name="name" - placeholder="Enter your name" - required; - button type="submit" { "Submit" } - } - } - br; - div id="response" { - p { "Hello world!" } - } - } - } - } - footer { - div class="w" { - p { a href="https://yree.io/mash" { "mash" } " 🥔 :: a " a href="https://yree.io" { "Yree" } " stack ♥" } - } - } - } - } -} - -/// Renders the response when a form is submitted -pub fn render_response(name: &str) -> Markup { - html! { - p { "Hello, " (name) "!" } - } -}