Added truncation side-wide for too long strings;

This commit is contained in:
Tobias Klika
2011-07-02 15:21:30 +02:00
parent dac0f9349b
commit 44876963e9
8 changed files with 28 additions and 9 deletions
+16 -4
View File
@@ -41,13 +41,25 @@ module ApplicationHelper
# STRING HELPER # STRING HELPER
def trimString str, length
truncate str, :length => length.to_i, :omission => ""
end
def camelCaseString phrase def camelCaseString phrase
phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase } phrase.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
return phrase return phrase
end 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 end
+3
View File
@@ -0,0 +1,3 @@
module ArtistsHelper
end
+1 -1
View File
@@ -1,6 +1,6 @@
- @tracks.track.each do |track| - @tracks.track.each do |track|
- artist = track.artist.respond_to?(:name) ? track.artist.name : track.artist - artist = track.artist.respond_to?(:name) ? track.artist.name : track.artist
%li{:artist=>artist,:track=>track.name} %li{:artist=>artist,:track=>track.name}
= track.name = trimTrack(track.name, artist)
%span by %span by
= link_to trimString(artist, 50), "#!/artists/#{CGI.escape(artist)}" = link_to trimString(artist, 50), "#!/artists/#{CGI.escape(artist)}"
+1 -1
View File
@@ -3,6 +3,6 @@
- @link = "#!/artists/#{CGI.escape(artist.name)}" - @link = "#!/artists/#{CGI.escape(artist.name)}"
.img= link_to image_tag(validate_img_url(artist.image, "artist", :large)), @link .img= link_to image_tag(validate_img_url(artist.image, "artist", :large)), @link
.text .text
%h2= link_to artist.name, @link %h2= link_to trimString(artist.name, 55), @link
%p %p
= artist.listeners+" Listeners" = artist.listeners+" Listeners"
-1
View File
@@ -44,7 +44,6 @@ function favourite_request(link, params){
function load_site_request(link, params){ function load_site_request(link, params){
params = (typeof params == "undefined" || typeof params == "boolean") ? "" : params; params = (typeof params == "undefined" || typeof params == "boolean") ? "" : params;
show_flash(false); show_flash(false);
if(link != user_path) if(link != user_path)
+1 -1
View File
@@ -91,7 +91,7 @@ function remove_links_from_description(){
function new_albums(){ function new_albums(){
album_hover(); album_hover();
album_add_show_songs_button(); //album_add_show_songs_button();
} }
+1
View File
@@ -10,6 +10,7 @@
overflow: hidden; overflow: hidden;
float: left; float: left;
img { img {
position: absolute; position: absolute;
top: 0; top: 0;
+4
View File
@@ -0,0 +1,4 @@
require 'test_helper'
class ArtistsHelperTest < ActionView::TestCase
end