Commit 73f9889fed4ff5ff06e8a1732d6ec6ea77d6fd70
Committed by
Antonio Terceiro
1 parent
22728463
Exists in
master
and in
29 other branches
Better tag cloud display
(ActionItem101)
Showing
5 changed files
with
32 additions
and
5 deletions
Show diff stats
app/helpers/tags_helper.rb
@@ -53,9 +53,14 @@ module TagsHelper | @@ -53,9 +53,14 @@ module TagsHelper | ||
53 | "top: #{ -(delta/2) - (v * (delta/2)).round }px;" | 53 | "top: #{ -(delta/2) - (v * (delta/2)).round }px;" |
54 | destination = url.kind_of?(Hash) ? url_for(url.merge(tagname_option => tag)) : (url.to_s + tag) | 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 | end.join("\n") | 64 | end.join("\n") |
60 | end | 65 | end |
61 | 66 |
app/models/tags_block.rb
@@ -4,6 +4,8 @@ class TagsBlock < Block | @@ -4,6 +4,8 @@ class TagsBlock < Block | ||
4 | include BlockHelper | 4 | include BlockHelper |
5 | include ActionController::UrlWriter | 5 | include ActionController::UrlWriter |
6 | 6 | ||
7 | + settings_items :limit, :type => :integer, :default => 12 | ||
8 | + | ||
7 | def self.description | 9 | def self.description |
8 | _('Block listing content count by tag') | 10 | _('Block listing content count by tag') |
9 | end | 11 | end |
@@ -21,6 +23,12 @@ class TagsBlock < Block | @@ -21,6 +23,12 @@ class TagsBlock < Block | ||
21 | tags = owner.article_tags | 23 | tags = owner.article_tags |
22 | return '' if tags.empty? | 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 | block_title(title) + | 32 | block_title(title) + |
25 | "\n<div class='tag_cloud'>\n"+ | 33 | "\n<div class='tag_cloud'>\n"+ |
26 | tag_cloud( tags, :id, | 34 | tag_cloud( tags, :id, |
@@ -29,6 +37,13 @@ class TagsBlock < Block | @@ -29,6 +37,13 @@ class TagsBlock < Block | ||
29 | "\n</div><!-- end class='tag_cloud' -->\n"; | 37 | "\n</div><!-- end class='tag_cloud' -->\n"; |
30 | end | 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 | def timeout | 47 | def timeout |
33 | 15.minutes | 48 | 15.minutes |
34 | end | 49 | end |
app/views/profile/tags.rhtml
1 | <h1><%= _("%s's tags") % @profile.name %></h1> | 1 | <h1><%= _("%s's tags") % @profile.name %></h1> |
2 | 2 | ||
3 | +<div class='tag_cloud'> | ||
3 | <% cache_timeout(@tags_cache_key, 4.hour.from_now) do %> | 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 | <% end %> | 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 | <% cache_timeout(@tags_cache_key, 4.hour.from_now) do %> | 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 | <% end %> | 6 | <% end %> |
7 | +</div> |