started howto module to provide basic examples and explore possibilities
This commit is contained in:
parent
e78a06547a
commit
f010ee0f47
9
src/howto/mod.rs
Normal file
9
src/howto/mod.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
pub mod views;
|
||||
|
||||
pub fn routes() -> Router<AppState> {
|
||||
Router::new().route("/", get(views::howtos).post(views::answer_question))
|
||||
}
|
17
src/howto/views.rs
Normal file
17
src/howto/views.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use axum::{extract::State, response::IntoResponse, Form};
|
||||
|
||||
use crate::service::templates;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Question {
|
||||
question: String,
|
||||
}
|
||||
|
||||
pub async fn howtos(templates: State<templates::Templates>) -> impl IntoResponse {
|
||||
templates.render_html("howto/index.html", ())
|
||||
}
|
||||
|
||||
pub async fn answer_question(Form(question): Form<Question>) -> impl IntoResponse {
|
||||
"There is your answer!".to_owned()
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod howto;
|
||||
mod service;
|
||||
mod state;
|
||||
|
||||
@ -26,6 +27,7 @@ async fn main() {
|
||||
let app = Router::new()
|
||||
.route("/", get(home))
|
||||
.route("/hello", get(hello_world))
|
||||
.nest("/howto", howto::routes())
|
||||
.route_service("/static/*file", handlers::static_handler.into_service())
|
||||
.fallback(handlers::not_found_handler)
|
||||
.with_state(state);
|
||||
|
1
static/htmx/htmx.min.js
vendored
Normal file
1
static/htmx/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
36
templates/base.html
Normal file
36
templates/base.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>A Basic HTML5 Template</title>
|
||||
<meta name="description" content="A simple HTML5 Template for new projects.">
|
||||
<meta name="author" content="SitePoint">
|
||||
|
||||
<meta property="og:title" content="A Basic HTML5 Template">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://www.sitepoint.com/a-basic-html5-template/">
|
||||
<meta property="og:description" content="A simple HTML5 Template for new projects.">
|
||||
<meta property="og:image" content="image.png">
|
||||
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
|
||||
<link rel="stylesheet" href="/static/uikit/css/uikit.css?v=1.0">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block top %}
|
||||
{% include "site/top.html" %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<!-- your content here... -->
|
||||
{% endblock %}
|
||||
<script src="/static/uikit/js/uikit.js"></script>
|
||||
<script src="/static/htmx/htmx.min.js"></script>
|
||||
</body>
|
||||
</html>
|
18
templates/howto/index.html
Normal file
18
templates/howto/index.html
Normal file
@ -0,0 +1,18 @@
|
||||
{% extends "index.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Howtos</h1>
|
||||
|
||||
<div>
|
||||
<form hx-post="/howto" hx-trigger="submit" hx-target="#answer">
|
||||
<label for="question">Question:</label>
|
||||
<input type="text" id="question" name="question" required>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
<div class="uk-card uk-card-body" id="answer">
|
||||
<h3 class="uk-card-title"></h3>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,35 +1 @@
|
||||
<!doctype html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>A Basic HTML5 Template</title>
|
||||
<meta name="description" content="A simple HTML5 Template for new projects.">
|
||||
<meta name="author" content="SitePoint">
|
||||
|
||||
<meta property="og:title" content="A Basic HTML5 Template">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://www.sitepoint.com/a-basic-html5-template/">
|
||||
<meta property="og:description" content="A simple HTML5 Template for new projects.">
|
||||
<meta property="og:image" content="image.png">
|
||||
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
|
||||
<link rel="stylesheet" href="/static/uikit/css/uikit.css?v=1.0">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block top %}
|
||||
{% include "site/top.html" %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<!-- your content here... -->
|
||||
{% endblock %}
|
||||
<script src="/static/uikit/js/uikit.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{% extends "base.html" %}
|
||||
|
Loading…
Reference in New Issue
Block a user