Use tag.attributes to set conditional HTML attributes
Using an `if..else` block made the code harder to follow since the opening tag was inside the block but the closing tag was outside it. Moreover, it didn't work well with HTML Beautifier (a gem we're going to introduce to manage ERB indentations).
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
<% if budget.image.present? %>
|
||||
<div class="budget-header with-background-image"
|
||||
style="<%= attached_background_css polymorphic_path(budget.image.variant(:large)) %>">
|
||||
<% else %>
|
||||
<div class="budget-header">
|
||||
<% end %>
|
||||
<div <%= tag.attributes(html_attributes) %>>
|
||||
<div class="row">
|
||||
<div class="small-12 column text-center">
|
||||
<span class="budget-title"><%= t("budgets.index.title") %></span>
|
||||
|
||||
@@ -5,4 +5,17 @@ class Budgets::BudgetComponent < ApplicationComponent
|
||||
def initialize(budget)
|
||||
@budget = budget
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def html_attributes
|
||||
if budget.image.present?
|
||||
{
|
||||
class: "budget-header with-background-image",
|
||||
style: attached_background_css(polymorphic_path(budget.image.variant(:large)))
|
||||
}
|
||||
else
|
||||
{ class: "budget-header" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,14 +58,14 @@
|
||||
<div><span class="panel-title"><%= t("legislation.draft_versions.show.text_body") %></span></div>
|
||||
</div>
|
||||
<div id="sticky-panel" class="draft-text">
|
||||
<% if @draft_version.final_version? %>
|
||||
<section>
|
||||
<% else %>
|
||||
<section class="legislation-annotatable"
|
||||
data-legislation-draft-version-id="<%= @draft_version.id %>"
|
||||
data-legislation-annotatable-base-url="<%= legislation_process_draft_version_path(@process, @draft_version) %>"
|
||||
data-legislation-open-phase="<%= @process.allegations_phase.open? %>">
|
||||
<% end %>
|
||||
<section <%= tag.attributes(
|
||||
class: "legislation-annotatable",
|
||||
data: {
|
||||
"legislation-draft-version-id": @draft_version.id,
|
||||
"legislation-annotatable-base-url": legislation_process_draft_version_path(@process, @draft_version),
|
||||
"legislation-open-phase": @process.allegations_phase.open?
|
||||
}
|
||||
) unless @draft_version.final_version? %>>
|
||||
<%= AdminLegislationSanitizer.new.sanitize(@draft_version.body_html) %>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user