The `use_helpers` method was added in ViewComponent 3.8.0, and it's included by default in all components since version 3.11.0. Note we sometimes delegated the `can?` method to the controller instead of the helpers, for no particularly reason. We're unifying that code as well.
35 lines
787 B
Ruby
35 lines
787 B
Ruby
class Budgets::PhasesComponent < ApplicationComponent
|
|
use_helpers :wysiwyg, :auto_link_already_sanitized_html
|
|
attr_reader :budget
|
|
|
|
def initialize(budget)
|
|
@budget = budget
|
|
end
|
|
|
|
private
|
|
|
|
def phases
|
|
budget.published_phases
|
|
end
|
|
|
|
def start_date(phase)
|
|
time_tag(phase.starts_at.to_date, format: :long) if phase.starts_at.present?
|
|
end
|
|
|
|
def end_date(phase)
|
|
time_tag(phase.ends_at.to_date - 1.day, format: :long) if phase.ends_at.present?
|
|
end
|
|
|
|
def phase_dom_id(phase)
|
|
"phase-#{phases.index(phase) + 1}-#{phase.name.parameterize}"
|
|
end
|
|
|
|
def prev_phase_dom_id(phase)
|
|
phase_dom_id(phases[phases.index(phase) - 1])
|
|
end
|
|
|
|
def next_phase_dom_id(phase)
|
|
phase_dom_id(phases[phases.index(phase) + 1])
|
|
end
|
|
end
|