Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #25 from wojtekmach/label_class_support

Add label_class, content_class etc global option support
  • Loading branch information...
commit 026252cbb4644f5b48d9ffe72cc1c302a6bfba36 2 parents c4c8441 + a9dc63d
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 30 additions and 8 deletions.
  1. +13 −1 lib/show_for.rb
  2. +2 −1  lib/show_for/builder.rb
  3. +15 −6 test/builder_test.rb
View
14 lib/show_for.rb
@@ -9,21 +9,33 @@ module ShowFor
mattr_accessor :label_tag
@@label_tag = :strong
+ mattr_accessor :label_class
+ @@label_class = :label
+
mattr_accessor :separator
@@separator = "<br />"
mattr_accessor :content_tag
@@content_tag = nil
+ mattr_accessor :content_class
+ @@content_class = :content
+
mattr_accessor :blank_content_class
@@blank_content_class = "blank"
mattr_accessor :wrapper_tag
@@wrapper_tag = :p
+ mattr_accessor :wrapper_class
+ @@wrapper_class = :wrapper
+
mattr_accessor :collection_tag
@@collection_tag = :ul
+ mattr_accessor :collection_class
+ @@collection_class = :collection
+
mattr_accessor :default_collection_proc
@@default_collection_proc = lambda { |value| "<li>#{ERB::Util.html_escape(value)}</li>".html_safe }
@@ -45,4 +57,4 @@ module ShowFor
def self.setup
yield self
end
-end
+end
View
3  lib/show_for/builder.rb
@@ -46,8 +46,9 @@ def wrap_with(type, content, options) #:nodoc:
tag = options.delete(:"#{type}_tag") || ShowFor.send(:"#{type}_tag")
if tag
+ type_class = ShowFor.send :"#{type}_class"
html_options = options.delete(:"#{type}_html") || {}
- html_options[:class] = "#{type} #{html_options[:class]}".strip
+ html_options[:class] = "#{type_class} #{html_options[:class]}".strip
@template.content_tag(tag, content, html_options)
else
content
View
21 test/builder_test.rb
@@ -39,6 +39,15 @@ def with_attributes_for(object, *attributes)
end
# WRAPPER
+ test "show_for allows wrapper to be configured globally" do
+ swap ShowFor, :wrapper_tag => "li", :wrapper_class => "my_wrapper" do
+ with_attribute_for @user, :name
+ assert_select "div.show_for li.user_name.my_wrapper"
+ assert_select "div.show_for li.my_wrapper strong.label"
+ assert_select "div.show_for li.my_wrapper"
+ 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 p.user_name.wrapper"
@@ -82,9 +91,9 @@ def with_attributes_for(object, *attributes)
end
test "show_for allows label to be configured globally" do
- swap ShowFor, :label_tag => :span do
+ swap ShowFor, :label_tag => :span, :label_class => "my_label" do
with_attribute_for @user, :name
- assert_select "div.show_for p.wrapper span.label"
+ assert_select "div.show_for p.wrapper span.my_label"
end
end
@@ -120,9 +129,9 @@ def with_attributes_for(object, *attributes)
# CONTENT
test "show_for allows content tag to be configured globally" do
- swap ShowFor, :content_tag => :span do
+ swap ShowFor, :content_tag => :span, :content_class => :my_content do
with_attribute_for @user, :name
- assert_select "div.show_for p.wrapper span.content"
+ assert_select "div.show_for p.wrapper span.my_content"
end
end
@@ -357,9 +366,9 @@ def with_attributes_for(object, *attributes)
end
test "show_for allows collection tag to be configured globally" do
- swap ShowFor, :collection_tag => :ol do
+ swap ShowFor, :collection_tag => :ol, :collection_class => "my_collection" do
with_attribute_for @user, :scopes
- assert_select "div.show_for p.wrapper ol.collection"
+ assert_select "div.show_for p.wrapper ol.my_collection"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.