diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-19 09:57:16 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-19 09:57:16 +0000 |
commit | 229ea6537459d9d55c2f140bce14fdfe45b4472e (patch) | |
tree | f1ba482e49a8af3eed24a39c855bb5cb54b33d87 /actionpack/lib/action_view | |
parent | bc76044fde8701d19ab85d244789a69ba5ed9bbd (diff) | |
download | rails-229ea6537459d9d55c2f140bce14fdfe45b4472e.tar.gz rails-229ea6537459d9d55c2f140bce14fdfe45b4472e.tar.bz2 rails-229ea6537459d9d55c2f140bce14fdfe45b4472e.zip |
simple_format helper doesn't choke on nil. Closes #6644.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5561 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 8f956133b7..0b04bd323f 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -154,12 +154,10 @@ module ActionView # considered as a linebreak and a <tt><br /></tt> tag is appended. This # method does not remove the newlines from the +text+. def simple_format(text) - text = text.gsub(/(\r\n|\n|\r)/, "\n") # lets make them newlines crossplatform - text.gsub!(/\n\n+/, "\n\n") # zap dupes - text.gsub!(/\n\n/, '</p>\0<p>') # turn two newlines into paragraph - text.gsub!(/([^\n])(\n)(?=[^\n])/, '\1\2<br />') # turn single newline into <br /> - - content_tag("p", text) + content_tag 'p', text.to_s. + gsub(/\r\n?/, "\n"). # \r\n and \r -> \n + gsub(/\n\n+/, "</p>\n\n<p>"). # 2+ newline -> paragraph + gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br end # Turns all urls and email addresses into clickable links. The +link+ parameter |