Skip to content
Browse files

add show_for_class option to config

closes #39
  • Loading branch information...
1 parent 5d73fff commit b1256e5f9fb9892317f828e6a3a43e7bc16b02cf @nashby nashby committed May 23, 2012
Showing with 20 additions and 1 deletion.
  1. +3 −0 lib/generators/show_for/templates/show_for.rb
  2. +3 −0 lib/show_for.rb
  3. +7 −1 lib/show_for/helper.rb
  4. +7 −0 test/helper_test.rb
View
3 lib/generators/show_for/templates/show_for.rb
@@ -3,6 +3,9 @@
# The tag which wraps show_for calls.
# config.show_for_tag = :div
+ # The DOM class set for show_for tag. Default is nil
+ # config.show_for_class = :custom
+
# The tag which wraps each attribute/association call. Default is :p.
# config.wrapper_tag = :dl
View
3 lib/show_for.rb
@@ -7,6 +7,9 @@ module ShowFor
mattr_accessor :show_for_tag
@@show_for_tag = :div
+ mattr_accessor :show_for_class
+ @@show_for_class = nil
+
mattr_accessor :label_tag
@@label_tag = :strong
View
8 lib/show_for/helper.rb
@@ -13,13 +13,19 @@ def show_for(object, html_options={}, &block)
tag = html_options.delete(:show_for_tag) || ShowFor.show_for_tag
html_options[:id] ||= dom_id(object)
- html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".rstrip
+ html_options[:class] = show_for_html_class(object, html_options)
builder = html_options.delete(:builder) || ShowFor::Builder
content = capture(builder.new(object, self), &block)
content_tag(tag, content, html_options)
end
+
+ private
+
+ def show_for_html_class(object, html_options)
+ "show_for #{dom_class(object)} #{html_options[:class]} #{ShowFor.show_for_class}".squeeze(" ").rstrip
+ end
end
end
View
7 test/helper_test.rb
@@ -37,4 +37,11 @@ class HelperTest < ActionView::TestCase
assert_select "p.show_for"
end
end
+
+ test "show for class should be configurable" do
+ swap ShowFor, :show_for_class => :awesome do
+ concat(show_for(@user) do |f| end)
+ assert_select "div.show_for.user.awesome"
+ end
+ end
end

0 comments on commit b1256e5

Please sign in to comment.
Something went wrong with that request. Please try again.