views: factor out humanized_number helper.
* Render counts in the user profile tooltip the same way as tag counts. * Render tag counts in the tags index page the same way as tag counts in the tags list.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
class TagListComponent < ApplicationComponent
|
class TagListComponent < ApplicationComponent
|
||||||
attr_reader :tags, :current_query, :show_extra_links
|
attr_reader :tags, :current_query, :show_extra_links
|
||||||
|
delegate :humanized_number, to: :helpers
|
||||||
|
|
||||||
def initialize(tags: [], current_query: nil, show_extra_links: false)
|
def initialize(tags: [], current_query: nil, show_extra_links: false)
|
||||||
@tags = tags
|
@tags = tags
|
||||||
@@ -38,14 +39,4 @@ class TagListComponent < ApplicationComponent
|
|||||||
def is_underused_tag?(tag)
|
def is_underused_tag?(tag)
|
||||||
tag.post_count <= 1 && tag.general? && tag.name !~ /_\((cosplay|style)\)\z/
|
tag.post_count <= 1 && tag.general? && tag.name !~ /_\((cosplay|style)\)\z/
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanized_post_count(tag)
|
|
||||||
if tag.post_count >= 10_000
|
|
||||||
"#{tag.post_count / 1_000}k"
|
|
||||||
elsif tag.post_count >= 1_000
|
|
||||||
"%.1fk" % (tag.post_count / 1_000.0)
|
|
||||||
else
|
|
||||||
tag.post_count.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag" %>
|
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag" %>
|
||||||
|
|
||||||
<%= tag.span humanized_post_count(t), class: ["post-count", ("low-post-count" if is_underused_tag?(t))], title: t.post_count %>
|
<%= tag.span humanized_number(t.post_count), class: ["post-count", ("low-post-count" if is_underused_tag?(t))], title: t.post_count %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag" %>
|
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag" %>
|
||||||
<%= tag.span humanized_post_count(t), class: "post-count", title: t.post_count %>
|
<%= tag.span humanized_number(t.post_count), class: "post-count", title: t.post_count %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -122,7 +122,13 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def humanized_number(number)
|
def humanized_number(number)
|
||||||
number_to_human number, units: { thousand: "k", million: "m" }, format: "%n%u"
|
if number >= 10_000
|
||||||
|
"#{number / 1_000}k"
|
||||||
|
elsif number >= 1_000
|
||||||
|
"%.1fk" % (number / 1_000.0)
|
||||||
|
else
|
||||||
|
number.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def time_ago_in_words_tagged(time, compact: false)
|
def time_ago_in_words_tagged(time, compact: false)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
← <%= link_to tag_alias.antecedent_name, tag_alias, class: "fineprint" %>
|
← <%= link_to tag_alias.antecedent_name, tag_alias, class: "fineprint" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= tag.span t.post_count, class: "post-count" %>
|
<%= tag.span humanized_number(t.post_count), class: "post-count", title: t.post_count %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% t.column column: "control" do |tag| %>
|
<% t.column column: "control" do |tag| %>
|
||||||
<% if policy(tag).update? %>
|
<% if policy(tag).update? %>
|
||||||
|
|||||||
Reference in New Issue
Block a user