Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add show_for_class option to config #42

Merged
merged 1 commit into from

2 participants

@nashby
Collaborator

closes #39

lib/show_for/helper.rb
@@ -13,7 +13,7 @@ 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 #{dom_class(object)} #{html_options[:class]} #{ShowFor.show_for_class}".squeeze(" ")
@carlosantoniodasilva Collaborator

If show_for_class is nil/blank, it'll leave an empty space at the end of :class, I think rstrip needs to stay.

@nashby Collaborator
nashby added a note

Actually not at the end. There is ShowFor.show_for_class and the end. So it will be something like "show_for user[:space:][:space]show_for_class"

@nashby Collaborator
nashby added a note

Ah, sorry. Do you mean to use squeeze and rstrip together?

@carlosantoniodasilva Collaborator

Yes, both :)

@nashby Collaborator
nashby added a note

I've updated PR and I've decided to extract it to the private method. Is it OK?

@carlosantoniodasilva Collaborator

Ok, great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@carlosantoniodasilva carlosantoniodasilva merged commit 766d35f into plataformatec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 23, 2012
  1. @nashby

    add show_for_class option to config

    nashby authored
    closes #39
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.