2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/pickaxe/extensions.rb', line 2
def word_wrap(*args)
options = args.
unless args.blank?
options[:line_width] = args[0] || Pickaxe::Shell.dynamic_width || 80
end
options.reverse_merge!({
:line_width => (Pickaxe::Shell.dynamic_width || 80),
:indent => 0
})
options[:line_width] -= options[:indent]
self.split("\n").collect do |line|
if line.length > options[:line_width]
line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n#{" " * options[:indent]}").strip
else
line.strip
end
end * "\n#{" " * options[:indent]}"
end
|