Extract component to render poll geozones
This way we remove a bit of duplication. These changes also affect the way geozones are rendered in a couple of minor ways, making them more consistent: * No empty list of geozones is rendered when there are no geozones (before these changes, an empty list was rendered in the index action but not in the show action) * The text clarifying the geozone restriction is always shown (before these changes, it was shown in the index action but not in the show action) We've added tests for these cases.
This commit is contained in:
9
app/components/polls/geozones_component.html.erb
Normal file
9
app/components/polls/geozones_component.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<p>
|
||||
<small><%= t("polls.index.geozone_info") %></small>
|
||||
</p>
|
||||
|
||||
<ul class="tags">
|
||||
<% poll.geozones.each do |geozone| %>
|
||||
<li><span><%= geozone.name %></span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
11
app/components/polls/geozones_component.rb
Normal file
11
app/components/polls/geozones_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Polls::GeozonesComponent < ApplicationComponent
|
||||
attr_reader :poll
|
||||
|
||||
def initialize(poll)
|
||||
@poll = poll
|
||||
end
|
||||
|
||||
def render?
|
||||
poll.geozones.any?
|
||||
end
|
||||
end
|
||||
@@ -40,16 +40,7 @@
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if poll.geozones.any? %>
|
||||
<p>
|
||||
<small><%= t("polls.index.geozone_info") %></small>
|
||||
</p>
|
||||
<% end %>
|
||||
<ul class="tags">
|
||||
<% poll.geozones.each do |g| %>
|
||||
<li><span><%= g.name %></span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= render Polls::GeozonesComponent.new(poll) %>
|
||||
<%= render SDG::TagListComponent.new(poll, limit: 5, linkable: false) %>
|
||||
</div>
|
||||
<div class="small-12 medium-3 column table" data-equalizer-watch>
|
||||
|
||||
@@ -11,13 +11,7 @@
|
||||
|
||||
<%= auto_link_already_sanitized_html simple_format(poll.summary) %>
|
||||
|
||||
<% if poll.geozones.any? %>
|
||||
<ul class="margin-top tags">
|
||||
<% poll.geozones.each do |g| %>
|
||||
<li><span><%= g.name %></span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<%= render Polls::GeozonesComponent.new(poll) %>
|
||||
<%= render SDG::TagListComponent.new(poll, linkable: false) %>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user