Skip to content

Instantly share code, notes, and snippets.

@dbussink
Created September 26, 2008 07:32
Show Gist options
  • Save dbussink/13056 to your computer and use it in GitHub Desktop.
Save dbussink/13056 to your computer and use it in GitHub Desktop.
diff --git a/merb_helpers/lib/merb_helpers/form/builder.rb b/merb_helpers/lib/merb_helpers/form/builder.rb
index e7a6e9c..251a59a 100644
--- a/merb_helpers/lib/merb_helpers/form/builder.rb
+++ b/merb_helpers/lib/merb_helpers/form/builder.rb
@@ -283,8 +283,12 @@ module Merb::Helpers::Form::Builder
contents = attrs.delete(:label)
end
if contents
+ if contents.is_a?(Hash)
+ attrs = attrs.merge(contents)
+ contents = attrs.delete(:title)
+ end
for_attr = attrs[:id] ? {:for => attrs[:id]} : {}
- tag(:label, contents, for_attr)
+ tag(:label, contents, attrs.merge(for_attr))
else
""
end
diff --git a/merb_helpers/spec/merb_helpers_form_spec.rb b/merb_helpers/spec/merb_helpers_form_spec.rb
index 00fa4ab..883d739 100644
--- a/merb_helpers/spec/merb_helpers_form_spec.rb
+++ b/merb_helpers/spec/merb_helpers_form_spec.rb
@@ -216,6 +216,11 @@ describe "text_field" do
result.should match(/<label>LABEL<\/label><input type="text" class="text"\s*\/>/)
end
+ it "should provide an additional label tag with additional options if the :label option is a hash" do
+ result = text_field(:label => {:title => "LABEL", :class => "cool"} )
+ result.should match(/<label class="cool">LABEL<\/label><input type="text" class="text"\s*\/>/)
+ end
+
it "should update an existing :class with a new class" do
result = text_field(:class => "awesome foobar")
result.should == "<input type=\"text\" class=\"awesome foobar text\"/>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment