diff options
Diffstat (limited to 'actionmailer/lib/action_mailer/mail_helper.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb new file mode 100644 index 0000000000..f4eeed0e42 --- /dev/null +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -0,0 +1,19 @@ +module ActionMailer + module MailHelper + # Uses Text::Format to take the text and format it, indented two spaces for + # each line, and wrapped at 72 columns. + def block_format(text) + formatted = text.split(/\n\r\n/).collect { |paragraph| + Text::Format.new( + :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph + ).format + }.join("\n") + + # Make list points stand on their own line + formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } + formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } + + formatted + end + end +end |