Limiting max number of tags shown on debate cards ~ issue#144
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
|
||||||
def tags(debate)
|
def tags(debate, limit = nil)
|
||||||
debate.tag_list.sort.map { |tag| link_to sanitize(tag), debates_path(tag: tag) }.join('').html_safe
|
tag_names = debate.tag_list_with_limit(limit)
|
||||||
|
|
||||||
|
tag_names.sort.map do |tag|
|
||||||
|
link_to sanitize(tag), debates_path(tag: tag)
|
||||||
|
end.join('').html_safe.tap do |output|
|
||||||
|
if limit && extra_tags = debate.tags_count_out_of_limit(limit)
|
||||||
|
output.concat(link_to("#{extra_tags}+", debate_path(debate)))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def percentage(vote, debate)
|
def percentage(vote, debate)
|
||||||
|
|||||||
@@ -42,6 +42,15 @@ class Debate < ActiveRecord::Base
|
|||||||
super.try :html_safe
|
super.try :html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_list_with_limit(limit = nil)
|
||||||
|
tags.most_used(limit).pluck :name
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags_count_out_of_limit(limit = nil)
|
||||||
|
count = tags.count - limit
|
||||||
|
count < 0 ? 0 : count
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def sanitize_description
|
def sanitize_description
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<%= link_to debate.description, debate %>
|
<%= link_to debate.description, debate %>
|
||||||
<div class="truncate"></div>
|
<div class="truncate"></div>
|
||||||
</div>
|
</div>
|
||||||
<%= render "shared/tags", debate: debate %>
|
<%= render "shared/tags", debate: debate, limit: 5 %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
<%- limit ||= nil %>
|
||||||
|
|
||||||
<% if debate.tags.any? %>
|
<% if debate.tags.any? %>
|
||||||
<span class='tags'><%= tags(debate) %></span>
|
<span class='tags'><%= tags(debate, limit) %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<%= link_to featured_debate.description, featured_debate %>
|
<%= link_to featured_debate.description, featured_debate %>
|
||||||
<div class="truncate"></div>
|
<div class="truncate"></div>
|
||||||
</div>
|
</div>
|
||||||
<%= render "shared/tags", debate: featured_debate %>
|
<%= render "shared/tags", debate: featured_debate, limit: 5 %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
Reference in New Issue
Block a user