Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic fixes in block_format AM helper method + test #5046

Merged
merged 1 commit into from Feb 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/mail_helper.rb
Expand Up @@ -3,9 +3,9 @@ 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|
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" }
Expand Down
31 changes: 31 additions & 0 deletions actionmailer/test/mail_helper_test.rb
Expand Up @@ -34,6 +34,23 @@ def use_message
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)
Expand Down Expand Up @@ -63,5 +80,19 @@ def test_use_format_paragraph
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