refactor: Used askama_axum::Template
docs: https://djc.github.io/askama/integrations.html#axum-integration
This commit is contained in:
parent
69a2d11501
commit
c3f97564d6
@ -3,8 +3,7 @@ mod templates;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
use axum::http::{StatusCode, Uri};
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
@ -14,10 +13,10 @@ async fn fallback(uri: Uri) -> (StatusCode, String) {
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct GetIndexResponse;
|
||||
pub struct GetIndexTemplate;
|
||||
|
||||
async fn root() -> impl IntoResponse {
|
||||
GetIndexResponse {}.into_response()
|
||||
async fn root() -> GetIndexTemplate {
|
||||
GetIndexTemplate {}
|
||||
}
|
||||
|
||||
pub fn get_router(assets_path: &Path) -> axum::Router {
|
||||
|
@ -1,10 +1,9 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "pages/cps.html")]
|
||||
struct CpsResponse;
|
||||
pub struct CpsTemplate;
|
||||
|
||||
pub async fn cps() -> impl IntoResponse {
|
||||
CpsResponse.into_response()
|
||||
pub async fn cps() -> CpsTemplate {
|
||||
CpsTemplate
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "pages/home.html")]
|
||||
struct HomeResponse;
|
||||
pub struct HomeTemplate;
|
||||
|
||||
pub async fn home() -> impl IntoResponse {
|
||||
HomeResponse.into_response()
|
||||
pub async fn home() -> HomeTemplate {
|
||||
HomeTemplate
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
use axum::{routing, Router};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "hello.html")]
|
||||
struct HelloResponse {
|
||||
struct HelloTemplate {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
async fn hello() -> impl IntoResponse {
|
||||
HelloResponse {
|
||||
async fn hello() -> HelloTemplate {
|
||||
HelloTemplate {
|
||||
name: "Theo".to_string(),
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub fn get_routes() -> Router {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
use axum::{extract::Query, routing, Router};
|
||||
use serde::Deserialize;
|
||||
|
||||
@ -16,12 +15,12 @@ struct MenuParameters {
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "layout/nav/nav-menu-items.html")]
|
||||
struct MenuResponse {
|
||||
struct MenuTemplate {
|
||||
mobile: bool,
|
||||
items: Vec<MenuItem>,
|
||||
}
|
||||
|
||||
impl MenuResponse {
|
||||
impl MenuTemplate {
|
||||
fn get_classes(&self, is_current_item: &bool) -> String {
|
||||
let common_classes = match self.mobile {
|
||||
true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(),
|
||||
@ -38,8 +37,8 @@ impl MenuResponse {
|
||||
}
|
||||
}
|
||||
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
MenuResponse {
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> MenuTemplate {
|
||||
MenuTemplate {
|
||||
mobile: params.mobile,
|
||||
items: vec![
|
||||
MenuItem {
|
||||
@ -54,7 +53,6 @@ async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
},
|
||||
],
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub fn get_routes() -> Router {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use askama::Template;
|
||||
use askama_axum::IntoResponse;
|
||||
use askama_axum::Template;
|
||||
use axum::{extract::Query, routing, Router};
|
||||
use serde::Deserialize;
|
||||
|
||||
@ -16,12 +15,12 @@ struct MenuParameters {
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "layout/nav/profile-menu-items.html")]
|
||||
struct MenuResponse {
|
||||
struct MenuTemplate {
|
||||
mobile: bool,
|
||||
items: Vec<MenuItem>,
|
||||
}
|
||||
|
||||
impl MenuResponse {
|
||||
impl MenuTemplate {
|
||||
fn get_classes(&self, is_current_item: &bool) -> String {
|
||||
let common_classes = match self.mobile {
|
||||
true => "block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800".to_string(),
|
||||
@ -36,8 +35,8 @@ impl MenuResponse {
|
||||
}
|
||||
}
|
||||
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
MenuResponse {
|
||||
async fn menu(Query(params): Query<MenuParameters>) -> MenuTemplate {
|
||||
MenuTemplate {
|
||||
mobile: params.mobile,
|
||||
items: vec![
|
||||
MenuItem {
|
||||
@ -57,7 +56,6 @@ async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
||||
},
|
||||
],
|
||||
}
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub fn get_routes() -> Router {
|
||||
|
Loading…
Reference in New Issue
Block a user