Hi! I'm writing a piece of code that tries to truncate the amount of text displayed in the cell to restrict it such that the formatting doesn't spoil if the string is too long.
What I want to do is: 1. If the 'met_person' string is longer than 20 characters, I want to pick the first 18 and add "..." to it and display that in the cell. 2. Also, I want to use the title attribute for the cell so that a mouse over shows the full text. 3. If the name is shorter than 20 characters, it is fine - just display it completely
So, right now, I have something like this which works (I guess it can be cleaned up): <td class='person' title='<%= meeting.met_person %>'><%= (meeting.met_person.length > 20)? meeting.met_person[0..17]+'...':meeting.met_person %></td>
My questions: 1. I'd like to make this a generic helper that automatically truncates the text. So, should I put in a helper file? So, this could be something like truncate_text(meeting.met_person, 20) and the function could do the check and return the correct string.
2. Since there is sufficient repetition to create the title and the text in the cell, it may be nice to create something that creates the full HTML code, rather than just the string. Where would that go? Would that be a helper too?
Thanks Mohit.