Extract component to render a goal/target tag
This commit is contained in:
@@ -13,7 +13,7 @@ class SDG::Goals::PlainTagListComponent < ApplicationComponent
|
|||||||
|
|
||||||
def goal_tags
|
def goal_tags
|
||||||
goals.order(:code).limit(limit).map do |goal|
|
goals.order(:code).limit(limit).map do |goal|
|
||||||
render SDG::Goals::IconComponent.new(goal)
|
render SDG::TagComponent.new(goal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SDG::Goals::TagListComponent < ApplicationComponent
|
|||||||
def goal_links
|
def goal_links
|
||||||
goals.order(:code).limit(limit).map do |goal|
|
goals.order(:code).limit(limit).map do |goal|
|
||||||
[
|
[
|
||||||
render(SDG::Goals::IconComponent.new(goal)),
|
render(SDG::TagComponent.new(goal)),
|
||||||
index_by_goal(goal),
|
index_by_goal(goal),
|
||||||
title: filter_text(goal)
|
title: filter_text(goal)
|
||||||
]
|
]
|
||||||
|
|||||||
1
app/components/sdg/tag_component.html.erb
Normal file
1
app/components/sdg/tag_component.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= text -%>
|
||||||
15
app/components/sdg/tag_component.rb
Normal file
15
app/components/sdg/tag_component.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class SDG::TagComponent < ApplicationComponent
|
||||||
|
attr_reader :goal_or_target
|
||||||
|
|
||||||
|
def initialize(goal_or_target)
|
||||||
|
@goal_or_target = goal_or_target
|
||||||
|
end
|
||||||
|
|
||||||
|
def text
|
||||||
|
if goal_or_target.is_a?(SDG::Goal)
|
||||||
|
render SDG::Goals::IconComponent.new(goal_or_target)
|
||||||
|
else
|
||||||
|
"#{SDG::Target.model_name.human} #{goal_or_target.code}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -13,7 +13,7 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent
|
|||||||
|
|
||||||
def target_tags
|
def target_tags
|
||||||
targets.sort[0..(limit.to_i - 1)].map do |target|
|
targets.sort[0..(limit.to_i - 1)].map do |target|
|
||||||
tag.span(text(target), data: { code: target.code })
|
tag.span(render(SDG::TagComponent.new(target)), data: { code: target.code })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,10 +21,6 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent
|
|||||||
record.sdg_targets
|
record.sdg_targets
|
||||||
end
|
end
|
||||||
|
|
||||||
def text(target)
|
|
||||||
"#{SDG::Target.model_name.human} #{target.code}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def i18n_namespace
|
def i18n_namespace
|
||||||
"targets"
|
"targets"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SDG::Targets::TagListComponent < ApplicationComponent
|
|||||||
def target_links
|
def target_links
|
||||||
targets.sort[0..(limit.to_i - 1)].map do |target|
|
targets.sort[0..(limit.to_i - 1)].map do |target|
|
||||||
[
|
[
|
||||||
"#{SDG::Target.model_name.human} #{target.code}",
|
render(SDG::TagComponent.new(target)),
|
||||||
index_by_target(target),
|
index_by_target(target),
|
||||||
title: filter_text(target),
|
title: filter_text(target),
|
||||||
data: { code: target.code }
|
data: { code: target.code }
|
||||||
|
|||||||
Reference in New Issue
Block a user