Permalink
Browse files

Added configurable "blank_content", i.e. any attribute content tag wi…

…th blank value will contain this value instead unless :if_blank is specified.
  • Loading branch information...
grimen committed Jan 8, 2010
1 parent 8aaca75 commit cabd32d9030b399e92057ce593e21a6eb54bc512
Showing with 11 additions and 1 deletion.
  1. +3 −0 lib/show_for.rb
  2. +1 −1 lib/show_for/content.rb
  3. +7 −0 test/builder_test.rb
View
@@ -18,6 +18,9 @@ module ShowFor
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,7 @@
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
View
@@ -219,6 +219,13 @@ def with_content_for(object, value, options={})
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
with_attribute_for @user, :scopes

0 comments on commit cabd32d

Please sign in to comment.