diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 23450bc5c..788e02747 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,2 +1,7 @@ module TagsHelper + def tag_post_count_style(tag) + @highest_post_count ||= Tag.highest_post_count + width_percent = Math.log(tag.post_count, @highest_post_count) * 100 + "background: linear-gradient(to left, #DDD #{width_percent}%, white #{width_percent}%)" + end end diff --git a/app/models/tag.rb b/app/models/tag.rb index b0a89e21f..bc7203f98 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -41,6 +41,12 @@ class Tag < ActiveRecord::Base def counts_for(tag_names) select_all_sql("SELECT name, post_count FROM tags WHERE name IN (?)", tag_names) end + + def highest_post_count + Cache.get("highest-post-count", 4.hours) do + select("post_count").order("post_count DESC").first.post_count + end + end end def real_post_count diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 6c5b83a8e..603f379c1 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -12,7 +12,7 @@
<% @tags.each do |tag| %>