refactor: Used askama_axum::Template #51

Merged
kosssi merged 1 commits from askama_axum_template into main 2024-08-10 17:51:52 +02:00
6 changed files with 26 additions and 35 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {