public
Description: Merb Plugins: Even more modules to hook up your Merb installation
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-plugins.git
Added a public #label helper. Specs provided by Bryan Ray. Closes #155
Michael Sheakoski (author)
Fri Sep 05 17:00:29 -0700 2008
commit  91c5f336e898b06c0a811eb827f58c61d8c513da
tree    9003fe9a64abb51b2c6c302172fccdaaa67f99c0
parent  a269b9b92ca1fc4acc14dce60202fc8d8a6e2aa8
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
 
 
 
 
 
 
 
 
306
307
308
...
287
288
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
291
292
293
294
295
296
297
298
299
300
0
@@ -287,22 +287,14 @@ module Merb::Helpers::Form::Builder
0
       super
0
     end
0
 
0
-    # Provides a generic HTML label.
0
-    #
0
-    # ==== Parameters
0
-    # attrs<Hash>:: HTML attributes
0
-    #
0
-    # ==== Returns
0
-    # String:: HTML
0
-    #
0
-    # ==== Example
0
-    #   <%= label :for => "name", :label => "Full Name" %> 
0
-    #   => <label for="name">Full Name</label>
0
-    def label(attrs)
0
-      attrs ||= {}
0
-      for_attr = attrs[:id] ? {:for => attrs[:id]} : {}
0
-      if label_text = attrs.delete(:label)
0
-        tag(:label, label_text, for_attr)
0
+    def label(contents, attrs = {})
0
+      if contents.is_a?(Hash)
0
+        attrs    = contents
0
+        contents = attrs.delete(:label)
0
+      end
0
+      if contents
0
+        for_attr = attrs[:id] ? {:for => attrs[:id]} : {}
0
+        tag(:label, contents, for_attr)
0
       else
0
         ""
0
       end
...
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
153
154
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
0
@@ -149,6 +149,21 @@ module Merb::Helpers::Form
0
     end
0
   end
0
 
0
+  # Provides a generic HTML label.
0
+  #
0
+  # ==== Parameters
0
+  # attrs<Hash>:: HTML attributes
0
+  #
0
+  # ==== Returns
0
+  # String:: HTML
0
+  #
0
+  # ==== Example
0
+  #   <%= label "Full Name", :for => "name" %> 
0
+  #   => <label for="name">Full Name</label>
0
+  def label(*args)
0
+    current_form_context.label(*args)
0
+  end
0
+
0
   # Provides a HTML text input tag
0
   #
0
   # ==== Parameters
...
1011
1012
1013
 
 
 
 
 
 
 
 
 
1014
1015
1016
...
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
0
@@ -1011,6 +1011,15 @@ describe "fieldset" do
0
   end
0
 end
0
 
0
+describe "label" do
0
+  it_should_behave_like "FakeController"
0
+
0
+  it "should render a label tag" do
0
+    result = label("First Name", :id => "user_first_name")
0
+    result.should match_tag(:label, :for => "user_first_name", :content => "First Name")
0
+  end
0
+end
0
+
0
 describe "file_field" do
0
   it_should_behave_like "FakeController"
0
 

Comments