Created
November 22, 2011 19:54
-
-
Save shamil614/1386727 to your computer and use it in GitHub Desktop.
Split paragraph 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_paragraphs(text,limit,wrapper_id_short=nil,wrapper_id_long=nil) | |
results = text.scan(/<p>.*?<\/p>/) | |
i = 0 | |
length = 0 | |
short_p = "" | |
while length < limit && i <= results.count - 1 | |
short_p << results[i] | |
length += results[i].length - 7 | |
i+= 1 | |
end | |
html = content_tag("div",short_p, :id => wrapper_id_short) | |
html << content_tag("div", results[i..length-1], :id => wrapper_id_long) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment