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

Changeset 8830

Show
Ignore:
Timestamp:
02/10/08 01:04:27 (5 months ago)
Author:
nzkoz
Message:

2-0-stable: Add label_tag helper for generating elements. References #10802 [DefV]

Merging [8685]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-0-stable/actionpack/CHANGELOG

    r8814 r8830  
    66 
    77* Fix bug with setting Request#format= after the getter has cached the value.  #10889 [cch1] 
     8 
     9* Add label_tag helper for generating elements. #10802 [DefV] 
    810 
    911* TestSession supports indifferent access.  #7372 [tamc, Arsen7, mhackett, julik, jean.helou] 
  • branches/2-0-stable/actionpack/lib/action_view/helpers/form_tag_helper.rb

    r8203 r8830  
    113113      def text_field_tag(name, value = nil, options = {}) 
    114114        tag :input, { "type" => "text", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys) 
     115      end 
     116 
     117      # Creates a label field 
     118      # 
     119      # ==== Options 
     120      # * Creates standard HTML attributes for the tag. 
     121      # 
     122      # ==== Examples 
     123      #   label_tag 'name' 
     124      #   # => <label for="name">Name</label> 
     125      # 
     126      #   label_tag 'name', 'Your name' 
     127      #   # => <label for="name">Your Name</label> 
     128      # 
     129      #   label_tag 'name', nil, :class => 'small_label' 
     130      #   # => <label for="name" class="small_label">Name</label> 
     131      def label_tag(name, text = nil, options = {}) 
     132        content_tag :label, text || name.humanize, { "for" => name }.update(options.stringify_keys) 
    115133      end 
    116134 
  • branches/2-0-stable/actionpack/test/template/form_tag_helper_test.rb

    r7993 r8830  
    189189  end 
    190190 
     191  def test_label_tag_without_text 
     192    actual = label_tag "title" 
     193    expected = %(<label for="title">Title</label>) 
     194    assert_dom_equal expected, actual 
     195  end 
     196 
     197  def test_label_tag_with_text 
     198    actual = label_tag "title", "My Title" 
     199    expected = %(<label for="title">My Title</label>) 
     200    assert_dom_equal expected, actual 
     201  end 
     202 
     203  def test_label_tag_class_string 
     204    actual = label_tag "title", "My Title", "class" => "small_label" 
     205    expected = %(<label for="title" class="small_label">My Title</label>) 
     206    assert_dom_equal expected, actual 
     207  end 
     208 
    191209  def test_boolean_optios 
    192210    assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")