Changeset 9083
- Timestamp:
- 03/24/08 02:29:30 (2 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/text_helper.rb (modified) (2 diffs)
- trunk/actionpack/test/template/text_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r9080 r9083 1 1 *SVN* 2 3 # Allow the #simple_format text_helper to take an html_options hash for each paragraph. #2448 [Francois Beausoleil, thechrisoshow] 2 4 3 5 * Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [rick] trunk/actionpack/lib/action_view/helpers/text_helper.rb
r9035 r9083 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." … … 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) 305 content_tag 'p', text.to_s. 306 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 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={}) 310 start_tag = tag('p', html_options, true) 311 text = text.to_s.dup 312 text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n 313 text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph 314 text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br 315 text.insert 0, start_tag 316 text << "</p>" 309 317 end 310 318 trunk/actionpack/test/template/text_helper_test.rb
r9030 r9083 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