Skip to main content

max / makenotwork

1.7 KB · 65 lines History Blame Raw
1 //! Askama template definitions for all HTML pages and fragments.
2 //!
3 //! Split by domain:
4 //! - `public`: forum directory, project, category, thread pages
5
6 mod public;
7
8 pub use public::*;
9
10 use askama::Template;
11 use axum::response::{Html, IntoResponse, Response};
12
13 /// CSRF token passed to templates; None when no session store is configured.
14 pub type CsrfTokenOption = Option<String>;
15
16 /// Convert any Askama template into an Axum response.
17 fn render_template<T: Template>(template: T) -> Response {
18 match template.render() {
19 Ok(html) => Html(html).into_response(),
20 Err(err) => {
21 tracing::error!(error = ?err, "template rendering error");
22 // Static branded page, not the Error500 *template*: the engine that
23 // just failed can't be trusted to render the fallback.
24 crate::error_page::internal_error_static()
25 }
26 }
27 }
28
29 /// Implement `IntoResponse` for one or more Askama template structs.
30 macro_rules! impl_into_response {
31 ($($T:ty),+ $(,)?) => {
32 $(
33 impl IntoResponse for $T {
34 fn into_response(self) -> Response {
35 render_template(self)
36 }
37 }
38 )+
39 };
40 }
41
42 impl_into_response!(
43 AccountSettingsTemplate,
44 AdminCommunityTemplate,
45 ForumDirectoryTemplate,
46 CommunityTemplate,
47 CategoryTemplate,
48 ThreadTemplate,
49 NewThreadTemplate,
50 EditThreadTemplate,
51 CommunitySettingsTemplate,
52 EditCategoryTemplate,
53 MembersTemplate,
54 UserProfileTemplate,
55 ModerationTemplate,
56 ModLogTemplate,
57 DeletedThreadsTemplate,
58 AdminDashboardTemplate,
59 TrackedThreadsTemplate,
60 TrackingInfoTemplate,
61 SearchResultsFragment,
62 Error404Template,
63 Error500Template,
64 );
65