diff options
-rw-r--r-- | actionmailer/lib/action_mailer.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 19 | ||||
-rw-r--r-- | actionmailer/test/mail_helper_test.rb | 2 |
4 files changed, 24 insertions, 3 deletions
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index e8adbf0eff..e7d396aca5 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -34,11 +34,12 @@ module ActionMailer autoload :DeprecatedBody autoload :Base autoload :DeliveryMethod + autoload :MailHelper autoload :Part autoload :PartContainer autoload :Quoting - autoload :TestCase autoload :TestHelper + end module Text diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ab00bbba3c..9862c2265b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -258,7 +258,8 @@ module ActionMailer #:nodoc: include AbstractController::Layouts include AbstractController::Helpers - + helper ActionMailer::MailHelper + if Object.const_defined?(:ActionController) include ActionController::UrlWriter end 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 diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb index d04215171d..2d3565d159 100644 --- a/actionmailer/test/mail_helper_test.rb +++ b/actionmailer/test/mail_helper_test.rb @@ -56,7 +56,7 @@ end class MailerHelperTest < Test::Unit::TestCase def new_mail( charset="utf-8" ) mail = Mail.new - mail.content_type(["text", "plain", { "charset" => charset }]) + mail.set_content_type "text", "plain", { "charset" => charset } if charset mail end |