module Padrino::Helpers::FormatHelpers

def word_wrap(text, *args)


word_wrap('Once upon a time', :line_width => 8) => "Once upon\na time"

==== Examples

This method breaks on the first whitespace character that does not exceed line_width (which is 80 by default).
Wraps the text into lines no longer than line_width width.
#
def word_wrap(text, *args)
  options = args.extract_options!
  unless args.blank?
    options[:line_width] = args[0] || 80
  end
  options.reverse_merge!(:line_width => 80)
  text.split("\n").collect do |line|
    line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
  end * "\n"
end