JadedEvan
8/27/2010 - 5:29 PM

word_wrap

word_wrap

  # HTML friendly version of text-wrapper. Forces the string to break
  # at given length
  def word_wrap(text, length=80)
    text.split("\s").collect do |line|
      line.length > length ? line.gsub(/(.{1,#{length}})(\s?|$)/, "\\1<br />").gsub(/<br \/>$/, '').strip : line
    end * "\n"
  end