Calculate weight of given array. e.g. %w[ruby ruby ruby rails]
Tagcloud.tagcloudize [ "rails", "ruby", "rails" ...] do |count,max|
90 + 110 * ( count / max.to_f)
end
results in:
[{:text=>"rails", :count=>1, :size=>126}, {:text=>"ruby", :count=>3, :size=>200}]
Now, one can use some kind of helper to generate html (not included in this gist, to keep independence), or here directly in haml:
Tagcloud.tagcloudize(array).each do |e|
%span{:style => "font-size: #{e[:size]}%"}
= link_to e[:text], search_path(:q => e[:text])
just to make the point, Stuff like this should be put into a helper or partial.
Improvements:
- Instead of direct size calculation, calculate levels for css classes. More prettier :)