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 @@This custom alert has the .alert-primary
class. This is the Link style.
This custom alert has the .alert-secondary
class. This is the Link style.
This custom alert has the .alert-info
class. This is the Link style.
This custom alert has the .alert-warning
class. This is the Link style.
This custom alert has the .alert-light
class. This is the Link style.
This custom alert has the .alert-dark
class. This is the Link style.
This custom alert has the .alert-primary
class. This is the Link style.
This custom alert has the .alert-secondary
class. This is the Link style.