Module: ActsAsTaggableOn::TagsHelper

Defined in:
lib/acts_as_taggable_on/tags_helper.rb

Instance Method Summary collapse

Instance Method Details

#tag_cloud(tags, classes) ⇒ Object

See the wiki for an example using tag_cloud.



4
5
6
7
8
9
10
11
12
13
# File 'lib/acts_as_taggable_on/tags_helper.rb', line 4

def tag_cloud(tags, classes)
  return [] if tags.empty?

  max_count = tags.sort_by(&:count).last.count.to_f

  tags.each do |tag|
    index = ((tag.count / max_count) * (classes.size - 1))
    yield tag, classes[index.nan? ? 0 : index.round]
  end
end