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:
parent
dc3d202665
commit
2c5e5a0015
5 changed files with 22 additions and 25 deletions
|
@ -389,19 +389,6 @@ class WikiController < ApplicationController
|
|||
end
|
||||
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
|
||||
|
||||
protected
|
||||
|
||||
def do_caching?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue