Created
November 22, 2011 20:49
-
-
Save shamil614/1386904 to your computer and use it in GitHub Desktop.
Split string on spaces helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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