Commit 45f1288a6a729ade3a800cc5f197d31d48115b1a
Committed by
Antonio Terceiro
1 parent
64dd2e0f
Exists in
master
and in
22 other branches
Order tags alphabetically. Closes ActionItem1325
Showing
5 changed files
with
29 additions
and
4 deletions
Show diff stats
app/helpers/tags_helper.rb
@@ -28,13 +28,14 @@ module TagsHelper | @@ -28,13 +28,14 @@ module TagsHelper | ||
28 | # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem | 28 | # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem |
29 | # (pt_BR only). | 29 | # (pt_BR only). |
30 | def tag_cloud(tags, tagname_option, url, options = {}) | 30 | def tag_cloud(tags, tagname_option, url, options = {}) |
31 | - | ||
32 | 31 | ||
33 | return content_tag('em', _('No tags yet.')) + | 32 | return content_tag('em', _('No tags yet.')) + |
34 | ' <a href="' + _('http://en.wikipedia.org/wiki/Tag_%28metadata%29') + | 33 | ' <a href="' + _('http://en.wikipedia.org/wiki/Tag_%28metadata%29') + |
35 | '" target="wptags"><span>(' + | 34 | '" target="wptags"><span>(' + |
36 | _('What are tags?') + ')</span></a>' if tags.empty? | 35 | _('What are tags?') + ')</span></a>' if tags.empty? |
37 | 36 | ||
37 | + tags = tags.sort_by{ |k,v| k.downcase } | ||
38 | + | ||
38 | max_size = options[:max_size] || Cloud::MAX_SIZE | 39 | max_size = options[:max_size] || Cloud::MAX_SIZE |
39 | min_size = options[:min_size] || Cloud::MIN_SIZE | 40 | min_size = options[:min_size] || Cloud::MIN_SIZE |
40 | 41 |
app/models/tags_block.rb
@@ -24,9 +24,7 @@ class TagsBlock < Block | @@ -24,9 +24,7 @@ class TagsBlock < Block | ||
24 | return '' if tags.empty? | 24 | return '' if tags.empty? |
25 | 25 | ||
26 | if limit | 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 } | 27 | + tags = tags.sort_by{ |k,v| -v }[0..(limit-1)] |
30 | end | 28 | end |
31 | 29 | ||
32 | block_title(title) + | 30 | block_title(title) + |
public/designs/themes/base/style.css
test/unit/tags_block_test.rb
@@ -37,4 +37,8 @@ class TagsBlockTest < Test::Unit::TestCase | @@ -37,4 +37,8 @@ class TagsBlockTest < Test::Unit::TestCase | ||
37 | assert_match /profile\/testinguser\/tags\/first-tag/, block.content | 37 | assert_match /profile\/testinguser\/tags\/first-tag/, block.content |
38 | end | 38 | end |
39 | 39 | ||
40 | + should 'order tags alphabetically' do | ||
41 | + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content | ||
42 | + end | ||
43 | + | ||
40 | end | 44 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class TagsHelperTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + include ApplicationHelper | ||
6 | + include TagsHelper | ||
7 | + include ActionController::UrlWriter | ||
8 | + | ||
9 | + def h(s); s; end | ||
10 | + def link_to(text, *args); text; end | ||
11 | + | ||
12 | + should 'order tags alphabetically' do | ||
13 | + result = tag_cloud( | ||
14 | + { 'tag1'=>9, 'Tag3'=>2, 'Tag2'=>2, 'aTag'=>2, 'beTag'=>2 }, | ||
15 | + :id, | ||
16 | + { :host=>'noosfero.org', :controller=>'test', :action=>'tag' } | ||
17 | + ) | ||
18 | + assert_equal %w(aTag beTag tag1 Tag2 Tag3).join("\n"), result | ||
19 | + end | ||
20 | + | ||
21 | +end |