Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7432: content_tag_accepts_block_from_helper.diff

File content_tag_accepts_block_from_helper.diff, 1.7 kB (added by cody, 2 years ago)
  • test/template/tag_helper_test.rb

    old new  
    3636  end 
    3737   
    3838  def test_content_tag_with_block 
    39     _erbout = '' 
    40     content_tag(:div) { _erbout.concat "Hello world!" } 
    41     assert_dom_equal "<div>Hello world!</div>", _erbout 
     39    assert_dom_equal "<div>Hello world!</div>", content_tag(:div) { "Hello world!" } 
    4240  end 
    4341   
    4442  def test_content_tag_with_block_and_options 
    45     _erbout = '' 
    46     content_tag(:div, :class => "green") { _erbout.concat "Hello world!" } 
    47     assert_dom_equal %(<div class="green">Hello world!</div>), _erbout 
     43    assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, :class => "green") { "Hello world!" } 
    4844  end 
    4945   
    5046  def test_cdata_section 
  • lib/action_view/helpers/tag_helper.rb

    old new  
    4747      def content_tag(name, content_or_options_with_block = nil, options = nil, &block) 
    4848        if block_given? 
    4949          options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) 
    50           content = capture(&block) 
    51           concat(content_tag_string(name, content, options), block.binding) 
     50          content = block.call 
    5251        else 
    5352          content = content_or_options_with_block 
    54           content_tag_string(name, content, options) 
    5553        end 
     54        content_tag_string(name, content, options) 
    5655      end 
    5756 
    5857      # Returns a CDATA section with the given +content+.  CDATA sections