Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/fix blank content class #47

Merged
merged 3 commits into from

2 participants

@blakehilscher

Fix for config.blank_content_class being ignored on attributes.

@rafaelfranca rafaelfranca merged commit 31bdd7e into plataformatec:master
@rafaelfranca
Collaborator

Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 21, 2012
  1. add failing test for blank_content_class

    Blake H authored
  2. corrected test name

    Blake H authored
  3. added apply_wrapper_options!(type, options, value) and added this met…

    Blake H authored
    …hod to options that are passed to wrap_with
This page is out of date. Refresh to see the latest.
View
12 lib/show_for/builder.rb
@@ -25,11 +25,11 @@ def object_name #:nodoc:
def wrap_label_and_content(name, value, options, &block) #:nodoc:
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)
+ wrap_with(:wrapper, label + content(value, options, false, &block), apply_wrapper_options!(:wrapper, options, value))
end
def wrap_content(name, value, options, &block) #:nodoc:
- wrap_with(:wrapper, content(value, options, false, &block), options)
+ wrap_with(:wrapper, content(value, options, false, &block), apply_wrapper_options!(:wrapper, options, value))
end
# Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
@@ -38,7 +38,13 @@ def apply_default_options!(name, options) #:nodoc:
wrapper_html = options[:wrapper_html] ||= {}
wrapper_html[:class] = "#{html_class} #{wrapper_html[:class]}".rstrip
end
-
+
+ def apply_wrapper_options!(type, options, value)
+ options[:"#{type}_html"] ||= {}
+ options[:"#{type}_html"][:class] = [options[:"#{type}_html"][:class], ShowFor.blank_content_class].join(' ') if value.blank? && value != false
+ options
+ end
+
# Gets the default tag set in ShowFor module and apply (if defined)
# around the given content. It also check for html_options in @options
# hash related to the current type.
View
7 lib/show_for/content.rb
@@ -1,9 +1,12 @@
module ShowFor
module Content
def content(value, options={}, apply_options=true, &block)
+
+ # cache value for apply_wrapper_options!
+ sample_value = value
+
if value.blank? && value != false
value = blank_value(options)
- options[:class] = [options[:class], ShowFor.blank_content_class].join(' ')
end
# We need to convert value to_a because when dealing with ActiveRecord
@@ -28,7 +31,7 @@ def content(value, options={}, apply_options=true, &block)
end
options[:content_html] = options.except(:content_tag) if apply_options
- wrap_with(:content, content, options)
+ wrap_with(:content, content, apply_wrapper_options!(:content, options, sample_value) )
end
protected
View
9 test/attribute_test.rb
@@ -171,4 +171,13 @@ class AttributeTest < ActionView::TestCase
assert_select "div.show_for p.user_email.wrapper", /Not specified/
assert_select "p.user_email strong.label", "Email"
end
+
+ test "show_for should wrap blank attributes with no_attribute" do
+ swap ShowFor, :blank_content_class => 'no_attribute' do
+ with_attributes_for @user, :name, :birthday
+ assert_select ".wrapper.user_birthday.no_attribute"
+ assert_select ".wrapper.user_name.no_attribute", false
+ end
+ end
+
end
Something went wrong with that request. Please try again.