Skip to content

Instantly share code, notes, and snippets.

@shamil614
Created November 22, 2011 20:49
Show Gist options
  • Save shamil614/1386904 to your computer and use it in GitHub Desktop.
Save shamil614/1386904 to your computer and use it in GitHub Desktop.
Split string on spaces helper
def split_on_spaces(text,limit,wrapper_id_short=nil,wrapper_id_long=nil)
results = text.split(' ')
i = 0
short_p = ""
long_p = ""
while short_p.length < limit && i <= results.count - 1
short_p << results[i] + ' '
i+= 1
end
rem = results[i..results.count-1]
rem.each{|x| long_p << x.to_s + ' ' }
html = content_tag("div", short_p.rstrip + '<span>...<span>', :id => wrapper_id_short)
html << content_tag("div", long_p, :id => wrapper_id_long)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment