move axum_ructe to lib

This commit is contained in:
Zynh0722 2023-11-05 11:38:50 -08:00
parent bfb697e3b9
commit c15046ae30
5 changed files with 14 additions and 13 deletions

View file

@ -18,8 +18,8 @@ use futures_util::Stream;
use serde::Deserialize; use serde::Deserialize;
use tokio_stream::{wrappers::errors::BroadcastStreamRecvError, StreamExt as _}; use tokio_stream::{wrappers::errors::BroadcastStreamRecvError, StreamExt as _};
use crate::axum_ructe::render;
use crate::AppState; use crate::AppState;
use cm_lib::render;
pub(crate) fn router() -> axum::Router<AppState> { pub(crate) fn router() -> axum::Router<AppState> {
axum::Router::new() axum::Router::new()

View file

@ -3,6 +3,7 @@ use axum::{
response::{Html, IntoResponse}, response::{Html, IntoResponse},
}; };
#[macro_export]
macro_rules! render { macro_rules! render {
($template:path) => {{ ($template:path) => {{
use $crate::axum_ructe::Render; use $crate::axum_ructe::Render;
@ -14,8 +15,6 @@ macro_rules! render {
}} }}
} }
pub(crate) use render;
pub struct Render<T: FnOnce(&mut Vec<u8>) -> std::io::Result<()>>(pub T); pub struct Render<T: FnOnce(&mut Vec<u8>) -> std::io::Result<()>>(pub T);
impl<T: FnOnce(&mut Vec<u8>) -> std::io::Result<()>> IntoResponse for Render<T> { impl<T: FnOnce(&mut Vec<u8>) -> std::io::Result<()>> IntoResponse for Render<T> {

View file

@ -1,4 +1,5 @@
pub mod models; pub mod axum_ructe;
pub mod schema;
pub mod report;
pub mod hx_request; pub mod hx_request;
pub mod models;
pub mod report;
pub mod schema;

View file

@ -1,14 +1,14 @@
mod api; mod api;
mod axum_ructe;
mod sse_handler;
mod management; mod management;
mod sse_handler;
use axum_ructe::render; use cm_lib::render;
use cm_lib::{ use cm_lib::{
hx_request::HxRequest,
models::{Drink, Shift}, models::{Drink, Shift},
report::GenerateDrinkReport, report::GenerateDrinkReport,
schema::shifts, hx_request::HxRequest, schema::shifts,
}; };
use axum::{ use axum::{

View file

@ -1,6 +1,8 @@
use axum::{routing::get, response::IntoResponse}; use axum::{response::IntoResponse, routing::get};
use crate::{AppState, axum_ructe::render}; use crate::AppState;
use cm_lib::render;
pub(crate) fn router() -> axum::Router<AppState> { pub(crate) fn router() -> axum::Router<AppState> {
axum::Router::new() axum::Router::new()
@ -12,7 +14,6 @@ async fn home() -> impl IntoResponse {
render!(crate::templates::management_html) render!(crate::templates::management_html)
} }
async fn dancers() -> impl IntoResponse { async fn dancers() -> impl IntoResponse {
render!(crate::templates::dancers_html) render!(crate::templates::dancers_html)
} }