Skip to content

Commit

Permalink
Fix blank labels to be html safe and do not include separator if labe…
Browse files Browse the repository at this point in the history
…l is skipped
  • Loading branch information
eugenebolshakov authored and carlosantoniodasilva committed Sep 14, 2010
1 parent 93e4c2b commit a9495c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/show_for/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ 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.html_safe +
content(value, options, false, &block), options)
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)
end

# Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
Expand Down Expand Up @@ -57,4 +58,4 @@ def collection_block?(block) #:nodoc:
block && block.arity == 1
end
end
end
end
4 changes: 2 additions & 2 deletions lib/show_for/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

label = ShowFor.label_proc.call(label) if options.fetch(:wrap_label, true) && ShowFor.label_proc
Expand All @@ -22,4 +22,4 @@ def human_attribute_name(attribute) #:nodoc:
@object.class.human_attribute_name(attribute.to_s)
end
end
end
end
3 changes: 2 additions & 1 deletion test/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def with_attributes_for(object, *attributes)
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
Expand Down Expand Up @@ -356,4 +357,4 @@ def with_attributes_for(object, *attributes)
assert_select "div.show_for p.user_email.wrapper", /Not specified/
assert_select "p.user_email strong.label", "Email"
end
end
end

0 comments on commit a9495c7

Please sign in to comment.