From ef7b87cc4d06b92d126ed24fe6a7c8f49ecdd07d Mon Sep 17 00:00:00 2001 From: Nick Gerakines Date: Tue, 8 Jul 2025 18:55:22 -0400 Subject: [PATCH] refactor: Moved to directory structure for localized templates instead of keeping them in file names. Signed-off-by: Nick Gerakines --- src/http/handle_admin_index.rs | 2 +- src/http/handle_create_event.rs | 6 ++--- src/http/handle_settings.rs | 6 ++--- src/http/handle_view_feed.rs | 4 +-- src/http/macros.rs | 15 ++++++----- src/http/templates.rs | 2 +- templates/acknowledgement.en-us.bare.html | 4 --- templates/bare.en-us.html | 3 --- templates/cookie-policy.en-us.bare.html | 4 --- templates/create_event.en-us.bare.html | 4 --- templates/create_rsvp.en-us.bare.html | 4 --- templates/edit_event.en-us.bare.html | 4 --- templates/edit_event.en-us.partial.html | 1 - templates/en-us/acknowledgement.bare.html | 4 +++ .../acknowledgement.common.html} | 0 .../acknowledgement.html} | 4 +-- .../{admin.en-us.html => en-us/admin.html} | 2 +- .../admin_denylist.html} | 2 +- .../admin_event.html} | 2 +- .../admin_events.html} | 2 +- .../admin_handles.html} | 2 +- .../admin_rsvp.html} | 2 +- .../admin_rsvps.html} | 2 +- .../alert.bare.html} | 4 +-- .../{alert.en-us.html => en-us/alert.html} | 4 +-- .../alert.partial.html} | 0 templates/en-us/bare.html | 25 +++++++++++++++++++ .../{base.en-us.html => en-us/base.html} | 4 +-- templates/en-us/cookie-policy.bare.html | 4 +++ .../cookie-policy.common.html} | 0 .../cookie-policy.html} | 4 +-- templates/en-us/create_event.bare.html | 4 +++ .../create_event.common.html} | 2 +- .../create_event.html} | 4 +-- .../create_event.link_form.html} | 0 .../create_event.location_form.html} | 0 .../create_event.partial.html} | 6 ++--- .../create_event.starts_form.html} | 0 templates/en-us/create_rsvp.bare.html | 4 +++ .../create_rsvp.common.html} | 2 +- .../create_rsvp.html} | 4 +-- .../create_rsvp.partial.html} | 0 .../delete_event.html} | 4 +-- .../delete_event.partial.html} | 0 templates/en-us/edit_event.bare.html | 4 +++ .../edit_event.common.html} | 4 +-- .../edit_event.html} | 4 +-- templates/en-us/edit_event.partial.html | 1 + .../event_list.incl.html} | 0 .../{footer.en-us.html => en-us/footer.html} | 0 templates/en-us/import.bare.html | 4 +++ .../import.common.html} | 2 +- .../{import.en-us.html => en-us/import.html} | 4 +-- .../import.partial.html} | 0 templates/en-us/index.bare.html | 4 +++ .../index.common.html} | 0 .../{index.en-us.html => en-us/index.html} | 4 +-- .../login.bare.html} | 4 +-- .../{login.en-us.html => en-us/login.html} | 4 +-- .../login.partial.html} | 0 templates/en-us/migrate_event.bare.html | 1 + .../migrate_event.common.html} | 0 .../migrate_event.html} | 4 +-- templates/{nav.en-us.html => en-us/nav.html} | 0 templates/en-us/privacy-policy.bare.html | 4 +++ .../privacy-policy.common.html} | 0 .../privacy-policy.html} | 4 +-- templates/en-us/profile.bare.html | 4 +++ .../profile.common.html} | 2 +- .../profile.html} | 4 +-- templates/en-us/settings.bare.html | 4 +++ .../settings.common.html} | 6 ++--- .../settings.email.html} | 0 .../settings.html} | 4 +-- .../settings.language.html} | 0 .../settings.tz.html} | 0 templates/en-us/terms-of-service.bare.html | 4 +++ .../terms-of-service.common.html} | 0 .../terms-of-service.html} | 4 +-- templates/en-us/view_event.bare.html | 4 +++ .../view_event.common.html} | 0 .../view_event.html} | 4 +-- templates/en-us/view_rsvp.bare.html | 4 +++ .../view_rsvp.common.html} | 2 +- .../view_rsvp.html} | 4 +-- .../view_rsvp.partial.html} | 0 templates/import.en-us.bare.html | 4 --- templates/index.en-us.bare.html | 4 --- templates/migrate_event.en-us.bare.html | 1 - templates/privacy-policy.en-us.bare.html | 4 --- templates/profile.en-us.bare.html | 4 --- templates/settings.en-us.bare.html | 4 --- templates/terms-of-service.en-us.bare.html | 4 --- templates/view_event.en-us.bare.html | 4 --- templates/view_rsvp.en-us.bare.html | 4 --- 95 files changed, 158 insertions(+), 133 deletions(-) delete mode 100644 templates/acknowledgement.en-us.bare.html delete mode 100644 templates/bare.en-us.html delete mode 100644 templates/cookie-policy.en-us.bare.html delete mode 100644 templates/create_event.en-us.bare.html delete mode 100644 templates/create_rsvp.en-us.bare.html delete mode 100644 templates/edit_event.en-us.bare.html delete mode 100644 templates/edit_event.en-us.partial.html create mode 100644 templates/en-us/acknowledgement.bare.html rename templates/{acknowledgement.en-us.common.html => en-us/acknowledgement.common.html} (100%) rename templates/{acknowledgement.en-us.html => en-us/acknowledgement.html} (60%) rename templates/{admin.en-us.html => en-us/admin.html} (96%) rename templates/{admin_denylist.en-us.html => en-us/admin_denylist.html} (98%) rename templates/{admin_event.en-us.html => en-us/admin_event.html} (96%) rename templates/{admin_events.en-us.html => en-us/admin_events.html} (98%) rename templates/{admin_handles.en-us.html => en-us/admin_handles.html} (98%) rename templates/{admin_rsvp.en-us.html => en-us/admin_rsvp.html} (99%) rename templates/{admin_rsvps.en-us.html => en-us/admin_rsvps.html} (99%) rename templates/{alert.en-us.bare.html => en-us/alert.bare.html} (57%) rename templates/{alert.en-us.html => en-us/alert.html} (69%) rename templates/{alert.en-us.partial.html => en-us/alert.partial.html} (100%) create mode 100644 templates/en-us/bare.html rename templates/{base.en-us.html => en-us/base.html} (92%) create mode 100644 templates/en-us/cookie-policy.bare.html rename templates/{cookie-policy.en-us.common.html => en-us/cookie-policy.common.html} (100%) rename templates/{cookie-policy.en-us.html => en-us/cookie-policy.html} (60%) create mode 100644 templates/en-us/create_event.bare.html rename templates/{create_event.en-us.common.html => en-us/create_event.common.html} (94%) rename templates/{create_event.en-us.html => en-us/create_event.html} (61%) rename templates/{create_event.en-us.link_form.html => en-us/create_event.link_form.html} (100%) rename templates/{create_event.en-us.location_form.html => en-us/create_event.location_form.html} (100%) rename templates/{create_event.en-us.partial.html => en-us/create_event.partial.html} (98%) rename templates/{create_event.en-us.starts_form.html => en-us/create_event.starts_form.html} (100%) create mode 100644 templates/en-us/create_rsvp.bare.html rename templates/{create_rsvp.en-us.common.html => en-us/create_rsvp.common.html} (92%) rename templates/{create_rsvp.en-us.html => en-us/create_rsvp.html} (61%) rename templates/{create_rsvp.en-us.partial.html => en-us/create_rsvp.partial.html} (100%) rename templates/{delete_event.en-us.html => en-us/delete_event.html} (75%) rename templates/{delete_event.en-us.partial.html => en-us/delete_event.partial.html} (100%) create mode 100644 templates/en-us/edit_event.bare.html rename templates/{edit_event.en-us.common.html => en-us/edit_event.common.html} (87%) rename templates/{edit_event.en-us.html => en-us/edit_event.html} (61%) create mode 100644 templates/en-us/edit_event.partial.html rename templates/{event_list.en-us.incl.html => en-us/event_list.incl.html} (100%) rename templates/{footer.en-us.html => en-us/footer.html} (100%) create mode 100644 templates/en-us/import.bare.html rename templates/{import.en-us.common.html => en-us/import.common.html} (79%) rename templates/{import.en-us.html => en-us/import.html} (61%) rename templates/{import.en-us.partial.html => en-us/import.partial.html} (100%) create mode 100644 templates/en-us/index.bare.html rename templates/{index.en-us.common.html => en-us/index.common.html} (100%) rename templates/{index.en-us.html => en-us/index.html} (90%) rename templates/{login.en-us.bare.html => en-us/login.bare.html} (89%) rename templates/{login.en-us.html => en-us/login.html} (90%) rename templates/{login.en-us.partial.html => en-us/login.partial.html} (100%) create mode 100644 templates/en-us/migrate_event.bare.html rename templates/{migrate_event.en-us.common.html => en-us/migrate_event.common.html} (100%) rename templates/{migrate_event.en-us.html => en-us/migrate_event.html} (56%) rename templates/{nav.en-us.html => en-us/nav.html} (100%) create mode 100644 templates/en-us/privacy-policy.bare.html rename templates/{privacy-policy.en-us.common.html => en-us/privacy-policy.common.html} (100%) rename templates/{privacy-policy.en-us.html => en-us/privacy-policy.html} (60%) create mode 100644 templates/en-us/profile.bare.html rename templates/{profile.en-us.common.html => en-us/profile.common.html} (98%) rename templates/{profile.en-us.html => en-us/profile.html} (91%) create mode 100644 templates/en-us/settings.bare.html rename templates/{settings.en-us.common.html => en-us/settings.common.html} (91%) rename templates/{settings.en-us.email.html => en-us/settings.email.html} (100%) rename templates/{settings.en-us.html => en-us/settings.html} (83%) rename templates/{settings.en-us.language.html => en-us/settings.language.html} (100%) rename templates/{settings.en-us.tz.html => en-us/settings.tz.html} (100%) create mode 100644 templates/en-us/terms-of-service.bare.html rename templates/{terms-of-service.en-us.common.html => en-us/terms-of-service.common.html} (100%) rename templates/{terms-of-service.en-us.html => en-us/terms-of-service.html} (60%) create mode 100644 templates/en-us/view_event.bare.html rename templates/{view_event.en-us.common.html => en-us/view_event.common.html} (100%) rename templates/{view_event.en-us.html => en-us/view_event.html} (91%) create mode 100644 templates/en-us/view_rsvp.bare.html rename templates/{view_rsvp.en-us.common.html => en-us/view_rsvp.common.html} (96%) rename templates/{view_rsvp.en-us.html => en-us/view_rsvp.html} (73%) rename templates/{view_rsvp.en-us.partial.html => en-us/view_rsvp.partial.html} (100%) delete mode 100644 templates/import.en-us.bare.html delete mode 100644 templates/index.en-us.bare.html delete mode 100644 templates/migrate_event.en-us.bare.html delete mode 100644 templates/privacy-policy.en-us.bare.html delete mode 100644 templates/profile.en-us.bare.html delete mode 100644 templates/settings.en-us.bare.html delete mode 100644 templates/terms-of-service.en-us.bare.html delete mode 100644 templates/view_event.en-us.bare.html delete mode 100644 templates/view_rsvp.en-us.bare.html diff --git a/src/http/handle_admin_index.rs b/src/http/handle_admin_index.rs index ef901eb..aa07cd5 100644 --- a/src/http/handle_admin_index.rs +++ b/src/http/handle_admin_index.rs @@ -17,7 +17,7 @@ pub(crate) async fn handle_admin_index( ); Ok(RenderHtml( - "admin.en-us.html", + "en-us/admin.html", admin_ctx.web_context.engine.clone(), template_context! { ..admin_template_context(&admin_ctx, &canonical_url), diff --git a/src/http/handle_create_event.rs b/src/http/handle_create_event.rs index e4074d3..19cb408 100644 --- a/src/http/handle_create_event.rs +++ b/src/http/handle_create_event.rs @@ -392,7 +392,7 @@ pub(crate) async fn handle_starts_at_builder( let is_development = cfg!(debug_assertions); let render_template = format!( - "create_event.{}.starts_form.html", + "{}/create_event.starts_form.html", language.to_string().to_lowercase() ); @@ -480,7 +480,7 @@ pub(crate) async fn handle_location_at_builder( let is_development = cfg!(debug_assertions); let render_template = format!( - "create_event.{}.location_form.html", + "{}/create_event.location_form.html", language.to_string().to_lowercase() ); @@ -554,7 +554,7 @@ pub(crate) async fn handle_link_at_builder( let is_development = cfg!(debug_assertions); let render_template = format!( - "create_event.{}.link_form.html", + "{}/create_event.link_form.html", language.to_string().to_lowercase() ); diff --git a/src/http/handle_settings.rs b/src/http/handle_settings.rs index 15683f8..c8632bb 100644 --- a/src/http/handle_settings.rs +++ b/src/http/handle_settings.rs @@ -95,7 +95,7 @@ pub(crate) async fn handle_timezone_update( }; let error_template = select_template!(false, true, language); - let render_template = format!("settings.{}.tz.html", language.to_string().to_lowercase()); + let render_template = format!("{}/settings.tz.html", language.to_string().to_lowercase()); let (_, timezones) = supported_timezones(Some(¤t_handle)); @@ -161,7 +161,7 @@ pub(crate) async fn handle_language_update( let error_template = select_template!(false, true, language); let render_template = format!( - "settings.{}.language.html", + "{}/settings.language.html", language.to_string().to_lowercase() ); @@ -254,7 +254,7 @@ pub(crate) async fn handle_email_update( let error_template = select_template!(false, true, language); let render_template = format!( - "settings.{}.email.html", + "{}/settings.email.html", language.to_string().to_lowercase() ); diff --git a/src/http/handle_view_feed.rs b/src/http/handle_view_feed.rs index db4e4a9..5ea187b 100644 --- a/src/http/handle_view_feed.rs +++ b/src/http/handle_view_feed.rs @@ -16,9 +16,9 @@ pub(crate) async fn handle_view_feed( Cached(auth): Cached, ) -> Result { let render_template = if hx_boosted { - format!("index.{}.bare.html", language.to_string().to_lowercase()) + format!("{}/index.bare.html", language.to_string().to_lowercase()) } else { - format!("index.{}.html", language.to_string().to_lowercase()) + format!("{}/index.html", language.to_string().to_lowercase()) }; Ok(RenderHtml( diff --git a/src/http/macros.rs b/src/http/macros.rs index 8aa62ad..c9f3b60 100644 --- a/src/http/macros.rs +++ b/src/http/macros.rs @@ -6,18 +6,21 @@ macro_rules! select_template { ($template_name:expr, $hxboosted:expr, $hxrequest:expr, $language:expr) => {{ if $hxboosted { format!( - concat!($template_name, ".{}.bare.html"), - $language.to_string().to_lowercase() + "{}/{}.bare.html", + $language.to_string().to_lowercase(), + $template_name ) } else if $hxrequest { format!( - concat!($template_name, ".{}.partial.html"), - $language.to_string().to_lowercase() + "{}/{}.partial.html", + $language.to_string().to_lowercase(), + $template_name ) } else { format!( - concat!($template_name, ".{}.html"), - $language.to_string().to_lowercase() + "{}/{}.html", + $language.to_string().to_lowercase(), + $template_name ) } }}; diff --git a/src/http/templates.rs b/src/http/templates.rs index 5be32b0..30fbd21 100644 --- a/src/http/templates.rs +++ b/src/http/templates.rs @@ -9,7 +9,7 @@ pub(crate) fn render_alert>( default_context: minijinja::Value, ) -> impl IntoResponse { RenderHtml( - format!("prompt.{}.html", language), + format!("{}/prompt.html", language), engine, template_context! { ..default_context, ..template_context! { message => message.into(), diff --git a/templates/acknowledgement.en-us.bare.html b/templates/acknowledgement.en-us.bare.html deleted file mode 100644 index 6b94b91..0000000 --- a/templates/acknowledgement.en-us.bare.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "bare.en-us.html" %} -{% block content %} -{% include 'acknowledgement.en-us.common.html' %} -{% endblock %} \ No newline at end of file diff --git a/templates/bare.en-us.html b/templates/bare.en-us.html deleted file mode 100644 index ca1e96b..0000000 --- a/templates/bare.en-us.html +++ /dev/null @@ -1,3 +0,0 @@ -{% include 'nav.en-us.html' %} -{% block content %}{% endblock %} -{% include 'footer.en-us.html' %} \ No newline at end of file diff --git a/templates/cookie-policy.en-us.bare.html b/templates/cookie-policy.en-us.bare.html deleted file mode 100644 index 27915d8..0000000 --- a/templates/cookie-policy.en-us.bare.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "bare.en-us.html" %} -{% block content %} -{% include 'cookie-policy.en-us.common.html' %} -{% endblock %} \ No newline at end of file diff --git a/templates/create_event.en-us.bare.html b/templates/create_event.en-us.bare.html deleted file mode 100644 index f1080b6..0000000 --- a/templates/create_event.en-us.bare.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "bare.en-us.html" %} -{% block content %} -{% include 'create_event.en-us.common.html' %} -{% endblock %} \ No newline at end of file diff --git a/templates/create_rsvp.en-us.bare.html b/templates/create_rsvp.en-us.bare.html deleted file mode 100644 index 03d051c..0000000 --- a/templates/create_rsvp.en-us.bare.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "bare.en-us.html" %} -{% block content %} -{% include 'create_rsvp.en-us.common.html' %} -{% endblock %} \ No newline at end of file diff --git a/templates/edit_event.en-us.bare.html b/templates/edit_event.en-us.bare.html deleted file mode 100644 index 3c9cfe3..0000000 --- a/templates/edit_event.en-us.bare.html +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "bare.en-us.html" %} -{% block content %} -{% include 'edit_event.en-us.common.html' %} -{% endblock %} \ No newline at end of file diff --git a/templates/edit_event.en-us.partial.html b/templates/edit_event.en-us.partial.html deleted file mode 100644 index 786a70f..0000000 --- a/templates/edit_event.en-us.partial.html +++ /dev/null @@ -1 +0,0 @@ -{% include 'create_event.en-us.partial.html' %} \ No newline at end of file diff --git a/templates/en-us/acknowledgement.bare.html b/templates/en-us/acknowledgement.bare.html new file mode 100644 index 0000000..9531072 --- /dev/null +++ b/templates/en-us/acknowledgement.bare.html @@ -0,0 +1,4 @@ +{% extends "en-us/bare.html" %} +{% block content %} +{% include 'en-us/acknowledgement.common.html' %} +{% endblock %} \ No newline at end of file diff --git a/templates/acknowledgement.en-us.common.html b/templates/en-us/acknowledgement.common.html similarity index 100% rename from templates/acknowledgement.en-us.common.html rename to templates/en-us/acknowledgement.common.html diff --git a/templates/acknowledgement.en-us.html b/templates/en-us/acknowledgement.html similarity index 60% rename from templates/acknowledgement.en-us.html rename to templates/en-us/acknowledgement.html index e6b7b99..76dc1c9 100644 --- a/templates/acknowledgement.en-us.html +++ b/templates/en-us/acknowledgement.html @@ -1,6 +1,6 @@ -{% extends "base.en-us.html" %} +{% extends "en-us/base.html" %} {% block title %}Acknowledgement - Smoke Signal{% endblock %} {% block head %}{% endblock %} {% block content %} -{% include 'acknowledgement.en-us.common.html' %} +{% include 'en-us/acknowledgement.common.html' %} {% endblock %} \ No newline at end of file diff --git a/templates/admin.en-us.html b/templates/en-us/admin.html similarity index 96% rename from templates/admin.en-us.html rename to templates/en-us/admin.html index bd96357..461c4cd 100644 --- a/templates/admin.en-us.html +++ b/templates/en-us/admin.html @@ -1,4 +1,4 @@ -{% extends "base.en-us.html" %} +{% extends "en-us/base.html" %} {% block title %}Smoke Signal Admin{% endblock %} {% block head %}{% endblock %} {% block content %} diff --git a/templates/admin_denylist.en-us.html b/templates/en-us/admin_denylist.html similarity index 98% rename from templates/admin_denylist.en-us.html rename to templates/en-us/admin_denylist.html index fc8ecf0..2f66081 100644 --- a/templates/admin_denylist.en-us.html +++ b/templates/en-us/admin_denylist.html @@ -1,4 +1,4 @@ -{% extends "base.en-us.html" %} +{% extends "en-us/base.html" %} {% include 'pagination.html' %} {% block title %}Manage Denylist - Smoke Signal Admin{% endblock %} {% block head %}{% endblock %} diff --git a/templates/admin_event.en-us.html b/templates/en-us/admin_event.html similarity index 96% rename from templates/admin_event.en-us.html rename to templates/en-us/admin_event.html index c784fa1..ef24328 100644 --- a/templates/admin_event.en-us.html +++ b/templates/en-us/admin_event.html @@ -1,4 +1,4 @@ -{% extends "base.en-us.html" %} +{% extends "en-us/base.html" %} {% block title %}Event Record - Smoke Signal Admin{% endblock %} {% block head %}