Module: MakeTaggable::TagsHelper
- Defined in:
- lib/make_taggable/tags_helper.rb
Overview
View helpers for rendering tags. Mixed into Action View automatically.
Instance Method Summary collapse
-
#tag_cloud(tags, classes) {|tag, css_class| ... } ⇒ Array
Yields each tag with the CSS class matching how often it is used, for building a tag cloud.
Instance Method Details
#tag_cloud(tags, classes) {|tag, css_class| ... } ⇒ Array
Yields each tag with the CSS class matching how often it is used, for building a tag cloud.
Classes are handed out in the order given, from least to most used, so the first class is the smallest and the last is the largest.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/make_taggable/tags_helper.rb', line 25 def tag_cloud(, classes) return [] if .empty? max_count = .max_by(&:taggings_count).taggings_count.to_f .each do |tag| index = ((tag.taggings_count / max_count) * (classes.size - 1)) yield tag, classes[index.nan? ? 0 : index.round] end end |