show_for 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,8 +23,10 @@ module ShowFor
23
23
  end
24
24
 
25
25
  def wrap_label_and_content(name, value, options, &block) #:nodoc:
26
- wrap_with(:wrapper, label(name, options, false) + ShowFor.separator.to_s +
27
- content(value, options, false, &block), options, true, (value.is_a?(Proc) or collection_block?(block)))
26
+ label = label(name, options, false)
27
+ label += html_safe(ShowFor.separator.to_s) if label.present?
28
+ wrap_with(:wrapper, label + content(value, options, false, &block),
29
+ options, true, (value.is_a?(Proc) or collection_block?(block)))
28
30
  end
29
31
 
30
32
  # Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
@@ -48,7 +50,7 @@ module ShowFor
48
50
  content
49
51
  end
50
52
 
51
- html.html_safe if safe && html.respond_to?(:html_safe)
53
+ html = html_safe(html) if safe
52
54
  concat ? @template.concat(html) : html
53
55
  end
54
56
 
@@ -57,5 +59,16 @@ module ShowFor
57
59
  def collection_block?(block) #:nodoc:
58
60
  block && block.arity == 1
59
61
  end
62
+
63
+ # Ensure we make html safe only if it responds to it.
64
+ def html_safe(content)
65
+ if content.respond_to?(:html_safe)
66
+ content.html_safe
67
+ elsif content.respond_to?(:html_safe!)
68
+ content.html_safe!
69
+ else
70
+ content
71
+ end
72
+ end
60
73
  end
61
74
  end
@@ -9,7 +9,7 @@ module ShowFor
9
9
  human_attribute_name(text_or_attribute)
10
10
  end
11
11
 
12
- return "" if label == false
12
+ return nil.to_s if label == false
13
13
  options[:label_html] = options.dup if apply_options
14
14
  wrap_with :label, label, options
15
15
  end
@@ -20,4 +20,4 @@ module ShowFor
20
20
  @object.class.human_attribute_name(attribute.to_s)
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module ShowFor
2
- VERSION = "0.1.5".freeze
3
- end
2
+ VERSION = "0.1.6".freeze
3
+ end
data/test/builder_test.rb CHANGED
@@ -26,7 +26,7 @@ class BuilderTest < ActionView::TestCase
26
26
  end
27
27
  end
28
28
 
29
- # WRAPPER
29
+ # WRAPPER
30
30
  test "show_for attribute wraps each attribute with a label and content" do
31
31
  with_attribute_for @user, :name
32
32
  assert_select "div.show_for p.user_name.wrapper"
@@ -66,6 +66,7 @@ class BuilderTest < ActionView::TestCase
66
66
  test "show_for skips label if requested" do
67
67
  with_attribute_for @user, :name, :label => false
68
68
  assert_no_select "div.show_for p.wrapper strong.label"
69
+ assert_no_select "div.show_for p.wrapper br"
69
70
  end
70
71
 
71
72
  test "show_for allows label to be configured globally" do
@@ -218,7 +219,7 @@ class BuilderTest < ActionView::TestCase
218
219
  with_content_for @user, "Special content", :content_tag => :b, :id => "thecontent", :class => "special"
219
220
  assert_select "div.show_for b#thecontent.special.content", "Special content"
220
221
  end
221
-
222
+
222
223
  test "show_for#content with blank value has a 'no value'-class" do
223
224
  swap ShowFor, :blank_content_class => "nothing" do
224
225
  with_content_for @user, nil, :content_tag => :b
@@ -327,4 +328,4 @@ class BuilderTest < ActionView::TestCase
327
328
  assert_select "div.show_for p.wrapper p.collection span", "Tag 2"
328
329
  assert_select "div.show_for p.wrapper p.collection span", "Tag 3"
329
330
  end
330
- end
331
+ end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
 
4
- gem 'actionpack', '2.3.5'
4
+ gem 'actionpack', '2.3.9'
5
5
 
6
6
  require 'action_controller'
7
7
  require 'action_view/test_case'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_for
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jos\xC3\xA9 Valim"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-29 00:00:00 +02:00
18
+ date: 2010-10-08 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21