Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit cabd32d9030b399e92057ce593e21a6eb54bc512 1 parent 8aaca75
@grimen grimen authored
View
3  lib/show_for.rb
@@ -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
2  lib/show_for/content.rb
@@ -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
7 test/builder_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.