Skip to content

Commit

Permalink
tags cloud for gallery partial
Browse files Browse the repository at this point in the history
  • Loading branch information
rilian committed May 12, 2012
1 parent 868bbef commit 5dfe09f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,10 @@
module ApplicationHelper
##
# Returns array of weighted tags, extracted from all Image
#
def get_tags_cloud
tags_cloud = Hash.new(0)
Image.published.map(&:tags).flatten.each { |tag| tags_cloud[tag] += 1 }
tags_cloud.sort {|a, b| rand <=> rand }
end
end
10 changes: 10 additions & 0 deletions app/views/images/_gallery.html.erb
@@ -1,3 +1,13 @@
<ul class="thumbnails">
<% get_tags_cloud.each do |tag, count| %>
<li>
<h<%= [(6-count), 2].max %>>
<%= link_to tag, root_path(:q => {:title_or_desc_or_tags_cache_or_album_title_cont => tag}) %>
</h<%= [(6-count), 2].max %>>
</li>
<% end %>
</ul>

<ul class="thumbnails">
<% images.each do |image| %>
<li class="span2">
Expand Down

0 comments on commit 5dfe09f

Please sign in to comment.