From 7146fc3dc01ff7d0c20d57e5416a9f29a7e6c5cf Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Mon, 23 Sep 2024 20:19:06 +0930 Subject: [PATCH] Remove block passing / layout support from 'trestle/flash/alert' partial --- app/views/trestle/flash/_alert.html.erb | 4 +- app/views/trestle/flash/_flash.html.erb | 11 ++- sandbox/app/admin/components/alerts_admin.rb | 8 ++ sandbox/app/admin/components/theme_admin.rb | 8 ++ .../admin/components/alerts/index.html.erb | 81 +++++++++++++------ .../admin/components/theme/_alerts.html.erb | 18 +++-- 6 files changed, 96 insertions(+), 34 deletions(-) diff --git a/app/views/trestle/flash/_alert.html.erb b/app/views/trestle/flash/_alert.html.erb index 2f7018e7..5b663dd1 100644 --- a/app/views/trestle/flash/_alert.html.erb +++ b/app/views/trestle/flash/_alert.html.erb @@ -12,6 +12,8 @@

<%= alert[:message] %>

<% end %> - <%= yield if block_given? %> + <% if local_assigns[:errors] %> + <%= render "trestle/flash/debug", errors: errors %> + <% end %> diff --git a/app/views/trestle/flash/_flash.html.erb b/app/views/trestle/flash/_flash.html.erb index f2cff82e..755c4574 100644 --- a/app/views/trestle/flash/_flash.html.erb +++ b/app/views/trestle/flash/_flash.html.erb @@ -1,7 +1,10 @@ <% if flash[:message] -%> - <%= render "trestle/flash/alert", html_class: "alert-success", icon: icon("alert-icon far fa-check-circle"), alert: normalize_flash_alert(flash[:message]) %> + <%= render "trestle/flash/alert", html_class: "alert-success", + icon: icon("alert-icon far fa-check-circle"), + alert: normalize_flash_alert(flash[:message]) %> <% elsif flash[:error] -%> - <%= render layout: "trestle/flash/alert", locals: { html_class: "alert-danger", icon: icon("alert-icon far fa-times-circle"), alert: normalize_flash_alert(flash[:error]) } do %> - <%= render "trestle/flash/debug", errors: Trestle::DebugErrors.new(instance.errors) if debug_form_errors? %> - <% end %> + <%= render "trestle/flash/alert", html_class: "alert-danger", + icon: icon("alert-icon far fa-times-circle"), + alert: normalize_flash_alert(flash[:error]), + errors: (Trestle::DebugErrors.new(instance.errors) if debug_form_errors?) %> <% end -%> diff --git a/sandbox/app/admin/components/alerts_admin.rb b/sandbox/app/admin/components/alerts_admin.rb index 82e3cb5f..e4c619f2 100644 --- a/sandbox/app/admin/components/alerts_admin.rb +++ b/sandbox/app/admin/components/alerts_admin.rb @@ -4,4 +4,12 @@ item :alerts, icon: "fas fa-exclamation-circle", priority: 1 end end + + helper do + def alert_message(html_class) + <<-HTML.html_safe + This custom alert has the #{html_class} class. This is the Link style. + HTML + end + end end diff --git a/sandbox/app/admin/components/theme_admin.rb b/sandbox/app/admin/components/theme_admin.rb index b57557dc..76088cd6 100644 --- a/sandbox/app/admin/components/theme_admin.rb +++ b/sandbox/app/admin/components/theme_admin.rb @@ -4,4 +4,12 @@ item :theme, icon: "fas fa-palette", priority: 8 end end + + helper do + def alert_message(html_class) + <<-HTML.html_safe + This custom alert has the #{html_class} class. This is the Link style. + HTML + end + end end diff --git a/sandbox/app/views/admin/components/alerts/index.html.erb b/sandbox/app/views/admin/components/alerts/index.html.erb index bfe84187..9d8728a6 100644 --- a/sandbox/app/views/admin/components/alerts/index.html.erb +++ b/sandbox/app/views/admin/components/alerts/index.html.erb @@ -8,12 +8,29 @@

These alert types are generated internally by Trestle within resourceful admins.

<% end %> - <%= render "trestle/flash/alert", html_class: "alert-success", icon: icon("alert-icon far fa-check-circle"), alert: { title: admin.t("flash.create.success.title"), message: admin.t("flash.create.success.message", lowercase_model_name: "resource") } %> - <%= render "trestle/flash/alert", html_class: "alert-danger", icon: icon("alert-icon far fa-times-circle"), alert: { title: admin.t("flash.create.failure.title"), message: admin.t("flash.create.failure.message", lowercase_model_name: "resource") } %> + <%= render "trestle/flash/alert", html_class: "alert-success", + icon: icon("alert-icon far fa-check-circle"), + alert: { + title: admin.t("flash.create.success.title"), + message: admin.t("flash.create.success.message", + lowercase_model_name: "resource") + } %> - <%= render layout: "trestle/flash/alert", locals: { html_class: "alert-danger", icon: icon("alert-icon far fa-times-circle"), alert: { title: admin.t("flash.create.failure.title"), message: admin.t("flash.create.failure.message", lowercase_model_name: "resource") } } do %> - <%= render "trestle/flash/debug", errors: { field: "is required", another: "is already taken" } %> - <% end %> + <%= render "trestle/flash/alert", html_class: "alert-danger", + icon: icon("alert-icon far fa-times-circle"), + alert: { + title: admin.t("flash.create.failure.title"), + message: admin.t("flash.create.failure.message", + lowercase_model_name: "resource") + } %> + + <%= render "trestle/flash/alert", html_class: "alert-danger", + icon: icon("alert-icon far fa-times-circle"), + alert: { + title: admin.t("flash.create.failure.title"), + message: admin.t("flash.create.failure.message", lowercase_model_name: "resource") + }, + errors: { field: "is required", another: "is already taken" } %> <% end %> <%= container do |c| %> @@ -21,29 +38,47 @@

Custom alerts

<% end %> - <%= render "trestle/flash/alert", html_class: "alert-primary", icon: icon("alert-icon fas fa-bell"), alert: { title: "Primary" } do %> -

This custom alert has the .alert-primary class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-primary", + icon: icon("alert-icon fas fa-bell"), + alert: { + title: "Primary", + message: alert_message(".alert-primary") + } %> - <%= render "trestle/flash/alert", html_class: "alert-secondary", icon: icon("alert-icon fas fa-download"), alert: { title: "Secondary" } do %> -

This custom alert has the .alert-secondary class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-secondary", + icon: icon("alert-icon fas fa-download"), + alert: { + title: "Secondary", + message: alert_message(".alert-secondary") + } %> - <%= render "trestle/flash/alert", html_class: "alert-info", icon: icon("alert-icon fas fa-exclamation"), alert: { title: "Info" } do %> -

This custom alert has the .alert-info class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-info", + icon: icon("alert-icon fas fa-exclamation"), + alert: { + title: "Info", + message: alert_message(".alert-info") + } %> - <%= render "trestle/flash/alert", html_class: "alert-warning", icon: icon("alert-icon fas fa-radiation-alt"), alert: { title: "Warning" } do %> -

This custom alert has the .alert-warning class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-warning", + icon: icon("alert-icon fas fa-radiation-alt"), + alert: { + title: "Warning", + message: alert_message(".alert-warning") + } %> - <%= render "trestle/flash/alert", html_class: "alert-light", icon: icon("alert-icon far fa-sun"), alert: { title: "Light" } do %> -

This custom alert has the .alert-light class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-light", + icon: icon("alert-icon fas fa-sun"), + alert: { + title: "Light", + message: alert_message(".alert-light") + } %> - <%= render "trestle/flash/alert", html_class: "alert-dark", icon: icon("alert-icon far fa-moon"), alert: { title: "Dark" } do %> -

This custom alert has the .alert-dark class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-dark", + icon: icon("alert-icon far fa-moon"), + alert: { + title: "Dark", + message: alert_message(".alert-dark") + } %> <% end %> <% end %> diff --git a/sandbox/app/views/admin/components/theme/_alerts.html.erb b/sandbox/app/views/admin/components/theme/_alerts.html.erb index e16300a8..678bf662 100644 --- a/sandbox/app/views/admin/components/theme/_alerts.html.erb +++ b/sandbox/app/views/admin/components/theme/_alerts.html.erb @@ -3,11 +3,17 @@

Alerts

- <%= render "trestle/flash/alert", html_class: "alert-primary", icon: icon("alert-icon fas fa-bell"), alert: { title: "Primary" } do %> -

This custom alert has the .alert-primary class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-primary", + icon: icon("alert-icon fas fa-bell"), + alert: { + title: "Primary", + message: alert_message(".alert-primary") + } %> - <%= render "trestle/flash/alert", html_class: "alert-secondary", icon: icon("alert-icon fas fa-download"), alert: { title: "Secondary" } do %> -

This custom alert has the .alert-secondary class. This is the Link style.

- <% end %> + <%= render "trestle/flash/alert", html_class: "alert-secondary", + icon: icon("alert-icon fas fa-download"), + alert: { + title: "Secondary", + message: alert_message(".alert-secondary") + } %> <% end %>