From 44876963e9d7468c948fe6c02ac957deabe76b72 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sat, 2 Jul 2011 15:21:30 +0200 Subject: [PATCH] Added truncation side-wide for too long strings; --- app/helpers/application_helper.rb | 20 ++++++++++++++++---- app/helpers/artists_helper.rb | 3 +++ app/views/artists/_more_tracks.html.haml | 4 ++-- app/views/search/_more_artists.html.haml | 2 +- public/javascripts/ajax/requests.js | 1 - public/javascripts/layout.js | 2 +- public/stylesheets/sass/_home.scss | 1 + test/unit/helpers/artists_helper_test.rb | 4 ++++ 8 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 app/helpers/artists_helper.rb create mode 100644 test/unit/helpers/artists_helper_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c0e4c17..e8c28dd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,13 +41,25 @@ module ApplicationHelper # STRING HELPER - def trimString str, length - truncate str, :length => length.to_i, :omission => "…" - end - def camelCaseString phrase phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase } return phrase end + def trimString str, length + truncate str, :length => length.to_i, :omission => "…" + end + + def trimTrack track, artist + returnValue = track + desiredLength = 60 + actualLength = track.length + artist.length + overflow = actualLength - desiredLength + + if actualLength > desiredLength + returnValue = trimString track, track.length - overflow + end + return returnValue + end + end \ No newline at end of file diff --git a/app/helpers/artists_helper.rb b/app/helpers/artists_helper.rb new file mode 100644 index 0000000..eaa1231 --- /dev/null +++ b/app/helpers/artists_helper.rb @@ -0,0 +1,3 @@ +module ArtistsHelper + +end diff --git a/app/views/artists/_more_tracks.html.haml b/app/views/artists/_more_tracks.html.haml index f8e7299..b34a850 100644 --- a/app/views/artists/_more_tracks.html.haml +++ b/app/views/artists/_more_tracks.html.haml @@ -1,6 +1,6 @@ - @tracks.track.each do |track| - artist = track.artist.respond_to?(:name) ? track.artist.name : track.artist %li{:artist=>artist,:track=>track.name} - = track.name + = trimTrack(track.name, artist) %span by - = link_to trimString(artist, 50), "#!/artists/#{CGI.escape(artist)}" \ No newline at end of file + = link_to trimString(artist, 50), "#!/artists/#{CGI.escape(artist)}" \ No newline at end of file diff --git a/app/views/search/_more_artists.html.haml b/app/views/search/_more_artists.html.haml index 5e2aec3..932c126 100644 --- a/app/views/search/_more_artists.html.haml +++ b/app/views/search/_more_artists.html.haml @@ -3,6 +3,6 @@ - @link = "#!/artists/#{CGI.escape(artist.name)}" .img= link_to image_tag(validate_img_url(artist.image, "artist", :large)), @link .text - %h2= link_to artist.name, @link + %h2= link_to trimString(artist.name, 55), @link %p = artist.listeners+" Listeners" \ No newline at end of file diff --git a/public/javascripts/ajax/requests.js b/public/javascripts/ajax/requests.js index 0ee95cc..930eef7 100644 --- a/public/javascripts/ajax/requests.js +++ b/public/javascripts/ajax/requests.js @@ -44,7 +44,6 @@ function favourite_request(link, params){ function load_site_request(link, params){ params = (typeof params == "undefined" || typeof params == "boolean") ? "" : params; - show_flash(false); if(link != user_path) diff --git a/public/javascripts/layout.js b/public/javascripts/layout.js index 7262108..3065967 100644 --- a/public/javascripts/layout.js +++ b/public/javascripts/layout.js @@ -91,7 +91,7 @@ function remove_links_from_description(){ function new_albums(){ album_hover(); - album_add_show_songs_button(); + //album_add_show_songs_button(); } diff --git a/public/stylesheets/sass/_home.scss b/public/stylesheets/sass/_home.scss index 9b53208..df8a82d 100644 --- a/public/stylesheets/sass/_home.scss +++ b/public/stylesheets/sass/_home.scss @@ -10,6 +10,7 @@ overflow: hidden; float: left; + img { position: absolute; top: 0; diff --git a/test/unit/helpers/artists_helper_test.rb b/test/unit/helpers/artists_helper_test.rb new file mode 100644 index 0000000..0919904 --- /dev/null +++ b/test/unit/helpers/artists_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ArtistsHelperTest < ActionView::TestCase +end