show_for 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/show_for.rb +0 -3
- data/lib/show_for/builder.rb +1 -1
- data/lib/show_for/content.rb +5 -4
- data/lib/show_for/helper.rb +2 -4
- data/lib/show_for/label.rb +1 -0
- data/lib/show_for/version.rb +1 -1
- data/test/builder_test.rb +3 -10
- metadata +3 -3
data/lib/show_for.rb
CHANGED
data/lib/show_for/builder.rb
CHANGED
data/lib/show_for/content.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/show_for/helper.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
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
|
data/lib/show_for/label.rb
CHANGED
data/lib/show_for/version.rb
CHANGED
data/test/builder_test.rb
CHANGED
@@ -212,9 +212,9 @@ class BuilderTest < ActionView::TestCase
|
|
212
212
|
assert_select "div.show_for p.wrapper", /<b>/
|
213
213
|
end
|
214
214
|
|
215
|
-
test "show_for
|
216
|
-
@user.name = "<b>hack you!</b>"
|
217
|
-
with_attribute_for @user, :name
|
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
|
-
-
|
9
|
-
version: 0.2.
|
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-
|
17
|
+
date: 2010-05-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|