Browse files

Fix blank labels and separators to be html_safe

  • Loading branch information...
1 parent 2a104a8 commit 500cc68d113f79ce57acdc1ad8f9f0e18e5a55a2 @carlosantoniodasilva carlosantoniodasilva committed Oct 7, 2010
Showing with 11 additions and 8 deletions.
  1. +4 −2 lib/show_for/builder.rb
  2. +2 −2 lib/show_for/label.rb
  3. +4 −3 test/builder_test.rb
  4. +1 −1 test/test_helper.rb
View
6 lib/show_for/builder.rb
@@ -23,8 +23,10 @@ def object_name #:nodoc:
end
def wrap_label_and_content(name, value, options, &block) #:nodoc:
- wrap_with(:wrapper, label(name, options, false) + ShowFor.separator.to_s +
- content(value, options, false, &block), options, true, (value.is_a?(Proc) or collection_block?(block)))
+ label = label(name, options, false)
+ label += ShowFor.separator.to_s.html_safe if label.present?
+ wrap_with(:wrapper, label + content(value, options, false, &block),
+ options, true, (value.is_a?(Proc) or collection_block?(block)))
end
# Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
View
4 lib/show_for/label.rb
@@ -9,7 +9,7 @@ def label(text_or_attribute, options={}, apply_options=true)
human_attribute_name(text_or_attribute)
end
- return "" if label == false
+ return nil.to_s if label == false
options[:label_html] = options.dup if apply_options
wrap_with :label, label, options
end
@@ -20,4 +20,4 @@ def human_attribute_name(attribute) #:nodoc:
@object.class.human_attribute_name(attribute.to_s)
end
end
-end
+end
View
7 test/builder_test.rb
@@ -26,7 +26,7 @@ def with_content_for(object, value, options={})
end
end
- # WRAPPER
+ # WRAPPER
test "show_for attribute wraps each attribute with a label and content" do
with_attribute_for @user, :name
assert_select "div.show_for p.user_name.wrapper"
@@ -66,6 +66,7 @@ def with_content_for(object, value, options={})
test "show_for skips label if requested" do
with_attribute_for @user, :name, :label => false
assert_no_select "div.show_for p.wrapper strong.label"
+ assert_no_select "div.show_for p.wrapper br"
end
test "show_for allows label to be configured globally" do
@@ -218,7 +219,7 @@ def with_content_for(object, value, options={})
with_content_for @user, "Special content", :content_tag => :b, :id => "thecontent", :class => "special"
assert_select "div.show_for b#thecontent.special.content", "Special content"
end
-
+
test "show_for#content with blank value has a 'no value'-class" do
swap ShowFor, :blank_content_class => "nothing" do
with_content_for @user, nil, :content_tag => :b
@@ -327,4 +328,4 @@ def with_content_for(object, value, options={})
assert_select "div.show_for p.wrapper p.collection span", "Tag 2"
assert_select "div.show_for p.wrapper p.collection span", "Tag 3"
end
-end
+end
View
2 test/test_helper.rb
@@ -1,7 +1,7 @@
require 'rubygems'
require 'test/unit'
-gem 'actionpack', '2.3.5'
+gem 'actionpack', '2.3.9'
require 'action_controller'
require 'action_view/test_case'

0 comments on commit 500cc68

Please sign in to comment.