Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove block passing / layout support from 'trestle/flash/alert' partial #500

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/views/trestle/flash/_alert.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<p><%= alert[:message] %></p>
<% end %>

<%= yield if block_given? %>
<% if local_assigns[:errors] %>
<%= render "trestle/flash/debug", errors: errors %>
<% end %>
</div>
</div>
11 changes: 7 additions & 4 deletions app/views/trestle/flash/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
8 changes: 8 additions & 0 deletions sandbox/app/admin/components/alerts_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>#{html_class}</code> class. This is the <a href="#">Link style</a>.
HTML
end
end
end
8 changes: 8 additions & 0 deletions sandbox/app/admin/components/theme_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>#{html_class}</code> class. This is the <a href="#">Link style</a>.
HTML
end
end
end
81 changes: 58 additions & 23 deletions sandbox/app/views/admin/components/alerts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,77 @@
<p>These alert types are generated internally by Trestle within resourceful admins.</p>
<% 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| %>
<% c.sidebar class: "order-first" do %>
<h2>Custom alerts</h2>
<% end %>

<%= render "trestle/flash/alert", html_class: "alert-primary", icon: icon("alert-icon fas fa-bell"), alert: { title: "Primary" } do %>
<p>This custom alert has the <code>.alert-primary</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-secondary</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-info</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-warning</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-light</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-dark</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
</div>
<% end %>
18 changes: 12 additions & 6 deletions sandbox/app/views/admin/components/theme/_alerts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
<h2 class="m-0">Alerts</h2>
</header>

<%= render "trestle/flash/alert", html_class: "alert-primary", icon: icon("alert-icon fas fa-bell"), alert: { title: "Primary" } do %>
<p>This custom alert has the <code>.alert-primary</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>
<p>This custom alert has the <code>.alert-secondary</code> class. This is the <a href="#">Link style</a>.</p>
<% 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 %>