Commit 6c532f5dfb7d278f3c53ffde6d911bdab2ff790b
Committed by
Antonio Terceiro
1 parent
688faaee
Exists in
master
and in
29 other branches
fixing big file names liting in layout
(ActionItem1299)
Showing
4 changed files
with
42 additions
and
2 deletions
Show diff stats
app/helpers/folder_helper.rb
| @@ -19,7 +19,7 @@ module FolderHelper | @@ -19,7 +19,7 @@ module FolderHelper | ||
| 19 | def display_article_in_listing(article, recursive = false, level = 0) | 19 | def display_article_in_listing(article, recursive = false, level = 0) |
| 20 | result = content_tag( | 20 | result = content_tag( |
| 21 | 'tr', | 21 | 'tr', |
| 22 | - content_tag('td', link_to((' ' * (level * 4) ) + image_tag(icon_for_article(article)) + article.name, article.url.merge(:view => true)))+ | 22 | + content_tag('td', link_to((' ' * (level * 4) ) + image_tag(icon_for_article(article)) + short_filename(article.name), article.url.merge(:view => true)))+ |
| 23 | content_tag('td', show_date(article.updated_at), :class => 'last-update'), | 23 | content_tag('td', show_date(article.updated_at), :class => 'last-update'), |
| 24 | :class => 'sitemap-item' | 24 | :class => 'sitemap-item' |
| 25 | ) | 25 | ) |
| @@ -69,4 +69,11 @@ module FolderHelper | @@ -69,4 +69,11 @@ module FolderHelper | ||
| 69 | _('Edit folder') | 69 | _('Edit folder') |
| 70 | end | 70 | end |
| 71 | 71 | ||
| 72 | + def short_filename(filename, limit_chars = 43) | ||
| 73 | + return filename if filename.size <= limit_chars | ||
| 74 | + extname = File.extname(filename) | ||
| 75 | + basename = File.basename(filename,extname) | ||
| 76 | + str_complement = '(...)' | ||
| 77 | + return basename[0..(limit_chars - extname.size - str_complement.size - 1)] + str_complement + extname | ||
| 78 | + end | ||
| 72 | end | 79 | end |
app/views/cms/view.rhtml
| @@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
| 72 | <tr> | 72 | <tr> |
| 73 | <td> | 73 | <td> |
| 74 | <%= image_tag(icon_for_article(item)) %> | 74 | <%= image_tag(icon_for_article(item)) %> |
| 75 | - <%= link_to item.name, :action => 'edit', :id => item.id %> | 75 | + <%= link_to short_filename(item.name,30), :action => 'edit', :id => item.id %> |
| 76 | </td> | 76 | </td> |
| 77 | <td> | 77 | <td> |
| 78 | <%= item.class.short_description %> | 78 | <%= item.class.short_description %> |
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +Feature: sitemap | ||
| 2 | + As a noosfero user | ||
| 3 | + I want to list articles | ||
| 4 | + | ||
| 5 | + Background: | ||
| 6 | + Given I am on the homepage | ||
| 7 | + And the following users | ||
| 8 | + | login | name | | ||
| 9 | + | joaosilva | Joao Silva | | ||
| 10 | + And the following files | ||
| 11 | + | owner | file | mime | | ||
| 12 | + | joaosilva | AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.txt | text/plain | | ||
| 13 | + | ||
| 14 | + Scenario: view a folder page | ||
| 15 | + When I am on /profile/joaosilva/sitemap | ||
| 16 | + Then I should see "AGENDA_CULTURA_-_FESTA_DE_VAQUEIRO(...).txt" | ||
| 17 | + | ||
| 18 | + Scenario: view a folder page | ||
| 19 | + Given I am logged in as "joaosilva" | ||
| 20 | + When I am on /myprofile/joaosilva/cms | ||
| 21 | + Then I should see "AGENDA_CULTURA_-_FEST(...).txt" |
test/unit/application_helper_test.rb
| @@ -558,6 +558,18 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -558,6 +558,18 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 558 | assert_equal environment.theme, current_theme | 558 | assert_equal environment.theme, current_theme |
| 559 | end | 559 | end |
| 560 | 560 | ||
| 561 | + should 'trunc to 15 chars the big filename' do | ||
| 562 | + assert_equal 'AGENDA(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3',15) | ||
| 563 | + end | ||
| 564 | + | ||
| 565 | + should 'trunc to default limit the big filename' do | ||
| 566 | + assert_equal 'AGENDA_CULTURA_-_FESTA_DE_VAQUEIRO(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3') | ||
| 567 | + end | ||
| 568 | + | ||
| 569 | + should 'does not trunc short filename' do | ||
| 570 | + assert_equal 'filename.mp3', short_filename('filename.mp3') | ||
| 571 | + end | ||
| 572 | + | ||
| 561 | protected | 573 | protected |
| 562 | 574 | ||
| 563 | def url_for(args = {}) | 575 | def url_for(args = {}) |