diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index fef502a..7acf7bd 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -28,13 +28,14 @@ module TagsHelper # courtesy of Aurelio: http://www.colivre.coop.br/Aurium/Nuvem # (pt_BR only). def tag_cloud(tags, tagname_option, url, options = {}) - return content_tag('em', _('No tags yet.')) + ' (' + _('What are tags?') + ')' if tags.empty? + tags = tags.sort_by{ |k,v| k.downcase } + max_size = options[:max_size] || Cloud::MAX_SIZE min_size = options[:min_size] || Cloud::MIN_SIZE diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb index ef4d093..bc0e520 100644 --- a/app/models/tags_block.rb +++ b/app/models/tags_block.rb @@ -24,9 +24,7 @@ class TagsBlock < Block return '' if tags.empty? if limit - tags_tmp = tags.sort_by{ |k,v| -v }[0..(limit-1)] - tags = {} - tags_tmp.map{ |k,v| tags[k] = v } + tags = tags.sort_by{ |k,v| -v }[0..(limit-1)] end block_title(title) + diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index 12a0073..f2b197b 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -695,6 +695,7 @@ div#notice { .tag_cloud a { text-decoration: none; + white-space: nowrap; } .tag_cloud a small { diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb index 5b5863d..1bd1ae2 100644 --- a/test/unit/tags_block_test.rb +++ b/test/unit/tags_block_test.rb @@ -37,4 +37,8 @@ class TagsBlockTest < Test::Unit::TestCase assert_match /profile\/testinguser\/tags\/first-tag/, block.content end + should 'order tags alphabetically' do + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content + end + end diff --git a/test/unit/tags_helper_test.rb b/test/unit/tags_helper_test.rb new file mode 100644 index 0000000..da5f0ae --- /dev/null +++ b/test/unit/tags_helper_test.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TagsHelperTest < Test::Unit::TestCase + + include ApplicationHelper + include TagsHelper + include ActionController::UrlWriter + + def h(s); s; end + def link_to(text, *args); text; end + + should 'order tags alphabetically' do + result = tag_cloud( + { 'tag1'=>9, 'Tag3'=>2, 'Tag2'=>2, 'aTag'=>2, 'beTag'=>2 }, + :id, + { :host=>'noosfero.org', :controller=>'test', :action=>'tag' } + ) + assert_equal %w(aTag beTag tag1 Tag2 Tag3).join("\n"), result + end + +end -- libgit2 0.21.2