Permalink
Browse files

Merge branch 'master' of git://github.com/grimen/show_for

  • Loading branch information...
2 parents a152390 + 0503c54 commit 918fb0a736b53f3c35ecea577e99f101770b1ca6 @josevalim josevalim committed Jan 8, 2010
Showing with 23 additions and 4 deletions.
  1. +6 −0 lib/show_for.rb
  2. +2 −1 lib/show_for/content.rb
  3. +1 −3 lib/show_for/helper.rb
  4. +14 −0 test/builder_test.rb
View
@@ -15,6 +15,12 @@ module ShowFor
mattr_accessor :content_tag
@@content_tag = nil
+ mattr_accessor :blank_content_class
+ @@blank_content_class = "blank"
+
+ mattr_accessor :blank_content
+ @@blank_content = ""
+
mattr_accessor :wrapper_tag
@@wrapper_tag = :p
View
@@ -1,7 +1,8 @@
module ShowFor
module Content
def content(value, options={}, apply_options=true, &block)
- value = options.delete(:if_blank) if value.blank? && value != false
+ value = options.delete(:if_blank) || ShowFor.blank_content if value.blank? && value != false
+ options[:class] = [options[:class], ShowFor.blank_content_class].join(' ') if value.blank?
content = case value
when Date, Time, DateTime
View
@@ -15,9 +15,7 @@ def show_for(object, html_options={}, &block)
html_options[:id] ||= dom_id(object)
html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".strip
- concat(content_tag(tag, html_options) do
- yield ShowFor::Builder.new(object, self)
- end)
+ content_tag(tag, yield(ShowFor::Builder.new(object, self)), html_options)
end
end
end
View
@@ -211,6 +211,20 @@ 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
+ assert_select "div.show_for b.nothing"
+ end
+ end
+
+ test "show_for#content with blank value fallbacks on a default value" do
+ swap ShowFor, :blank_content => "Not specified" do
+ with_content_for @user, nil, :content_tag => :b
+ assert_select "div.show_for b", "Not specified"
+ end
+ end
# COLLECTIONS
test "show_for accepts an attribute as a collection" do

0 comments on commit 918fb0a

Please sign in to comment.