show_for 0.2.1 → 0.2.2

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.
data/lib/show_for.rb CHANGED
@@ -18,9 +18,6 @@ module ShowFor
18
18
  mattr_accessor :blank_content_class
19
19
  @@blank_content_class = "blank"
20
20
 
21
- mattr_accessor :blank_content
22
- @@blank_content = ""
23
-
24
21
  mattr_accessor :wrapper_tag
25
22
  @@wrapper_tag = :p
26
23
 
@@ -48,7 +48,7 @@ module ShowFor
48
48
  content
49
49
  end
50
50
 
51
- html.html_safe
51
+ html
52
52
  end
53
53
 
54
54
  # Returns true if the block is supposed to iterate through a collection,
@@ -6,6 +6,10 @@ module ShowFor
6
6
  options[:class] = [options[:class], ShowFor.blank_content_class].join(' ')
7
7
  end
8
8
 
9
+ # We need to convert value to_a because when dealing with ActiveRecord
10
+ # Array proxies, the follow statement Array# === value return false
11
+ value = value.to_a if value.is_a?(Array)
12
+
9
13
  content = case value
10
14
  when Date, Time, DateTime
11
15
  I18n.l value, :format => options.delete(:format) || ShowFor.i18n_format
@@ -14,18 +18,15 @@ module ShowFor
14
18
  when FalseClass
15
19
  I18n.t :"show_for.no", :default => "No"
16
20
  when Array, Hash
17
- options[:escape] = false
18
21
  collection_handler(value, options, &block)
19
22
  when Proc
20
- options[:escape] = false
21
- @template.capture(&value).html_safe
23
+ @template.capture(&value)
22
24
  when NilClass
23
25
  ""
24
26
  else
25
27
  value
26
28
  end
27
29
 
28
- content = @template.send(:h, content) unless options.delete(:escape) == false
29
30
  options[:content_html] = options.dup if apply_options
30
31
  wrap_with(:content, content, options)
31
32
  end
@@ -14,11 +14,9 @@ module ShowFor
14
14
 
15
15
  html_options[:id] ||= dom_id(object)
16
16
  html_options[:class] = "show_for #{dom_class(object)} #{html_options[:class]}".strip
17
- builder_class = html_options.delete(:builder) || ShowFor::Builder
18
17
 
19
- content = with_output_buffer do
20
- yield builder_class.new(object, self)
21
- end
18
+ builder = html_options.delete(:builder) || ShowFor::Builder
19
+ content = capture(builder.new(object, self), &block)
22
20
 
23
21
  content_tag(tag, content, html_options)
24
22
  end
@@ -11,6 +11,7 @@ module ShowFor
11
11
 
12
12
  return "" if label == false
13
13
  options[:label_html] = options.dup if apply_options
14
+
14
15
  label = ShowFor.label_proc.call(label) if options.fetch(:wrap_label, true) && ShowFor.label_proc
15
16
  wrap_with :label, label, options
16
17
  end
@@ -1,3 +1,3 @@
1
1
  module ShowFor
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.2".freeze
3
3
  end
data/test/builder_test.rb CHANGED
@@ -212,9 +212,9 @@ class BuilderTest < ActionView::TestCase
212
212
  assert_select "div.show_for p.wrapper", /&lt;b&gt;/
213
213
  end
214
214
 
215
- test "show_for does not escape content if chosen" do
216
- @user.name = "<b>hack you!</b>"
217
- with_attribute_for @user, :name, :escape => false
215
+ test "show_for works with html_safe marked strings" do
216
+ @user.name = "<b>hack you!</b>".html_safe
217
+ with_attribute_for @user, :name
218
218
  assert_select "div.show_for p.wrapper b", "hack you!"
219
219
  end
220
220
 
@@ -240,13 +240,6 @@ class BuilderTest < ActionView::TestCase
240
240
  end
241
241
  end
242
242
 
243
- test "show_for#content with blank value fallbacks on a default value" do
244
- swap ShowFor, :blank_content => "Not specified" do
245
- with_content_for @user, nil, :content_tag => :b
246
- assert_select "div.show_for b", "Not specified"
247
- end
248
- end
249
-
250
243
  # COLLECTIONS
251
244
  test "show_for accepts an attribute as a collection" do
252
245
  with_attribute_for @user, :scopes
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jos\xC3\xA9 Valim"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-03 00:00:00 +02:00
17
+ date: 2010-05-20 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20