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.
29 lines
521 B
Ruby
29 lines
521 B
Ruby
class SDG::Goals::IndexComponent < ApplicationComponent
|
|
attr_reader :goals, :header, :phases
|
|
use_helpers :link_list
|
|
|
|
def initialize(goals, header:, phases:)
|
|
@goals = goals
|
|
@header = header
|
|
@phases = phases
|
|
end
|
|
|
|
private
|
|
|
|
def title
|
|
t("sdg.goals.title")
|
|
end
|
|
|
|
def goal_links
|
|
goals.map { |goal| goal_link(goal) }
|
|
end
|
|
|
|
def goal_link(goal)
|
|
[icon(goal), sdg_goal_path(goal.code)]
|
|
end
|
|
|
|
def icon(goal)
|
|
render SDG::Goals::IconComponent.new(goal)
|
|
end
|
|
end
|