mirror of https://github.com/rails/rails
Merge pull request #5046 from avakhov/am-block-format-fit
Cosmetic fixes in block_format AM helper method + test
This commit is contained in:
commit
1c75b9afa0
|
@ -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" }
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue