Commit 73f9889fed4ff5ff06e8a1732d6ec6ea77d6fd70

Authored by Aurelio A. Heckert
Committed by Antonio Terceiro
1 parent 22728463

Better tag cloud display

(ActionItem101)
app/helpers/tags_helper.rb
... ... @@ -53,9 +53,14 @@ module TagsHelper
53 53 "top: #{ -(delta/2) - (v * (delta/2)).round }px;"
54 54 destination = url.kind_of?(Hash) ? url_for(url.merge(tagname_option => tag)) : (url.to_s + tag)
55 55  
56   - display_count = options[:show_count] ? "<small><sup>(#{count})</sup></small>" : ""
  56 + if options[:show_count]
  57 + display_count = options[:show_count] ? "<small><sup>(#{count})</sup></small>" : ""
  58 + link_to tag + display_count, destination, :style => style
  59 + else
  60 + link_to tag , destination, :style => style,
  61 + :title => n_( 'one item', '%d items', count ) % count
  62 + end
57 63  
58   - link_to tag + display_count, destination, :style => style
59 64 end.join("\n")
60 65 end
61 66  
... ...
app/models/tags_block.rb
... ... @@ -4,6 +4,8 @@ class TagsBlock &lt; Block
4 4 include BlockHelper
5 5 include ActionController::UrlWriter
6 6  
  7 + settings_items :limit, :type => :integer, :default => 12
  8 +
7 9 def self.description
8 10 _('Block listing content count by tag')
9 11 end
... ... @@ -21,6 +23,12 @@ class TagsBlock &lt; Block
21 23 tags = owner.article_tags
22 24 return '' if tags.empty?
23 25  
  26 + if limit
  27 + tags_tmp = tags.sort_by{ |k,v| -v }[0..(limit-1)]
  28 + tags = {}
  29 + tags_tmp.map{ |k,v| tags[k] = v }
  30 + end
  31 +
24 32 block_title(title) +
25 33 "\n<div class='tag_cloud'>\n"+
26 34 tag_cloud( tags, :id,
... ... @@ -29,6 +37,13 @@ class TagsBlock &lt; Block
29 37 "\n</div><!-- end class='tag_cloud' -->\n";
30 38 end
31 39  
  40 + def footer
  41 + owner_id = owner.identifier
  42 + lambda do
  43 + link_to s_('tags|View all'), :profile => owner_id, :controller => 'profile', :action => 'tags'
  44 + end
  45 + end
  46 +
32 47 def timeout
33 48 15.minutes
34 49 end
... ...
app/views/box_organizer/_tags_block.rhtml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<div id='edit-recent-documents-block'>
  2 + <%= labelled_form_field _('Limit of tags to display:'), text_field(:block, :limit, :size => 3) %>
  3 +</div>
... ...
app/views/profile/tags.rhtml
1 1 <h1><%= _("%s's tags") % @profile.name %></h1>
2 2  
  3 +<div class='tag_cloud'>
3 4 <% cache_timeout(@tags_cache_key, 4.hour.from_now) do %>
4   - <%= tag_cloud(@tags, :id, { :action => :tag}, {:show_count => true} ) %>
  5 + <%= tag_cloud @tags, :id, { :action => :tag}, {:show_count => true} %>
5 6 <% end %>
  7 +</div>
... ...
app/views/search/tags.rhtml
1   -<h2><%= _('Tag cloud') %></h2>
  1 +<h1><%= _('Tag cloud') %></h1>
2 2  
  3 +<div class='tag_cloud'>
3 4 <% cache_timeout(@tags_cache_key, 4.hour.from_now) do %>
4   - <%= tag_cloud(@tags, :tag, :action => 'tag') %>
  5 + <%= tag_cloud @tags, :tag, {:action => 'tag'}, {:show_count => true} %>
5 6 <% end %>
  7 +</div>
... ...