diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 28 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 3 |
2 files changed, 19 insertions, 12 deletions
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 80ffc9b7ee..887c7012d9 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -3,17 +3,8 @@ module ActionMailer # 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) - begin - require 'text/format' - rescue LoadError => e - $stderr.puts "You don't have text-format installed in your application. Please add it to your Gemfile and run bundle install" - raise e - end unless defined?(Text::Format) - formatted = text.split(/\n\r\n/).collect { |paragraph| - Text::Format.new( - :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph - ).format + simple_format(paragraph) }.join("\n") # Make list points stand on their own line @@ -37,5 +28,22 @@ module ActionMailer def attachments @_message.attachments end + + private + def simple_format(text, len = 72, indent = 2) + sentences = [[]] + + text.split.each do |word| + if (sentences.last + [word]).join(' ').length > len + sentences << [word] + else + sentences.last << word + end + end + + sentences.map { |sentence| + "#{" " * indent}#{sentence.join(' ')}" + }.join "\n" + end end end diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 0dce0ac15d..ce664bf301 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -25,7 +25,6 @@ end silence_warnings do # These external dependencies have warnings :/ - require 'text/format' require 'mail' end @@ -79,4 +78,4 @@ def restore_delivery_method ActionMailer::Base.delivery_method = @old_delivery_method end -ActiveSupport::Deprecation.silenced = true
\ No newline at end of file +ActiveSupport::Deprecation.silenced = true |