Skip to content

Instantly share code, notes, and snippets.

@shamil614
Created November 22, 2011 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil614/1386727 to your computer and use it in GitHub Desktop.
Save shamil614/1386727 to your computer and use it in GitHub Desktop.
Split paragraph helper
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