diff options
author | Alexey Vakhov <vakhov@gmail.com> | 2012-02-15 10:31:23 +0400 |
---|---|---|
committer | Alexey Vakhov <vakhov@gmail.com> | 2012-02-15 10:31:23 +0400 |
commit | 393d4eca8f19aefbbd4adf0b40f8b5b71a71ebe8 (patch) | |
tree | 2491dfcfb4757559f0a7de7e94a37f7d9f55df39 /actionmailer | |
parent | 5cc47e4c1926e0806897532d5d49c35df912b28c (diff) | |
download | rails-393d4eca8f19aefbbd4adf0b40f8b5b71a71ebe8.tar.gz rails-393d4eca8f19aefbbd4adf0b40f8b5b71a71ebe8.tar.bz2 rails-393d4eca8f19aefbbd4adf0b40f8b5b71a71ebe8.zip |
Cosmetic fixes in block_format AM helper method + test
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/mail_helper_test.rb | 31 |
2 files changed, 33 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 6f22adc479..869c4dff4c 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -3,9 +3,9 @@ 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) - formatted = text.split(/\n\r\n/).collect { |paragraph| + formatted = text.split(/\n\r?\n/).collect { |paragraph| format_paragraph(paragraph) - }.join("\n") + }.join("\n\n") # Make list points stand on their own line formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb index 17e9c82045..158a48e995 100644 --- a/actionmailer/test/mail_helper_test.rb +++ b/actionmailer/test/mail_helper_test.rb @@ -34,6 +34,23 @@ class HelperMailer < ActionMailer::Base end end + def use_block_format + @text = <<-TEXT +This is the +first paragraph. + +The second + paragraph. + +* item1 * item2 + * item3 + TEXT + + mail_with_defaults do |format| + format.html { render(:inline => "<%= block_format @text %>") } + end + end + protected def mail_with_defaults(&block) @@ -63,5 +80,19 @@ class MailerHelperTest < ActionMailer::TestCase mail = HelperMailer.use_format_paragraph assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded end + + def test_use_block_format + mail = HelperMailer.use_block_format + expected = <<-TEXT + This is the first paragraph. + + The second paragraph. + + * item1 + * item2 + * item3 + TEXT + assert_equal expected.gsub("\n", "\r\n"), mail.body.encoded + end end |