Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not generate label/content/wrapper/collection classes when config …

…is set to `nil`

Allows disabling/ignoring the generation of these classes when they are
not necessary.
  • Loading branch information...
commit 40c77e7531d800e19c8959b939dcb3998c778253 1 parent 133855b
@carlosantoniodasilva carlosantoniodasilva authored
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+## Unreleased
+
+### enhancements
+
+ * Do not generate label/content/wrapper/collection classes when config is set to `nil`.
+
## 0.4.0
### enhancements
View
2  lib/show_for/builder.rb
@@ -67,7 +67,7 @@ def wrap_with(type, content, options) #:nodoc:
if tag
type_class = ShowFor.send :"#{type}_class"
html_options = options.delete(:"#{type}_html") || {}
- html_options[:class] = "#{type_class} #{html_options[:class]}".rstrip
+ html_options[:class] = [type_class, html_options[:class]].compact.presence
@template.content_tag(tag, content, html_options)
else
content
View
16 test/attribute_test.rb
@@ -30,6 +30,14 @@ class AttributeTest < ActionView::TestCase
end
end
+ test "show_for allows collection class to be disabled globally" do
+ swap ShowFor, :collection_tag => :ol, :collection_class => nil do
+ with_attribute_for @user, :scopes
+ assert_select "div.show_for div.wrapper ol"
+ assert_no_select "ol[class]"
+ end
+ end
+
test "show_for allows collection tag to be changed by attribute" do
with_attribute_for @user, :scopes, :collection_tag => :ol
assert_select "div.show_for div.wrapper ol.collection"
@@ -48,6 +56,14 @@ class AttributeTest < ActionView::TestCase
end
end
+ test "show_for allows content class to be disabled globally" do
+ swap ShowFor, :content_tag => :span, :content_class => nil do
+ with_attribute_for @user, :name
+ assert_select "div.show_for div.wrapper span"
+ assert_no_select "span[class]"
+ end
+ end
+
test "show_for allows content tag to be changed by attribute" do
with_attribute_for @user, :name, :content_tag => :span
assert_select "div.show_for div.wrapper span.content"
View
7 test/builder_test.rb
@@ -11,6 +11,13 @@ class BuilderTest < ActionView::TestCase
end
end
+ test "show_for allows wrapper class to be disabled globally" do
+ swap ShowFor, :wrapper_tag => "li", :wrapper_class => nil do
+ with_attribute_for @user, :name
+ assert_select "div.show_for li[class='user_name']"
+ end
+ end
+
test "show_for attribute wraps each attribute with a label and content" do
with_attribute_for @user, :name
assert_select "div.show_for div.user_name.wrapper"
View
8 test/label_test.rb
@@ -24,6 +24,14 @@ class LabelTest < ActionView::TestCase
end
end
+ test "show_for allows label class to be disabled globally" do
+ swap ShowFor, :label_tag => :span, :label_class => nil do
+ with_attribute_for @user, :name
+ assert_select "div.show_for div.wrapper span"
+ assert_no_select "span[class]"
+ end
+ end
+
test "show_for allows label to be changed by attribute" do
with_attribute_for @user, :name, :label_tag => :span
assert_select "div.show_for div.wrapper span.label"
Please sign in to comment.
Something went wrong with that request. Please try again.