Commit f51b6082b49021f41faff079410fdb463a2bc478

Authored by Aurelio A. Heckert
Committed by Joenio Costa
1 parent 6c1289d2

Order tags alphabetically

(ActionItem1325)
app/helpers/tags_helper.rb
... ... @@ -28,7 +28,6 @@ module TagsHelper
28 28 # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem
29 29 # (pt_BR only).
30 30 def tag_cloud(tags, tagname_option, url, options = {})
31   -
32 31  
33 32 return content_tag('em', _('No tags yet.')) +
34 33 ' <a href="' + _('http://en.wikipedia.org/wiki/Tag_%28metadata%29') +
... ... @@ -42,7 +41,7 @@ module TagsHelper
42 41 max = tags.values.max.to_f
43 42 min = tags.values.min.to_f
44 43  
45   - tags.map do |tag,count|
  44 + tags.sort_by{ |k,v| k.downcase }.map do |tag,count|
46 45 if ( max == min )
47 46 v = 0.5
48 47 else
... ...
public/designs/themes/base/style.css
... ... @@ -666,6 +666,7 @@ div#notice {
666 666  
667 667 .tag_cloud a {
668 668 text-decoration: none;
  669 + white-space: nowrap;
669 670 }
670 671  
671 672 .tag_cloud a small {
... ...
test/unit/tags_block_test.rb
... ... @@ -37,4 +37,8 @@ class TagsBlockTest &lt; Test::Unit::TestCase
37 37 assert_match /profile\/testinguser\/tags\/first-tag/, block.content
38 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 44 end
... ...
test/unit/tags_helper_test.rb 0 → 100644
... ... @@ -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
... ...