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).
22 lines
468 B
Ruby
22 lines
468 B
Ruby
class Budgets::BudgetComponent < ApplicationComponent
|
|
attr_reader :budget
|
|
use_helpers :attached_background_css
|
|
|
|
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
|