Ticket #2448: simple_format_html_options.diff
| File simple_format_html_options.diff, 2.3 kB (added by thechrisoshow, 7 months ago) |
|---|
-
actionpack/test/template/text_helper_test.rb
old new 24 24 25 25 text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze 26 26 assert_equal "<p>A\n<br /> \n<br />B</p>\n\n<p>\t\n<br />C\n<br />D</p>", simple_format(text) 27 28 assert_equal %q(<p class="test">This is a classy test</p>), simple_format("This is a classy test", :class => 'test') 29 assert_equal %Q(<p class="test">para 1</p>\n\n<p class="test">para 2</p>), simple_format("para 1\n\npara 2", :class => 'test') 27 30 end 28 31 29 32 def test_truncate -
actionpack/lib/action_view/helpers/text_helper.rb
old new 291 291 # considered as a linebreak and a <tt><br /></tt> tag is appended. This 292 292 # method does not remove the newlines from the +text+. 293 293 # 294 # You can pass any HTML attributes into <tt>html_options</tt>. These 295 # will be added to all created paragraphs. 294 296 # ==== Examples 295 297 # my_text = "Here is some basic text...\n...with a line break." 296 298 # … … 301 303 # 302 304 # simple_format(more_text) 303 305 # # => "<p>We want to put a paragraph...</p>\n\n<p>...right there.</p>" 304 def simple_format(text) 306 # 307 # simple_format("Look ma! A class!", :class => 'description') 308 # # => "<p class='description'>Look ma! A class!</p>" 309 def simple_format(text, html_options={}) 305 310 content_tag 'p', text.to_s. 306 311 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n 307 gsub(/\n\n+/, "</p>\n\n<p>"). # 2+ newline -> paragraph 308 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br 312 gsub(/\n\n+/, "</p>\n\n#{tag('p', html_options, true)}"). # 2+ newline -> paragraph 313 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'), # 1 newline -> br 314 html_options 309 315 end 310 316 311 317 # Turns all URLs and e-mail addresses into clickable links. The +link+ parameter