module Padrino::Helpers::FormatHelpers

def word_wrap(text, *args)

Other tags:
    Api: - public

Returns:
  • (String) - The text with line wraps for lines longer then +line_width+

Options Hash: (**options)
  • :line_width (Fixnum) --

Parameters:
  • options (Hash) --
  • text (String) --

Overloads:
  • word_wrap(text, options={})
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").map do |line|
    line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
  end * "\n"
end