Refactoring

Move the truncate() method into ApplicationHelper.
Move another method around, for no particularly
good reason. Controllers really shouldn't have
public methods that don't correspond to actions.
This commit is contained in:
Jacques Distler 2009-12-14 02:01:50 -06:00
parent dc3d202665
commit 2c5e5a0015
5 changed files with 22 additions and 25 deletions

View file

@ -111,4 +111,17 @@ module ApplicationHelper
PageRenderer.new(page.revisions.last).display_content
end
def truncate(text, length = 30, truncate_string = '...')
return text if text.length <= length
len = length - truncate_string.length
t = ''
text.split.collect do |word|
if t.length + word.length <= len
t << word + ' '
else
return t.chop + truncate_string
end
end
end
end