| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
mod public; |
| 8 |
mod partials; |
| 9 |
|
| 10 |
pub use public::*; |
| 11 |
|
| 12 |
use askama::Template; |
| 13 |
use axum::{ |
| 14 |
http::StatusCode, |
| 15 |
response::{Html, IntoResponse, Response}, |
| 16 |
}; |
| 17 |
|
| 18 |
|
| 19 |
pub type CsrfTokenOption = Option<String>; |
| 20 |
|
| 21 |
|
| 22 |
fn render_template<T: Template>(template: T) -> Response { |
| 23 |
match template.render() { |
| 24 |
Ok(html) => Html(html).into_response(), |
| 25 |
Err(err) => { |
| 26 |
tracing::error!(error = ?err, "template rendering error"); |
| 27 |
(StatusCode::INTERNAL_SERVER_ERROR, "Template error").into_response() |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
macro_rules! impl_into_response { |
| 34 |
($($T:ty),+ $(,)?) => { |
| 35 |
$( |
| 36 |
impl IntoResponse for $T { |
| 37 |
fn into_response(self) -> Response { |
| 38 |
render_template(self) |
| 39 |
} |
| 40 |
} |
| 41 |
)+ |
| 42 |
}; |
| 43 |
} |
| 44 |
|
| 45 |
impl_into_response!( |
| 46 |
AccountSettingsTemplate, |
| 47 |
AdminCommunityTemplate, |
| 48 |
ForumDirectoryTemplate, |
| 49 |
CommunityTemplate, |
| 50 |
CategoryTemplate, |
| 51 |
ThreadTemplate, |
| 52 |
NewThreadTemplate, |
| 53 |
EditThreadTemplate, |
| 54 |
CommunitySettingsTemplate, |
| 55 |
EditCategoryTemplate, |
| 56 |
MembersTemplate, |
| 57 |
UserProfileTemplate, |
| 58 |
ModerationTemplate, |
| 59 |
ModLogTemplate, |
| 60 |
AdminDashboardTemplate, |
| 61 |
TrackedThreadsTemplate, |
| 62 |
TrackingInfoTemplate, |
| 63 |
SearchResultsFragment, |
| 64 |
Error404Template, |
| 65 |
Error500Template, |
| 66 |
); |
| 67 |
|