January, 2009
For a project I’m working on, we’d like to have the rails truncate helper truncate strings at word boundaries rather than at the in the middle of a word after exactly a certain number of characters.
Daniel Morrison’s awesome_truncate provides the basic idea, but it has a few problems:
truncate, in which options are passed as a hash rather than a listtruncate with calls to awesome_truncateIn addition, our client asked us to ensure that there is never a single word on a line by itself at the end of the truncated string.
If you’re even remotely interested in such matters, you’ve probably already heard about Al Jazeera’s Creative Commons-licensed repository of footage from Gaza.